Skip to content

Theme: forward ThemeProvider cornerRadius preset to :root for root providers#79153

Open
ciampo wants to merge 4 commits into
trunkfrom
add-corner-radius-root-selector
Open

Theme: forward ThemeProvider cornerRadius preset to :root for root providers#79153
ciampo wants to merge 4 commits into
trunkfrom
add-corner-radius-root-selector

Conversation

@ciampo

@ciampo ciampo commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #78816 (review thread).

What

A root ThemeProvider (isRoot) now forwards its cornerRadius preset to the document element, so --wpds-border-radius-* applies to <html> — not just the provider's scoping <div>. This matches how color and cursor already behave.

Why

color/cursor from a root provider already cascade to :root; cornerRadius was the odd one out. Mixed pages (React UI + PHP-rendered admin HTML) consume the tokens outside the React root, so the radius preset should reach <html> too.

Only isRoot providers are affected — non-root nested providers still scope their preset locally.

How

Each corner-radius-* mode in terrazzo.config.ts gains a :root:has([data-wpds-root-provider="true"][data-wpds-corner-radius="…"]) selector (plus regenerated CSS + CHANGELOG).

Test plan
  • In Storybook (Design System → Theme → Theme Provider), render a root ThemeProvider and switch the preset; confirm --wpds-border-radius-* updates on :root in DevTools.
  • Confirm a non-root provider still scopes its preset locally and does not affect :root.
  • Confirm color/cursor root forwarding still works and the default (subtle) preset matches existing appearance.
Note on the generated CSS

src/prebuilt/css/design-tokens.css is regenerated by npm run build (in packages/theme); running the full build produces this exact diff with no other changes.

Use of AI

Made with Cursor.

@github-actions github-actions Bot added the [Package] Theme /packages/theme label Jun 12, 2026
@ciampo ciampo self-assigned this Jun 12, 2026
@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Jun 12, 2026
@ciampo ciampo marked this pull request as ready for review June 12, 2026 14:17
@ciampo ciampo requested a review from a team as a code owner June 12, 2026 14:17
@github-actions

github-actions Bot commented Jun 12, 2026

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: ciampo <mciampini@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>

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

@ciampo ciampo force-pushed the add-corner-radius-root-selector branch from 3108de9 to 93a39d0 Compare June 12, 2026 14:48
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Size Change: +36 B (0%)

Total Size: 8.58 MB

📦 View Changed
Filename Size Change
build/modules/boot/index.min.js 52.8 kB +36 B (+0.07%)

compressed-size-action

@ciampo ciampo force-pushed the add-corner-radius-root-selector branch from 93a39d0 to dc37527 Compare June 15, 2026 15:35
ciampo added a commit that referenced this pull request Jun 15, 2026
Restores `data-wpds-root-provider="true"` on the wrapper when `isRoot`,
so prebuilt CSS can forward preset-based settings (e.g. `cornerRadius`
in #79153) to `:root` via `:root:has([data-wpds-root-provider="true"]…)`.

Dynamic color/cursor values keep using the JS sync in `useLayoutEffect`
(they can't be expressed in a static stylesheet). Comment updated to
explain the deliberate split.
@github-actions

Copy link
Copy Markdown

Flaky tests detected in dc37527.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27557643745
📝 Reported issues:

@aduth

aduth commented Jun 15, 2026

Copy link
Copy Markdown
Member

A couple clarifying questions on the difference in implementation between radius & color/cursor:

  • Does this mean that someone must load design-tokens.css for corner radius customization to take effect? My understanding is that up until now it's been somewhat optional to load that stylesheet, with how color and cursor styles are implemented and build upon the defaults embedded through the CSS fallback values.
  • I'm not sure I fully follow why they're different; i.e. why couldn't cornerRadius be implemented through ThemeProvider inline styles, or vice-versa why cursor shouldn't be implemented through design-tokens.css modifier selectors. Should we want them to be distinctly implemented?

@aduth aduth 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.

LGTM 👍

This was a little tricky to test, since all the border radiuses in Storybook fall within a ThemeProvider wrapper and so testing the :root forwarding required a bit of manual manipulation to copy/paste an element from the inspector to outside the ThemeProvider wrapper. Separately-but-maybe-relatedly it might be a good idea to change some of our hard-coded borderRadius in theme examples to use the tokens.

Before After
Screenshot 2026-06-15 at 3 35 06 PM Screenshot 2026-06-15 at 3 36 32 PM

// block (it also defines base tokens on `:root`) to avoid interfering
// with the color assertions above.
describe( 'cornerRadius forwarding', () => {
const BORDER_RADIUS = '--wpds-border-radius-sm';

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.

Nit: I'd only expect SCREAMING_SNAKE_CASE constant variables at the top-level of the module (ref), so either moving this to be with the rest or renaming it to a camelCase naming scheme.

beforeAll( () => {
prebuiltStyle = document.createElement( 'style' );
prebuiltStyle.textContent = readFileSync(
join( __dirname, '../prebuilt/css/design-tokens.css' ),

@aduth aduth Jun 15, 2026

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.

Tangent: I wonder if we could save ourselves some future headache adopting something like babel-plugin-transform-import-meta so we could start using (and avoid future migration to) import.meta.dirname since __dirname doesn't exist in true ESM. Ideally we'd upgrade Jest and try to start using some of their native ESM support, but that's a bigger task.

Comment on lines +10 to +12
### Enhancements

- `ThemeProvider`: forward the `cornerRadius` preset to the document element when `isRoot` is set, matching `color` and `cursor`. [#79153](https://github.com/WordPress/gutenberg/pull/79153).

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.

Arguably a bug fix, but since it hasn't released yet I suppose it's not a bug quite yet!

ciampo added 4 commits June 15, 2026 23:59
Restore the `:root:has([data-wpds-root-provider="true"][data-wpds-corner-radius="…"])`
selectors for each corner-radius preset mode in the Terrazzo config (and the
generated prebuilt CSS) so a root `ThemeProvider` applies the
`--wpds-border-radius-*` tokens to the document element, consistent with how
`color` and `cursor` tokens already behave.

Follow-up to #78816 (comment)
Add coverage for the prebuilt `:root:has( [data-wpds-root-provider='true']… )`
rule: a root provider forwards its corner-radius preset to the document
element, while a non-root provider does not. Loads the prebuilt design-token
CSS (where the border-radius preset values live) to exercise the cascade.
@ciampo ciampo force-pushed the add-corner-radius-root-selector branch from dc37527 to 415e57d Compare June 15, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Theme /packages/theme [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants