Skip to content

Global Styles: Preserve individual sides of padding and margin shorthand - #85437

Merged
mirka merged 6 commits into
WordPress:trunkfrom
salvatorecorsi:fix/40132-expand-global-spacing-shorthands
Oct 28, 2026
Merged

mirka merged 6 commits into
WordPress:trunkfrom
salvatorecorsi:fix/40132-expand-global-spacing-shorthands

Conversation

@salvatorecorsi

@salvatorecorsi salvatorecorsi commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #40132.

Expand CSS padding and margin shorthand correctly when editing Global Styles dimensions. Changing the left side of 68px 32px now preserves 68px on top/bottom and 32px on the right.

Why?

The dimensions panel currently copies the entire shorthand string into every side. Editing one side then saves invalid longhand values such as padding-top: 68px 32px, which changes the untouched sides' rendered spacing.

How?

Expand the panel's local and inherited padding/margin values with a small helper inside block-editor before passing them to the existing controls. It preserves whitespace inside CSS functions such as calc() and var(). The components package and CSS serialization remain unchanged.

Testing Instructions

  1. In Global Styles, use padding or margin shorthand such as 68px 32px, 12px 24px 36px, or 12px 24px 36px 48px in theme.json or a style variation.
  2. Open Dimensions and edit one side. Verify the other sides retain the corresponding original values and the preview's spacing stays correct.
  3. With spacing presets enabled, change one axis of an inherited 12px 24px value. Verify the other axis keeps its inherited size.
  4. Check that a value containing calc() or var() with spaces remains intact when editing a different side.

Testing Instructions for Keyboard

Reach the padding/margin controls with Tab, unlink the sides if necessary, edit the Left side input and press Enter. The other sides must retain their original spacing. Existing controls and keyboard interactions are retained.

Validation

  • The retained DimensionsPanel jsdom suite passes, covering two-, three- and four-value shorthands, inherited spacing and CSS functions with spaces. Its ten regression cases were previously verified to fail on unchanged production code.
  • Related Global Styles, BoxControl and border-box utility coverage also passes.
  • Both components and block-editor package typechecks, focused ESLint and the block-editor changelog validator pass.
  • Full production build passes.

Updated against trunk on October 24 to include the Entity Fields/Actions compatibility fix from #85390. The spacing helper and tests are unchanged, and the related tests, package typechecks, lint and build pass after the merge. The previous Site Editor performance failure occurred in the old trunk comparison baseline; the refreshed CI still needs to complete.

The redundant browser test was removed following review because the jsdom assertions already check the side values passed to onChange. No full repository suite or Docker E2E run is claimed.

Use of AI Tools

OpenAI Codex was used for investigation, implementation, tests, automated validation and an independent automated review. No separate human review by the repository owner is claimed. WordPress maintainer review is requested.

A maintainer with triage access is requested to apply [Type] Bug for the label check.

@github-actions github-actions Bot added [Package] Components /packages/components [Package] Block editor /packages/block-editor labels Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: salvatorecorsi <salvatorecorsi@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@salvatorecorsi
salvatorecorsi marked this pull request as ready for review October 23, 2026 07:08
@salvatorecorsi
salvatorecorsi requested review from a team and ellatrix as code owners October 23, 2026 07:08
@github-actions github-actions Bot removed the [Package] Components /packages/components label Oct 23, 2026
@mirka

mirka commented Oct 26, 2026

Copy link
Copy Markdown
Member

On a deeper investigation, I noticed that the theme.json schema and reference docs only allow { top, right, bottom, left } for styles.spacing.padding and margin, so a shorthand string is outside the documented format, even though the style engine passes it through. I'm fine with reading it here the way #84826 does for border widths, since the alternative is saving invalid longhand CSS.

@tellthemachines @ramonjd you asked in #39926 whether we want to support shorthand at all. Any objection to treating it as tolerated input rather than adding it to the documented format?

All in all, I personally thought it would be reasonable to address as currently in this PR.

Context for my assessment

How shorthand is handled elsewhere:

Side effects:

  • The block inspector also renders DimensionsPanel, so a string in a block's style.spacing.padding or margin is now split too. I couldn't find a core block, fixture, or pattern that stores one.
  • Take a theme with shorthand padding and useRootPaddingAwareAlignments. Its padding doesn't set the root padding variables. Once the user edits one side, the saved value is an object, the variables turn on, and full-width blocks shift. Trunk already saves an object at that point. The difference is that the values are now valid, so the shift actually happens. This comes from the root padding guard, not this PR.
  • A two-value shorthand now opens with the sides unlinked and no inherited placeholder. On trunk, "All sides" shows 68, and saving writes 68px to every side.
  • Some inputs still don't work, such as 68px 32px !important or a string of several var:preset|… references. They were already broken and aren't documented, so I don't think this PR needs to handle them.

@ramonjd

ramonjd commented Oct 28, 2026

Copy link
Copy Markdown
Member

Any objection to treating it as tolerated input rather than adding it to the documented format?

No objections from me. Thanks for digging up that 2022 discussion.

With the benefit of hindsight, I think the approach of "tolerated shorthand without documenting it" is fair enough.

Theme creators who set such values will have reasons for going against the schema, and my view is, unless it seriously breaks something, we don't have to turn valid CSS into invalid CSS.

@t-hamano

Copy link
Copy Markdown
Contributor

For reference, even core's own theme.json used a shorthand value for the button element padding for a long time. It was only changed to the object format in #57374 on the Gutenberg side and in r60217 for core. Given that, it's likely that other themes still use shorthand values, so I think we should keep handling them gracefully rather than turning them into invalid CSS.

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks everyone!

@mirka
mirka enabled auto-merge (squash) October 28, 2026 10:15
@mirka
mirka merged commit 805ec99 into WordPress:trunk Oct 28, 2026
79 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 28, 2026
@ingeniumed ingeniumed added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended labels Nov 1, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
…and (WordPress#85437)

* Global Styles: Preserve individual sides of spacing shorthand

* Docs: Record spacing shorthand fix in block-editor changelog

* Docs: Record private spacing helper in components changelog

* Global Styles: Keep spacing shorthand parsing local

---------

Co-authored-by: salvatorecorsi <salvatorecorsi@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: Lena Morita <lena@jaguchi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global styles don't support multi-value shorthand padding

5 participants