gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Improve global padding to be more consistent

Open richtabor opened this issue 2 years ago • 26 comments

In exploring pattern interoperability across themes, I've noticed inconsistencies around how global padding is applied.

I'm just writing out a bit on each area patterns are leveraged, to lay out where the expectations are here.

I'm using base TT4 as a reference, with this markup (gist) as my pattern. The pattern is a fullwidth, constrained layout, Group block its inner blocks set to "wide". I'd consider this the standard "section" structure, where the pattern is fullwidth, but the contents are wide—representing the standard width of the page contents. There is no padding assigned to this pattern, as I'd expect global padding to be applied when it's in use.

Site Editor

Inserting the pattern on a template (meets expectations)

If we add that to the "Blog Home" template of TT4, inside the main wrapper Group block, the pattern performs as expected. It actually works as expected (with global padding) at the top-level as well—not just within the main Group.

Global padding is applied properly to the left and right bounds of the pattern—ensuring that the site's intended padding is represented within the pattern, without the pattern having to declare a value for left and right padding. Notice how the inner blocks of the pattern are as wide as the header template part's inner blocks (also using wide width).

CleanShot 2024-03-29 at 14 12 53

Isolated/focus mode (does not meet expectations)

If I take that same pattern and create a synced pattern from it, there are no changes to the display within the template, as expected, but once I select to edit this pattern (which invokes focus/isolated mode) the global padding is no longer present:

CleanShot 2024-03-29 at 14 26 14

As global padding is properly applied at the top level of a template, I'd expect the same behavior when in focus/isolated view, to have global padding applied.

Inserting the pattern on a page in the Site Editor (does not meet expectations)

TT4 uses a similar structure for the page template, as the blog home: a main wrapper Group block, set as "default ", with a core/post-content block set to a constrained layout. This way, editors can set blocks wide, or fullwidth—but the standard width is the site's contentWidth. This is a standard established template structure.

The problem is however, with this scenario, any patterns added to the post content will not receive the expected global padding values.

CleanShot 2024-03-29 at 14 41 46

The only way to have global padding assigned is to set the core/post-content block to a default layout—which is not appropriate, as users' text on a page will be 100% wide, and they'll loose the ability to choose width sizes.

I'd expect the global padding to apply in this scenario.

Post Editor (does not meet expectations)

Inserting the pattern on a page in the post editor

The pattern's global padding is omitted from the Post Editor, as it is within a page using Site Editor. I'd expect the global padding to apply in this scenario as well.

The difference between the Site Editor and the Post Editor, is that in the Site Editor when I changed the page template's core/post-content block layout to default, the global padding was applied to the pattern. There was no effect on global padding within the Post Editor.

CleanShot 2024-03-29 at 16 35 00

cc @tellthemachines, as I recall you worked on global padding at some point. :)

richtabor avatar Mar 29 '24 18:03 richtabor

Ideally patterns should not have to define left and right padding values—in all scenarios—so that they look great inheriting the theme's left and right global padding values, as they inherit colors, typography, block spacing, etc.

This would help make the WordPress.org pattern directory much more purposeful, allowing for much more theme-agnostic patterns.

richtabor avatar Mar 29 '24 20:03 richtabor

@richtabor are you seeing these issues in trunk Gutenberg or 6.5-RC4?

I cannot replicate those issues in 6.5 🤔 There it works as expected for me.

fabiankaegy avatar Mar 29 '24 21:03 fabiankaegy

@richtabor are you seeing these issues in trunk Gutenberg or 6.5-RC4?

Both, double-check the pattern you're using to test does not have padding left and right associated with it. TT4 added padding left/right to its patterns because of this, although it wasn't clearly defined.

richtabor avatar Mar 29 '24 21:03 richtabor

@richtabor Yeah my patterns don't have any left / right padding in them. Just a block theme that has the useRootPaddingAwareAlignments set to true, has style.spacing.padding.left & right defined and the pattern is wrapped in a group that has it's layout set to constrained.

That works as expected in all of the instances you mention for me on 6.5

fabiankaegy avatar Mar 29 '24 21:03 fabiankaegy

Mind recording a quick video? There's something not aligning.

EDIT: pun not intended, but welcomed. :)

richtabor avatar Mar 29 '24 21:03 richtabor

@richtabor actually, I believe I found what the reason was I couldn't replicate.

In my barebones theme I'm using this setup for the settings.layout.contentSize & settings.layout.wideSize:

{
    "version": 2,
    "settings": {
        "layout": {
            "contentSize": "min(650px, calc(100vw - var(--wp--style--root--padding-left) - var(--wp--style--root--padding-right)))",
            "wideSize": "min(850px, calc(100vw - var(--wp--style--root--padding-left) - var(--wp--style--root--padding-right)))"
        }
    }
}

And because of that the thing that was supposed to be the root padding still works as you would expect it in my case. But it works because the max-width of all the elements is already taking that padding out.

With a plain tt4 installation I can replicate what you are describing and am confused why the root padding is not getting applied. But I tested with WordPress 6.4.3 and it is the same thing there.

fabiankaegy avatar Mar 29 '24 22:03 fabiankaegy

I've had the same experience with my Ollie theme. Early on, I thought for sure I must be doing something wrong, but after testing in multiple popular block themes, I noticed the same issue.

As Rich mentions, this breaks a fundamental feature of block themes by not relying on the root padding. Having to add the missing padding directly to patterns makes them far less portable and composable by other themes.

Users are also reporting confusion with this, expecting the root padding to work universally.

mikemcalister avatar Mar 30 '24 00:03 mikemcalister

Global padding is only meant to apply to root or root-adjacent blocks, so I wouldn't expect it to be present on a pattern inserted into post content. I don't think patterns should rely on root padding as a rule, because it's context-specific and patterns should work when inserted an any point in the block tree.

When useRootPaddingAwareAlignments is enabled, the only thing it's meant to do is make sure that the root level padding (which without useRootPaddingAwareAlignments would be applied to the body element) is applied inside the outermost full-width block. In your post editor example, that block is Post Content, and adding another full width block inside it negates that padding. Unfortunately we can't support multiple nested blocks with root padding and full width, because that causes other types of unexpected behaviour, such as reported in #43095.

The behaviour in focus mode is also deliberate and was implemented to fix #51937.

tellthemachines avatar Apr 02 '24 01:04 tellthemachines

I don't think patterns should rely on root padding as a rule, because it's context-specific and patterns should work when inserted an any point in the block tree.

The discrepancies on when padding is applied is not ideal. On one view, it's applied as expected (from the user's perspective), in the others, the result is not expected.

If patterns have to include their own left and right padding in this scenario, then patterns simply can't exist apart from a specific theme (as the Pattern Directory is attempting to allow). I don't think that's an acceptable omission.

richtabor avatar Apr 02 '24 02:04 richtabor

Could Post Content not be treated as the top-level root?

richtabor avatar Apr 02 '24 03:04 richtabor

I always thought that any group block that has the layout set to constrained should get the root padding applied.

Constraining the max width without the root padding seems odd to me 🤔

fabiankaegy avatar Apr 02 '24 05:04 fabiankaegy

Constraining the max width without the root padding seems odd to me 🤔

I second this. When editing a Page, I have the same issue trying to get a full-width group block (to add full-width background color) with an inner paragraph (heading/etc) block. I have "Inner Block uses content width" checked on the containing Group block. The Inner paragraph block runs up to the edge on screens smaller than "contentSize" unless I manually give the inner block side padding. This grouping of blocks seems like a common scenario. Regular content editors will have difficulty remembering to add back (root/side) padding to inner blocks. When editing on a larger screen where the "content width" is shorter than your browser width, the missing (root/side) padding is not obvious.

I've created a couple Block Themes, and keep running into this issue. I thought it was something I was missing in my settings/template block configuration, but I realized TT4 behaves the same way.

bridgetwes avatar Apr 02 '24 18:04 bridgetwes

Here's a follow-up video showing how outer padding is applied inconsistently, using this pattern for testing and TT4:

  1. Pattern inserted at the top level of a template.
  2. Pattern viewed in isolated/focus view.
  3. Pattern inserted at the top level of post content (same result on post editor).

https://github.com/WordPress/gutenberg/assets/1813435/c0b08651-5c5f-4d65-b815-9ebcf4d793a0

I'd expect all three to have outer padding.

The behaviour in focus mode is also deliberate and was implemented to fix https://github.com/WordPress/gutenberg/issues/51937.

Yes, top/bottom editor padding should not be applied to focus mode. I found this related issue as well: https://github.com/WordPress/gutenberg/issues/59742

richtabor avatar Apr 02 '24 19:04 richtabor

I currently trip up a lot on this because of the lack of transparency around what's happening. I'm not sure I'm fully up to date with current behaviour but I'd like to see:

  • I don't like vertical and horizontal global padding results in different behaviours. From a glance, it looks as though if I set vertical padding it adds that to body, but horizontal padding is added to various blocks (like constrained layout groups). This relates to the point about transparency. I feel we need to create greater separation between these two settings because they do different things. e.g. "Set body padding" is one setting, and "Set default section(?) padding" as another. You can set horizontal and vertical padding for both. This would allow for greatest level of flexibility for theme authors. Default body padding is 0.
  • Always show padding value on blocks, even if its coming from global padding. If it is coming from global padding value, make sure we communicate that. I would hope the style inheritance work can help resolve that.
  • Full width patterns have a default padding set to whatever global is, this includes wrapper blocks in templates or post content block if set to full width
  • Constrained width patterns have a default padding set to whatever global is
  • Everything else has no padding by default

SaxonF avatar Apr 03 '24 00:04 SaxonF

Constrained width patterns have a default padding set to whatever global is

I just want to make sure that what you mean by that is that it uses the global setting. Not that it copies the global value into the pattern and saves it there. Updating this global value should affect all these instances you've described.

fabiankaegy avatar Apr 03 '24 06:04 fabiankaegy

@fabiankaegy thats what I mean yep . The style inheritance work aims to show global values in inspector for greater transparency and highlight properties that have been updated locally. The same would apply here.

SaxonF avatar Apr 03 '24 12:04 SaxonF

I feel we need to create greater separation between these two settings because they do different things. e.g. "Set body padding" is one setting, and "Set default section(?) padding" as another.

I see these as the same setting. Why would you have content different, whether it's a section of a site or not? Sure, if you are explicit in breaking out of the mold, but default behavior they're the same in the vast majority of cases.

richtabor avatar Apr 03 '24 23:04 richtabor

@richtabor because the current behaviour is unpredictable (hence this discussion) and changes depending on horizontal vs vertical (I could be wrong here). Separating them into "body" and "section" settings is a bit more explicit and maps more closely to how someone thinks about CSS, which we don't always want to do but in this case I feel is beneficial for theme authors. Also lets you set global vertical padding on sections.

Just an idea and is not required for my other points to still stand. I don't feel strongly about it.

SaxonF avatar Apr 04 '24 01:04 SaxonF

Can someone shed some light on the purpose and use case of this CSS?

.has-global-padding :where(.has-global-padding:not(.wp-block-block)) {
	padding-right: 0;
	padding-left: 0;
}

This seems to be the problematic piece, as far as I can tell. It is overriding this, which in the case of a full-width group that should have right/left padding applied:

.has-global-padding {
	padding-right: var(--wp--style--root--padding-right);
	padding-left: var(--wp--style--root--padding-left);
}

bgardner avatar Apr 12 '24 16:04 bgardner

Worth noting that adding something like this to theme.json seems to work, overriding the first block in my comment above:

{
	"styles": {
		"blocks": {
			"core/group": {
				"css": ".alignfull {padding-left: var(--wp--custom--spacing--gap); padding-right: var(--wp--custom--spacing--gap);}"
			}
		}
	}
}

bgardner avatar Apr 12 '24 17:04 bgardner