-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Don't apply root padding to nested layout blocks #43842
Conversation
Size Change: +4.08 kB (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
$block_rules .= '.has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }'; | ||
$block_rules .= '.has-global-padding > .alignfull > :where([class*="wp-block-"]:not(.alignfull):not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }'; | ||
$block_rules .= '.has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }'; | ||
$block_rules .= '.has-global-padding > .alignfull > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the remaining issue occurs when a wide width block is within a fullwidth block (that's not omitted from the above code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's especially noticeable when you add padding to the parent group block, regardless of constrained layout or not.
Editor:
Front-end:
You can try this snippet, with Twenty twenty Three to replicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for digging in on this — I know its a tricky one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that padding will be applied to any block inside the nested alignfull
block that's not also alignfull
; you can see it also gets applied to a regular width block:
(the yellow Group blocks are outside the full width Group and the Media&Text ones inside it)
This is also complicated by the box-sizing
property on the blocks that receive padding: some of them are set to border-box
(e.g. Media&Text) and others to content-box
(e.g. Paragraph, Image) so results vary depending on the block types.
I'm thinking we could target this extra padding rule only to children of alignfull
blocks that don't have content width set, as they're the ones that really need that padding? Whereas in blocks with content width set it's more likely to break the alignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've tried ignoring children of alignfull
blocks with content width.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing pretty well for me @tellthemachines! With @richtabor's provided markup, when I switch the Media & Text block from wide alignment to full alignment, the nested full width alignment block no longer has extra padding applied 👍
Just left a couple of comments — now that the rules are fairly complex, it'd be good to try to add some inline comments explaining each rule, to aid future debugging. The only blocker I ran into was with an issue with the output in global styles, but looks like it should be a fairly simple fix 🤞
'padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) } .has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); } .has-global-padding :where(.has-global-padding) { padding-right: 0; padding-left: 0; } .has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); } .has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; } .has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left);.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0; }'; | ||
} | ||
|
||
ruleset += '}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line appears to break global styles output for me. Can we split this into multiple lines so that it's easier to read / work out where we're concatenating }
characters? (I think one of the rules is missing a closing brace, and the very final rule has an extra closing brace since the below ruleset += '}';
line will add a closing one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh well spotted, yeah this needs to be more legible 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
$block_rules .= '.has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }'; | ||
$block_rules .= '.has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }'; | ||
$block_rules .= '.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0; }'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily a blocker, but now that these rules are fairly complex, is it worth adding a comment before each line about what the rule does? The other rules in this function feel fairly self explanatory to me, but just thinking of our future selves if we want to update these rules at any point, so that we don't forget why each line exists.
Thanks for the review @andrewserong ! I included some inline comments on what those CSS rules do. Hopefully they're clear enough! I'll also be working on a dev note for this functionality next week, that will further document the rules and our assumptions about how they should work. Once the feature's in Core we should add that documentation to the handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tellthemachines, those added comments are super helpful and make it much easier to read 👍
This appears to be testing well for me in the site editor as well as the post editor now. It might be worth getting another pair of eyes from @richtabor or others to confirm that the fix largely addresses the pain points. But, given the RC for the next Gutenberg release isn't until next Tuesday, we could always merge and follow-up separately with any required tweaks, too.
LGTM! 🎉
I'll go ahead and merge this; if anything's still off we can address it in a follow-up. |
What?
Fixes #43095 by resetting each root padding rule so it doesn't apply where there are nested
.has-global-padding
selectors. The new rules added simply negate the existing rules if the.has-global-padding
block is nested inside another.has-global-padding
block.Behaviour before fix
.has-global-padding
;.alignfull
direct children of blocks with.has-global-padding
;.alignfull
blocks with negative margins.Expected behaviour with fix applied
alignfull
children will get negative left/right margins;alignfull
blocks with negative margins mentioned in 2..I've tested this with a bunch of different nesting patterns and it seems to be working as expected. The one place where there can be a bit of weirdness is in the post editor view, because the
.has-global-padding
class isn't output at root level even if the Post Content block has layout set. This means that a block with layout in the post editor might display some extra padding:which won't appear in the front end view:
I think the only way to fully fix that is to make it possible for the post editor to be aware of the Post Content block settings, which we should look into doing separately from this fix.
Testing Instructions
"useRootPaddingAwareAlignments": true
inside the settings object;Screenshots or screencast
Before:
After: