-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot apply wide or full widths to nested blocks with theme.json applied #33374
Comments
I was able to replicate this. Problem is that this returns an empty array when we have an empty gutenberg/packages/block-editor/src/hooks/align.js Lines 174 to 175 in fc243d2
|
@pattyok Try adding the following to your
That should restore those alignment controls. |
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 |
I guess this is related/the same, but for me If I remove layout{} from theme.json or do not specify content or wide sizes within layout{} then I would expect |
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. |
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? |
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? |
That part is fixed. They've removed the inner content container. So now you can simply use |
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? |
Let me continue my reasoning:
|
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. |
To further clarify - why can't you allow me to set wide and full on an inner block and also allow you to override what wide and fulll mean in a specific instance? |
Because it's impossible to consistently style wide/full alignments properly by ignoring intermediate container divs. You end up with broken alignments/layout depending on the use-case. |
I disagree that it's impossible but also that should be left to the theme
developer to solve. Not the platform...
I do still think some work on the language in the interface would be
helpful.
'Inherit default layout' - I still have no idea what that means - I expect
it to mean that it would follow what I have set for inner blocks that are
alignwide and alignfull.
Referencing Inner Blocks within that interface somewhere would be helpful.
…On Fri, Jul 30, 2021 at 9:52 AM Riad Benguella ***@***.***> wrote:
Because it's impossible to consistently style wide/full alignments
properly by ignoring intermediate container divs. You end up with broken
alignments/layout depending on the use-case.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#33374 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASODOCJMOYBC6MUOXDJX4TT2LKDFANCNFSM5AHZPRXQ>
.
|
With Full Site Editing, it's not the responsibility of the theme to define these structural styles, meaning the platform need to have a precise way to output these styles regardless of the used theme. Themes will be more about design, templates, and block patterns but less about figuring out how to style align left, align right, align center, or full width. these things will come with the platform and the "layout" feature is a step towards it.
I completely I agree, I think we have a an issue about that #31950 |
@pattyok Did you ever figure out how to handle this? I asked the same question #36465 It sounds like you wanted to create the same thing, a simple custom block: fullwidth background that allows your client to insert innerblocks that have alignment controls. Did you have to stop using theme.json to do it? |
@youknowriad Does this mean, if I use theme.json, I can't make a custom block that allows innerblocks to have alignment controls? I know the group block allows it, but you have to toggle. I don't want my clients to have to toggle. I understand that with FSE, with a theme being released to many, that could be an issue. But I need this ability for custom themes for clients. My example situationI have a simple "section" custom block. It's just a fullwidth container with padding and a background color. That's it. It allows my client to choose the "section" block, set a background color, and add innerblocks. This way they can group content together with a set style. They don't have to think about layout or padding. No toggling. Just enter content. If I want to have this ability, should I stop using theme.json, and specify supports using PHP instead? (I was converting themes to be hybrid. I don't use FSE, but I do like how theme.json handles things. Except for this issue.) Thanks! |
@youknowriad More succinctly: When I make a custom block, is there a way to say I want the innerblocks to have default alignment (and alignment controls) when creating it? Like the layout toggle for the Group block, but baked in. To be clear, CSS isn't the issue. I can add that. It's purely the ability to give innerblocks alignment controls so the user can still choose wide/full. |
@bethalessi My solution for now has been to set the Group block to use the "Inherit layout" option by default with a block variation: /* Inherit Layout by Default for Group Block */
wp.blocks.registerBlockVariation(
'core/group',
{
isDefault: true,
attributes: {
layout: {
inherit: true,
},
},
}
); I'd love to see this become the default behavior in WordPress, since it seems that defaulting to "just work please" rather than "select your widths every time" is a much better experience that significantly reduces the cognitive load on editors |
I did give up on theme.json as I felt it wasnt ready for a production site,
yet.
But of course the same behavior is applied to the group block in the block
widgets, with or without theme.json.
The odd thing is that you *can* set widths for inner blocks on a column,
and at long last we can have a one-column layout(!?!) So I can build what
you are talking about with a single column layout. Though I got so used to
using the group block for this type of layout, I have taken to building out
patterns with the alignwide/alignfull class assigned in the pattern
template to the inner blocks as needed.
…On Mon, Nov 15, 2021 at 5:50 AM Beth Alessi ***@***.***> wrote:
@pattyok <https://github.com/pattyok> Did you ever figure out how to
handle this? I asked the same question #36465
<#36465>
It sounds like you wanted to create the same thing, a simple custom block:
fullwidth background that allows your client to insert innerblocks that
have alignment controls.
Did you have to stop using theme.json to do it?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#33374 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASODOGKD4T2CR6F5SRCS5DUMEFZFANCNFSM5AHZPRXQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
you can do it by providing a layout to inner blocks, that said, the feature is still experimental at the moment, you should be able to pass That said, I personally think it's wrong to automatically do it because you don't really know where your "section" or "group" block is going to be used. Maybe it's inside a small column in which case alignments don't really make sense, maybe it's inside the "row" block and alignments don't make sense there either. |
@tellthemachines thanks for the summary of issues. It's really helpful! I have a few thoughts, but first let me just say:
I assume you mean the new default would set Having said that, I think there needs to be a full rethink of content alignments/widths, including in full block themes. Conceptually, I understand the idea: Our users look at these alignments like they look at font sizes. Something set to a predefined max width that they can reliably use to create consistent layouts. In our case, The idea that
The idea that every container needs to have its content width custom-defined just seems like an answer searching for a problem. Needing to define the content width of every container is too much flexibility to offer as a default. It's nice that it has become an option for the folks who want it, but for people developing basic content, it's just a roadblock. I don't see myself ever using this feature, and would prefer to be able to fully turn it off. Simply install I've outlined one possible solution here: #36082 (comment) but there have been many very good suggestions. I appreciate that you are looking into this and am very hopeful that at least a change in the default to |
Thanks for the feedback @eric-michel !
Yes, that's what I mean.
Agreed! How it works currently, wide alignment is always the same value (say 1100px). But if the container of the wide aligned block is narrower than that value, the block will respect the width of the container, so it will be narrower than 1100px. If the container expands, those 1100px will be respected. I guess it works more as a max-width than a fixed width, which also make sense in the context of smaller screen sizes. If I understood your comment in #36082 correctly, you propose that we shouldn't display the "wide" alignment option on blocks that are inside containers narrower than the "wide" value. The obstacle to doing that is we have no way of knowing how wide the container is, because not all containers have alignment set. In some containers, it doesn't make sense to have alignment, because their width is responsive. The classic example of this with Core blocks is a layout using Columns. Say I have a column that takes up 50% of the screen; depending on screen size, that column might need its content width restricted, and it might be able to accommodate a wide width, but on a smaller screen its width might compute to 500px, in which case all its contents will take up its full width. The contents of this column should still have wide and full alignment options, because on large screens they will actually be useful.
That's a good point! We're also discussing how to approach theme controls for user-set content width here. |
@tellthemachines this is a super helpful conversation!
I'm glad you mentioned this specifically because I think it drives to the core of where folks differ between supporting the old mechanism (just having all alignment options always available) vs supporting the new paradigm (needing to define alignment options on a container-per-container basis). We built our theme around the idea of width alignments as a simple definition of max width, not absolute width. This is fortunately supported by the very helpful descriptive text under the alignment controls: This concept has been super straightforward for our users, and I've never gotten a question about why, for instance, a block set to Of course, that's simply my subjective experience, which is absolutely limited. I imagine somewhere this has been a pain point for someone and that has inspired this change. However, so far, most of the comments I've seen from users and folks who support users is that the older paradigm was more intuitive.
I definitely see what you mean with the example above, but I think that problem could easily be extended to top-level blocks. Ignore containers for a moment, and imagine someone editing a page on their tablet at 900px width. If they add a In that vein, I would add to my linked proposal that all alignments that could theoretically be useful at an infinite screen width should be made available. So, in your example above where a columns block is set to Honestly, I would also be totally fine for all alignment options to always be available, as they are in non- |
Question: How do I add support for these types of layouts within my custom block theme that I am making? Whenever I set a layout in a single post or single page. That single post or page doesn't have the styles applied it should (max-width for example). Is there any documentation on setting up custom layouts for your block themes? |
Sure, provided there is already a content width defined on the container (this is the case with the Post Content block in most block themes; that's why we usually have wide and full options available on top-level blocks inside the post editor). If there is no content width defined, all blocks go full width, because that's what HTML does by default. In that case, wide and full options are unnecessary, because all blocks are already full width. Does that make sense? I'm looking into changing the default on at least some of the blocks with layout enabled (Group, Post Content and Column are the likeliest candidates for now). Let's see how that works, and iterate from there!
@Simbaclaws your theme needs to set values for content and wide widths. These docs should help. |
I've read this a few times and I think I get what you're saying, but am not positive, so I apologize if I end up with an unproductive response! I think what you're saying is that the Post Content block has a content width (meaning a max-width of its child blocks) set by default via In that case (assuming I'm interpreting you correctly), I guess what's really confusing to me is the decision to make I'm coming at this from the perspective of using Gutenberg a lot before This is also how the Twenty Twenty-One theme does it, which is actually where we got that standard from. Twenty Twenty-One's implementation made sense - it defined a max-width (in the form of the CSS custom prop You're saying "If there is no content width defined, all blocks go full width..." but my question is: why is there no content width defined? At some point, the sensible standard set by Twenty Twenty-One (a standard max-content width applied to From my perspective, the most intuitive solution is to apply I realize this is mostly an academic discussion because you said you're exploring changing the defaults of some container blocks which would largely resolve this issue, but I'm actually interested in the answers to these questions because it's entirely possible I'm missing something that makes this shift required (especially related to block themes, since I have not done much with those) and am hoping to learn more. |
Not quite! Sorry if I was unclear. Post Content is the same as the other block containers: by default, no content width is defined on it. What happens is that most block theme authors set the Post Content block on their themes to respect the theme content width. That's a two part process:
So when we start building a block theme, or create a new template in the site editor, no block has any content width. I guess the intention is to replicate how unstyled HTML works, and then the theme author configures everything to their liking. This makes sense, to a certain point, when we're building a theme from scratch, but doesn't make as much sense when we're editing content inside the post editor, where we expect a content width to already be defined by the theme.
Definitely, as long as the theme defines a content width (which most, if not all, themes do 😄 )
Totally understand, it helps to know how these things work under the hood, especially when we use them all the time! |
@tellthemachines thanks for all the really helpful responses! I'm really excited that you'll be swapping the defaults on some blocks to allow them to inherit the site's alignments by default. That will largely solve our problem and allow us to adopt
It would be awesome if you added the
Nevermind, I see you already have PRs in process, which is super exciting! |
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. Thanks for all your input folks! |
@tellthemachines I can see in Gutenberg 14 RC2 the options " Is there a way to activate this experimental feature in the |
@CreativeDive in your custom container block's 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! |
@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 " EDIT: I assume the " |
@tellthemachines Unfortunately I only got around to it later and for me there are a few questions and ambiguities. Layout definitionThe layout definition always gives us two input fields:
First point, not working properly for me here, if all inner blocks are restricted and don't have the The question is, can this happen? If yes, then 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 If a container block does not have a specific content width, The unavailable wide and full options for inner blocks were an issueIt's more common that within a " 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 " EDIT: I just recently switched to using |
@tellthemachines I think the different class names to detect layout option in the CSS way can be very helpful: OFF - Inner blocks respect content widthDefault (Nested blocks will fill the width of this container.)
ON - Inner blocks respect content widthLayout is on without defined sizes (Nested blocks use theme content width with options for full and wide widths.)
ON - Inner blocks respect content widthLayout is on with defined sizes (Nested blocks use theme content width with options for full and wide widths.)
EDIT: But with none of these 3 settings, my nested blocks in my custom container block get a |
@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 |
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. 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. |
@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
Test Case 2: Custom container block
Test Case 3: Custom container block
I will now test the same with the |
@tellthemachines Here is the same report, but instead I use the Test Case 1: Core group block
Test Case 2: Core group block
@tellthemachines It's nice that the SIDE NOTE: If my custom container block is nested inside the core/group block, the " |
@tellthemachines Another bug. 🐛 Adding a new custom container block, with the following settings in the
Only if I manually change the " |
@tellthemachines @andrewserong should I create a new issue? |
@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! |
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
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
Device information
The text was updated successfully, but these errors were encountered: