Skip to content

Theme.json schema: allow spacing margin/padding to be defined as sides - #79653

Open
gunjanjaswal wants to merge 2 commits into
WordPress:trunkfrom
gunjanjaswal:fix/79628-theme-json-spacing-sides
Open

gunjanjaswal wants to merge 2 commits into
WordPress:trunkfrom
gunjanjaswal:fix/79628-theme-json-spacing-sides

Conversation

@gunjanjaswal

@gunjanjaswal gunjanjaswal commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #79628.

In the theme.json schema, settings.spacing.margin and settings.spacing.padding only allowed a boolean, but the editor actually takes more than that. It also accepts an array of sides like [ "top", "bottom" ], or an object with a sides array. You can see it in packages/block-editor/src/components/global-styles/dimensions-panel.js, where the sides get read like this:

Array.isArray( settings?.spacing?.padding )
    ? settings?.spacing?.padding
    : settings?.spacing?.padding?.sides;

So boolean, array, and { sides } all work fine at runtime, but the schema only ever described the boolean. Anyone using side arrays got bogus validation errors, and the generated reference docs were off too.

The fix is just to widen the schema. In schemas/json/theme.json, margin and padding now use a oneOf of a boolean, an array of side strings (top/right/bottom/left/horizontal/vertical), or an object with a sides array. I regenerated docs/reference-guides/theme-json-reference/theme-json-living.md with npm run docs:theme-ref, and added a fixture at test/integration/fixtures/theme-json-spacing-sides/theme.json covering the array and object forms, which test/integration/theme-schema.test.js validates. I left this scoped to margin and padding since that's what the issue's about, but blockGap reads the same way, so it'd be an easy follow-up if you want it.

To check it: npm run test:unit test/integration/theme-schema.test.js. Or set settings.spacing.padding to [ "top", "bottom" ] in a theme.json and open it in a schema-aware editor, and it shouldn't flag an error anymore.

Use of AI Tools

This PR was written with AI assistance (Claude Code). I reviewed, tested, and understand every change, and I take responsibility for it.

settings.spacing.margin and settings.spacing.padding can be a boolean, an
array of sides, or an object with a `sides` array. The dimensions panel
already reads all three (the Array.isArray checks in dimensions-panel.js),
but the schema only allowed boolean, so a valid theme.json using side
arrays was flagged as invalid in editors.

Update the schema to accept the three shapes, regenerate the theme.json
reference docs, and add an integration fixture covering the array and
object forms.

Fixes WordPress#79628.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

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: gunjanjaswal <gunjanjaswal@git.wordpress.org>
Co-authored-by: todeveni <skithund@git.wordpress.org>

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

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

1 similar comment
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 29, 2026
@github-actions

Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @gunjanjaswal! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

The two red checks look unrelated to this change (schema + generated docs + a test fixture):

  • Playwright - 1 fails on specs/editor/blocks/html.spec.js (HTML block › supports editable inner blocks within static HTML), which doesn't touch the theme.json schema. Looks like the same HTML block breakage from Gutenberg in WP 7 totally destroyed custom HTML block #79316, and it's failing on trunk too.
  • type-related-labels just needs a [Type] label on the PR, which a maintainer would add.

The schema test (test/integration/theme-schema.test.js) and docs generation both pass.

@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Friendly bump on this — it's been open a while without a first look. It's a small, self-contained schema change: letting theme.json spacing margin/padding be defined per-side rather than only as a single value. If it's drifted from trunk I'm glad to rebase; just let me know if there's anything needed to get it in front of a reviewer.

@gunjanjaswal

Copy link
Copy Markdown
Contributor Author

Circling back on this. The "Required changes from trunk" check just means the branch has drifted behind trunk since the summer — I'm glad to rebase it clean the moment a reviewer's ready to take a look. The change itself is small and self-contained: allow theme.json spacing margin/padding to be defined as per-side objects, with the schema and the generated docs updated to match. Would really appreciate a first review when someone has a moment.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

theme.json defines spacing→margin and spacing→padding as booleans

1 participant