Theme: Propagate density through React context#78662
Conversation
Add `density` to `resolvedSettings` alongside `color`/`cursor`, so that nested `ThemeProvider`s inherit the value through React (not only via the DOM attribute/CSS cascade). The wrapper's `data-wpds-density` attribute now reflects the resolved density rather than only the prop. Addresses task B1 of #77462.
|
Size Change: +40 B (0%) Total Size: 8.16 MB 📦 View Changed
ℹ️ View Unchanged
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Flaky tests detected in 6dfaf57. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26442883910
|
What?
See task B1 in #77462. Adds
densitytoresolvedSettingsso nestedThemeProviders inherit it through React context.Why?
Today
densityis only propagated via thedata-wpds-densityDOM attribute / CSS cascade.useContext( ThemeContext ).resolvedSettings.densityis alwaysundefined, which is inconsistent with howcolorandcursorwork.How?
densityto the defaultThemeContextvalue.densityinuseThemeProviderStyles(prop ?? inheritedSettings.density) and include it inresolvedSettings.data-wpds-densityattribute, so nested providers that omit the prop still emit the right attribute.Testing Instructions
<ThemeProvider density="compact">, readuseContext( ThemeContext ).resolvedSettings.density— should now be'compact'(previouslyundefined).ThemeProviderwithout adensityprop inside one withdensity="compact"; the inner wrapper'sdata-wpds-densityshould becompact.Testing Instructions for Keyboard
N/A — internal API change, no UI affordances.
Screenshots or screencast
N/A — no visual changes.
Use of AI Tools
This PR was authored with the help of an AI coding assistant (Cursor). All changes were reviewed by a human before submission.