Skip to content

Cannot apply wide or full widths to nested blocks with theme.json applied #33374

Closed

Description

@pattyok

Description

Trying out theme.json. When it is activated, the option to set wide/full width on a block placed inside a group disappears. This happens whether theme.json has any content in it or not. If remove theme.json, the option re-appears. I am working with my own custom theme, but I was able to reproduce with the TwentyTwentyOne theme as well.

Step-by-step reproduction instructions

  1. Set the theme to twenty-twenty one
  2. Add a group block, add a media-text, columns, group or cover block inside the group
  3. Notice the ability to set the width of each of those blocks to wide, full or normal
  4. Add a theme.json file to the theme (it doesnt seem to matter what is inside this theme file)

Expected behaviour

I still should be able to set the width of a block when it is nested.

Actual behaviour

I can't set the width of a block when it is nested. The align-wide and align-full options are not shown in the toolbar.

Screenshots or screen recording (optional)

Code snippet (optional)

This is the theme.json I am using - though editing it way down does not seem to make a difference.
https://gist.github.com/pattyok/0e7726a15c59ba8d183d2d1427728b48.js

WordPress information

  • WordPress version: 5.8-RC2
  • Gutenberg version: 11.0.0
  • Are all plugins except Gutenberg deactivated? Yes
  • Are you using a default theme (e.g. Twenty Twenty-One)? Yes

Device information

  • Device: Desktop
  • Operating system: maxOS 11.3
  • Browser: Chrome

Activity

  1. getdave commented on Jul 20, 2021

    @getdave
    Contributor

    I was able to replicate this. Problem is that this returns an empty array when we have an empty theme.json.

    const validAlignments = useAvailableAlignments(
    blockAllowedAlignments

  2. getdave commented on Jul 20, 2021

    @getdave
    Contributor

    @pattyok Try adding the following to your theme.json

    {
        "version": 1,
        "settings": {
            "layout": {
                "contentSize": "840px",
                "wideSize": "1100px"
            }
        }
    }
    

    That should restore those alignment controls.

  3. added
    [Type] Bug
    Global Styles
    on Jul 20, 2021
  4. pattyok commented on Jul 20, 2021

    @pattyok
    Author

    Yes, those settings are in there, and the problem still exists. Note that this is only an issue for nested blocks.

    Here is a better link to my theme.json. https://gist.github.com/pattyok/0e7726a15c59ba8d183d2d1427728b48

  5. thetwopct commented on Jul 28, 2021

    @thetwopct

    I guess this is related/the same, but for me add_theme_support( 'align-wide' ) is ignored once theme.json is present.

    If I remove layout{} from theme.json or do not specify content or wide sizes within layout{} then add_theme_support( 'align-wide' ) in my theme functions is ignored and blocks do not support wide and full alignment.

    I would expect add_theme_support( 'align-wide' ) to still work if layout{} is not present.

  6. youknowriad commented on Jul 30, 2021

    @youknowriad
    Contributor

    Hi There!

    Thanks for opening the issue, this is an intended behavior, the logic is simple. If you define "widths" (content and wide) widths for your canvas, there's nothing that tells that these widths apply to the nested blocks of any container because that container can be smaller (think a column, a small group block, a buttons block...) meaning we can't just blindly allow nested blocks of these containers to have wide/full alignments, you first have to define the "layout" of their container blocks. So for the group block, this is supported you can, go to the sidebar controls (inspector controls) of your group block and define the widths for the inner blocks of that particular container, you can also inherit the same definition as the global layout config (there's a toggle there). Once you define a layout for a given container, its children will have the possibility to be full/wide aligned.

    In other words, wide/full alignments config are container specific and should have always been, this release fixes it with an opt-in mechanism (theme.json) to avoid breaking existing themes.

  7. pattyok commented on Jul 30, 2021

    @pattyok
    Author

    Oh wow. I feel like it made a lot more sense before. The language you are using in the interface is completely foreign to me, and after looking at it with this information, I am still having a difficult time grasping how the words match the concept, though I am pretty well-versed on the block environment...

    It seems like you are putting a big burden on the user to set the layout of the group every time they put one on the page.

    I just want to have a full width background. Inside that background I want to be able to set whether the content inside is also full width, wide or narrow. I would like these widths to be consistent across the site so I do not want to offer the option of setting widths within the interface. I most often use a calculated width for the wide-width so I prefer to just set the class and use css to set that.

    What exactly is the problem of being able to set full, wide or none on the inner content of a group? Shouldn't that be the default and then one can have the option to override it and not the other way around?

  8. youknowriad commented on Jul 30, 2021

    @youknowriad
    Contributor

    What exactly is the problem of being able to set full, wide or none on the inner content of a group?

    The problem is that a block can not break out of its container, if its container is not wide enough, putting it "full width" only means "full width" inside of its container.

  9. pattyok commented on Jul 30, 2021

    @pattyok
    Author

    But as a theme editor I can set what full-width inside of wide width means...

  10. youknowriad commented on Jul 30, 2021

    @youknowriad
    Contributor

    But as a theme editor I can set what full-width inside of wide width means...

    It doesn't matter if you set it, if there's a div between your block and the place where the width is defined (the post content container for instance), your style won't apply properly. Theme authors struggled a lot with this previously, a lot of themes have broken styles and alignments in some situations because of this. Can you give an example of how you'd define that width?

  11. pattyok commented on Jul 30, 2021

    @pattyok
    Author

    Can you give an example of how you'd define that width?

    That part is fixed. They've removed the inner content container. So now you can simply use
    .alignwide > .alignfull { width: 100%;}

  12. youknowriad commented on Jul 30, 2021

    @youknowriad
    Contributor

    I'm not sure I follow the CSS you just shared, let me give you an example: Say you have an image block inside a group block inside a column block with a width of 50% and I apply "wide" or "full" on the image block what should happen?

  13. youknowriad commented on Jul 30, 2021

    @youknowriad
    Contributor

    Let me continue my reasoning:

    • In the example above, the full/wide doesn't make sense in the previous behavior, in some themes it breaks the layout entirely, in others it doesn't do anything because the column is limited to 50%.

    • in the new behavior which I think is more correct, you don't have "wide/full" alignments options there unless the group block in the column says, the wide area for my inner blocks is "80%" or "say 500px" while the content area is "60%" (just random numbers). This opens the possibilities for two column layouts with different "wide/full" widths for each column for instance. Or in a home page, you could have different sections one after the other, one of them narrower than the other... Basically, it's not a one size fits all.

  14. pattyok commented on Jul 30, 2021

    @pattyok
    Author

    I understand what you are saying. But I think that offering the one-sized fits all solution first with the option to override is preferable to forcing the user to have to set the widths every time they put a thing on the page.

    When I deliver a theme for a client I put things in place to guide them towards consistency this does not allow for that.

  15. 41 remaining items

  16. tellthemachines commented on Aug 8, 2022

    @tellthemachines
    Contributor

    It would be awesome if you added the cover block to this list as well!

    We won't be able to add the cover block just yet, because it's not using the layout controls. I see there's a PR that's been open for a few months (#37662); it's not a straightforward problem to solve because of how the block is structured (its child blocks are not direct descendants of the wrapper, so the layout styles would have to be applied to an inner container). But we'll get there eventually! It definitely makes sense for Cover to have the same layout controls as other containers.

  17. tellthemachines commented on Aug 22, 2022

    @tellthemachines
    Contributor

    #42763 should have solved the majority of issues mentioned in this thread. Group blocks will now have content width by default, so there won't be any jarring difference in alignment controls for blocks contained in them.

    Note that I only applied the change to Group so far; this way we can see how the solution works before changing things for other blocks.

    For the Cover block mentioned above, I opened #43140 with details on what we need to have in place so we can use Layout with it.

    Thanks for all your input folks!

  18. CreativeDive commented on Aug 28, 2022

    @CreativeDive
    Contributor

    @tellthemachines I can see in Gutenberg 14 RC2 the options "wide" and "full" are now available for nested blocks inside a core/group block. I wonder how we can test this for our custom blocks. "wide" and "full" are still not available for nested blocks inside a custom container block.

    Is there a way to activate this experimental feature in the block.json file for our custom blocks?

  19. tellthemachines commented on Aug 28, 2022

    @tellthemachines
    Contributor

    @CreativeDive in your custom container block's block.json, you'll need to add "__experimentalLayout": { "type": "constrained"} inside the "supports" object.

    One thing to consider: if the custom block is already being used out in the wild, this will break back compat for existing blocks, because it will set that layout type on them by default. If you wish to preserve back compat for existing blocks, have a look instead at how we handled the Group block in #42763, and let me know if you have any questions!

  20. CreativeDive commented on Aug 29, 2022

    @CreativeDive
    Contributor

    @tellthemachines thank you. Yes, I tried that. But unfortunately that doesn't seem to work.

    "supports": {
        "__experimentalLayout": { 
            "type": "constrained"
        }
    }
    

    The "Inner blocks respect the width of the content" option is disabled by default as expected, but the "wide" and "full" options are still unavailable for inner blocks.

    EDIT: I assume the "wide" and "full" options should be available by now, is that correct?

  21. CreativeDive commented on Aug 29, 2022

    @CreativeDive
    Contributor

    @tellthemachines Unfortunately I only got around to it later and for me there are a few questions and ambiguities.

    Layout definition

    The layout definition always gives us two input fields:

    Content width
    Width width

    Bildschirmfoto 2022-08-29 um 09 15 03

    First point, not working properly for me here, if all inner blocks are restricted and don't have the wide option available, then why is the Width width input field showing?

    The question is, can this happen? If yes, then Width width field should not be available in this case.

    How should it basically work?

    My basic understanding on this topic is the following and I think this is what everyone wants:

    When a container block specifies that inner blocks should conform to a specified content width, options such as wide and full may not be available.

    If a container block does not have a specific content width, wide and full options should be available for inner blocks.

    The unavailable wide and full options for inner blocks were an issue

    It's more common that within a "full" width block, I want to set an inner block to "wide" so that that block is slightly wider than all the other inner blocks. But that was no longer possible.

    It would be important for this to be possible again in principle.

    What is the current status now?

    In version 14 of Gutenberg something has changed in this regard. But I'm still not sure if I understand it correctly and if it works as it should?

    I want the freedom to redefine "full" and "wide" for inner blocks and not be constrained.

    EDIT: I just recently switched to using theme.json entirely. Using theme.json is a win in almost every way. The only pain I have with this is that wide and full are no longer available for inner blocks.

  22. CreativeDive commented on Aug 29, 2022

    @CreativeDive
    Contributor

    @tellthemachines I think the different class names to detect layout option in the CSS way can be very helpful:

    OFF - Inner blocks respect content width

    Default (Nested blocks will fill the width of this container.)

    is-layout-flow

    ON - Inner blocks respect content width

    Layout is on without defined sizes (Nested blocks use theme content width with options for full and wide widths.)

    is-layout-constrained

    ON - Inner blocks respect content width

    Layout is on with defined sizes (Nested blocks use theme content width with options for full and wide widths.)

    is-layout-constrained.wp-container-*

    EDIT: But with none of these 3 settings, my nested blocks in my custom container block get a wide and full option. Is this a bug in RC2?

  23. CreativeDive commented on Aug 29, 2022

    @CreativeDive
    Contributor

    @tellthemachines it seems there is a bug with the custom content width fields. If I enter a value the fields are displayed two times in the sidebar.

    Aug-29-2022.14-12-47.mp4
  24. tellthemachines commented on Aug 29, 2022

    @tellthemachines
    Contributor

    Thanks for the feedback @CreativeDive !

    The "Inner blocks respect the width of the content" option is disabled by default as expected, but the "wide" and "full" options are still unavailable for inner blocks.

    If the block's layout is set to "constrained", then "Inner blocks respect content width" should be enabled. Is that working for you?

    The wide and full options for the inner blocks will only appear if a content width is defined, which can be done by the theme, in the global styles interface or on the block itself.
    Check if your theme's theme.json has something like "layout": { "contentSize": "840px", "wideSize": "1100px"} in its settings object. If it doesn't, and you haven't defined content sizes anywhere in the block or the global styles editor, then "wide" and "full" options won't appear for children.

    A simple test is adding a value to the custom content width field. If you do that, "wide" and "full" should become available on the children.

    @tellthemachines it seems there is a bug with the custom content width fields. If I enter a value the fields are displayed two times in the sidebar.

    Yes, I can reproduce that. Definitely a bug 😅 Looking into it now.

  25. CreativeDive commented on Aug 30, 2022

    @CreativeDive
    Contributor

    The wide and full options for the inner blocks will only appear if a content width is defined, which can be done by the theme, in the global styles interface or on the block itself.
    Check if your theme's theme.json has something like "layout": { "contentSize": "840px", "wideSize": "1100px"} in its settings object. If it doesn't, and you haven't defined content sizes anywhere in the block or the global styles editor, then "wide" and "full" options won't appear for children.

    @tellthemachines thank you, it's very important to know how the things should be working to test if everything is working fine or not.

    Now I can get you the full bug report.

    Test Case 1: Custom container block

    1. "layout": { "contentSize": "840px", "wideSize": "1100px"} is set in theme.json.
    2. "__experimentalLayout": { "type": "constrained" } is set in the block.json inside the support object.
    3. Add a new block (in that case my custom container block).
      ----> "Inner blocks respect content width" is NOT enabled by default.
      ----> Is this a bug ? 🐛

    Test Case 2: Custom container block

    1. Same like in test case 1.
    2. But additionally "attributes": { "layout": { "type": "object", "default": { "type": "constrained" } } }, is set in the block.json
    3. Add a new block (in that case my custom container block).
      ----> "Inner blocks respect content width" is enabled by default.
    4. Copy the block and look inside the block code:
      ----> The block code does not contain"type":"constrained"
      --------> I think that is correct and expected.

    Test Case 3: Custom container block

    1. Same like in test case 1.
    2. But additionally "attributes": { "layout": { "type": "object", "default": { "type": "constrained" } } }, is set in the block.json
    3. Add a new block (in that case my custom container block).
      ----> "Inner blocks respect content width" is enabled by default.
    4. Set a custom content size in the sidebar field.
      ----> The inner blocks get the width from the content size field
    5. Copy the block and look inside the block code:
      ----> The block code contains "type":"constrained"
      --------> I think that is correct and expected.
    6. Add a core/cover block to the inner block component of this block.
    7. You say when a content size is entered, "wide" and "full" should be available for child blocks. I wish it would be like this.
      ----> But it does not work! It seems it's a BUG! 🐛 ‼️

    Bildschirmfoto 2022-08-30 um 08 16 26

    I will now test the same with the core/group block to see a comparison.

  26. CreativeDive commented on Aug 30, 2022

    @CreativeDive
    Contributor

    @tellthemachines Here is the same report, but instead I use the core/group block.

    Test Case 1: Core group block

    1. "layout": { "contentSize": "840px", "wideSize": "1100px"} is set in theme.json.
    2. "__experimentalLayout": { "type": "constrained" } is set in the block.json inside the support object.
    3. Add a new block (in that case the core/group block).
      ----> "Inner blocks respect content width" is enabled by default.
      --------> I think that is correct and expected.
    4. Copy the block and look inside the block code:
      ----> The block code contains "type":"constrained"
      --------> I think that is correct and expected.
    5. Add a core/cover block to the inner block component of this block.
    6. You say when a content size is entered, "wide" and "full" should be available for child blocks.
      ----> But, the "wide" and "full" options are available also without set a content size in the sidebar
      ----> Is this a bug ? 🐛

    Test Case 2: Core group block

    1. Same like in test case 1.
    2. Set a custom content size in the sidebar field.
      ----> The inner blocks get the width from the content size field
    3. You say when a content size is entered, "wide" and "full" should be available for child blocks.
      ----> The "wide" and "full" options are available.
      --------> I think that is correct and expected.

    Bildschirmfoto 2022-08-30 um 08 36 04

    @tellthemachines It's nice that the core/group children's blocks now also have "wide" and "full" available. But it is NOT the case for our custom blocks. But it must be available for inner blocks. This is exactly what I and many others expect. Can you reproduce this?

    SIDE NOTE: If my custom container block is nested inside the core/group block, the "wide" and "full" are available. But not inside my custom container block. Is there a limitation and can it be fixed or activated by an additional setting?

  27. CreativeDive commented on Aug 30, 2022

    @CreativeDive
    Contributor

    @tellthemachines Another bug. 🐛

    Adding a new custom container block, with the following settings in the block.json:

    "attributes": { "layout": { "type": "object", "default": { "type": "constrained" } } },
    "__experimentalLayout": { "type": "constrained" }
    
    1. The block starts with "Inner blocks respect content width" is enabled by default.
      --------> I think that is correct and expected.
    2. The block class name in the block editor source code contains is-layout-constrained.
      --------> I think that is correct and expected.
    3. Save the post and look at the front end output.
    4. The block class name in the front end source code contains is-layout-flow.
      ----> It's a BUG! 🐛 ‼️

    Bildschirmfoto 2022-08-30 um 14 52 34

    Only if I manually change the "Inner blocks respect content width" toggle to OFF and back to ON, the expected class name is-layout-constrained appears in the front end block output.

  28. CreativeDive commented on Aug 31, 2022

    @CreativeDive
    Contributor

    @tellthemachines @andrewserong should I create a new issue?

  29. andrewserong commented on Aug 31, 2022

    @andrewserong
    Contributor

    @CreativeDive, yes please — another issue would be great so that we can look at follow up issues in isolation. Thank you for writing up the bug and test instructions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Global Styles[Type] Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions