You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot apply wide or full widths to nested blocks with theme.json applied #33374
Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Type] BugAn existing feature does not function as intended
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
Set the theme to twenty-twenty one
Add a group block, add a media-text, columns, group or cover block inside the group
Notice the ability to set the width of each of those blocks to wide, full or normal
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.
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.
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.
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?
Reacted by Eric Michel, Lukas Gächter, Mark Root-Wiley, Will Skora, NicoHood, Lauri Merisaari, nickfmc, Christina, Cory Birdsong, Benny Vluggen and 3 more
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.
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?
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?
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.
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.
Reacted by Mark Root-Wiley, Lauri Merisaari, Eric Michel, Lukas Gächter, Phil Sola, Anthony Hortin, Elaine Shannon and wwdes
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.
#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.
@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?
@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!
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?
@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
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.
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.
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
"layout": { "contentSize": "840px", "wideSize": "1100px"} is set in theme.json.
"__experimentalLayout": { "type": "constrained" } is set in the block.json inside the support object.
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
Same like in test case 1.
But additionally "attributes": { "layout": { "type": "object", "default": { "type": "constrained" } } }, is set in the block.json
Add a new block (in that case my custom container block).
----> "Inner blocks respect content width" is enabled by default.
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
Same like in test case 1.
But additionally "attributes": { "layout": { "type": "object", "default": { "type": "constrained" } } }, is set in the block.json
Add a new block (in that case my custom container block).
----> "Inner blocks respect content width" is enabled by default.
Set a custom content size in the sidebar field.
----> The inner blocks get the width from the content size field
Copy the block and look inside the block code:
----> The block code contains"type":"constrained"
--------> I think that is correct and expected.
Add a core/cover block to the inner block component of this block.
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! 🐛 ‼️
I will now test the same with the core/group block to see a comparison.
@tellthemachines Here is the same report, but instead I use the core/group block.
Test Case 1: Core group block
"layout": { "contentSize": "840px", "wideSize": "1100px"} is set in theme.json.
"__experimentalLayout": { "type": "constrained" } is set in the block.json inside the support object.
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.
Copy the block and look inside the block code:
----> The block code contains "type":"constrained"
--------> I think that is correct and expected.
Add a core/cover block to the inner block component of this block.
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
Same like in test case 1.
Set a custom content size in the sidebar field.
----> The inner blocks get the width from the content size field
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.
@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?
The block starts with "Inner blocks respect content width" is enabled by default.
--------> I think that is correct and expected.
The block class name in the block editor source code contains is-layout-constrained.
--------> I think that is correct and expected.
Save the post and look at the front end output.
The block class name in the front end source code contains is-layout-flow.
----> It's a BUG! 🐛 ‼️
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.
@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!
Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Type] BugAn existing feature does not function as intended
Activity
getdave commentedon Jul 20, 2021
I was able to replicate this. Problem is that this returns an empty array when we have an empty
theme.json.gutenberg/packages/block-editor/src/hooks/align.js
Lines 174 to 175 in fc243d2
getdave commentedon Jul 20, 2021
@pattyok Try adding the following to your
theme.jsonThat should restore those alignment controls.
pattyok commentedon Jul 20, 2021
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
thetwopct commentedon Jul 28, 2021
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.youknowriad commentedon Jul 30, 2021
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.
pattyok commentedon Jul 30, 2021
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?
youknowriad commentedon Jul 30, 2021
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.
pattyok commentedon Jul 30, 2021
But as a theme editor I can set what full-width inside of wide width means...
youknowriad commentedon Jul 30, 2021
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?
pattyok commentedon Jul 30, 2021
That part is fixed. They've removed the inner content container. So now you can simply use
.alignwide > .alignfull { width: 100%;}youknowriad commentedon Jul 30, 2021
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?
youknowriad commentedon Jul 30, 2021
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.
pattyok commentedon Jul 30, 2021
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.
41 remaining items
tellthemachines commentedon Aug 8, 2022
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.
tellthemachines commentedon Aug 22, 2022
#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!
CreativeDive commentedon Aug 28, 2022
@tellthemachines I can see in Gutenberg 14 RC2 the options "
wide" and "full" are now available for nested blocks inside acore/groupblock. 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.jsonfile for our custom blocks?tellthemachines commentedon Aug 28, 2022
@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!
CreativeDive commentedon Aug 29, 2022
@tellthemachines thank you. Yes, I tried that. But unfortunately that doesn't seem to work.
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?CreativeDive commentedon Aug 29, 2022
@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 widthWidth widthFirst point, not working properly for me here, if all inner blocks are restricted and don't have the
wideoption available, then why is theWidth widthinput field showing?The question is, can this happen? If yes, then
Width widthfield 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
wideandfullmay not be available.If a container block does not have a specific content width,
wideandfulloptions 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.jsonentirely. Using theme.json is a win in almost every way. The only pain I have with this is thatwideandfullare no longer available for inner blocks.CreativeDive commentedon Aug 29, 2022
@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-flowON - 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-constrainedON - 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
wideandfulloption. Is this a bug in RC2?CreativeDive commentedon Aug 29, 2022
@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
tellthemachines commentedon Aug 29, 2022
Thanks for the feedback @CreativeDive !
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.jsonhas 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.
Yes, I can reproduce that. Definitely a bug 😅 Looking into it now.
CreativeDive commentedon Aug 30, 2022
@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
"layout": { "contentSize": "840px", "wideSize": "1100px"}is set intheme.json."__experimentalLayout": { "type": "constrained" }is set in theblock.jsoninside thesupportobject.----> "Inner blocks respect content width" is NOT enabled by default.
----> Is this a bug ? 🐛
Test Case 2: Custom container block
"attributes": { "layout": { "type": "object", "default": { "type": "constrained" } } },is set in theblock.json----> "Inner blocks respect content width" is enabled by default.
----> The block code does not contain
"type":"constrained"--------> I think that is correct and expected.
Test Case 3: Custom container block
"attributes": { "layout": { "type": "object", "default": { "type": "constrained" } } },is set in theblock.json----> "Inner blocks respect content width" is enabled by default.
----> The inner blocks get the width from the content size field
----> The block code contains
"type":"constrained"--------> I think that is correct and expected.
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! 🐛
I will now test the same with the
core/groupblock to see a comparison.CreativeDive commentedon Aug 30, 2022
@tellthemachines Here is the same report, but instead I use the
core/groupblock.Test Case 1: Core group block
"layout": { "contentSize": "840px", "wideSize": "1100px"}is set in theme.json."__experimentalLayout": { "type": "constrained" }is set in the block.json inside the support object.----> "Inner blocks respect content width" is enabled by default.
--------> I think that is correct and expected.
----> The block code contains "type":"constrained"
--------> I think that is correct and expected.
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
----> The inner blocks get the width from the content size field
wide" and "full" should be available for child blocks.----> The "
wide" and "full" options are available.--------> I think that is correct and expected.
@tellthemachines It's nice that the
core/groupchildren'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?CreativeDive commentedon Aug 30, 2022
@tellthemachines Another bug. 🐛
Adding a new custom container block, with the following settings in the
block.json:--------> I think that is correct and expected.
is-layout-constrained.--------> I think that is correct and expected.
is-layout-flow.----> It's a BUG! 🐛
Only if I manually change the "
Inner blocks respect content width" toggle to OFF and back to ON, the expected class nameis-layout-constrainedappears in the front end block output.CreativeDive commentedon Aug 31, 2022
@tellthemachines @andrewserong should I create a new issue?
andrewserong commentedon Aug 31, 2022
@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!