Repository navigation
Snackbar: Use WPDS shadow tokens, improve theme inheritance - #87818
Conversation
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: -47 B (0%) Total Size: 8.73 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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. Actions are reachable via RIGHT/LEFT arrow keys in
|
|
|
||
| // Button's pressed color comes from the surrounding theme, which is light | ||
| // behind the dark snackbar. | ||
| &:active { | ||
| color: $white; | ||
| } |
There was a problem hiding this comment.
I gather that we may be able to address this more holistically depending where we end up with #87834, and this still feels correct insofar as we were previously relying on the admin background incidentally being dark the same way that the snackbar is, but it does feel a bit odd that we have to patch in these forced colors for button, spinner, etc. In the current arrangement I would rather expect a nested set of ThemeProviders, one that establishes the background context for things like focus rings in how the snackbar is shown atop content, and one for the Snackbar and its contents itself (with a black background).
There was a problem hiding this comment.
Agreed that nested providers are the cleaner model: an outer one for the content behind the snackbar (shadow, focus ring) and an inner dark one for its contents, which would replace the :active and spinner patches. The inner seed depends on how #87834 lands, so I'd rather do it there than pick a dark seed now.
For example, if we landed on Option C in #87834, the implementation could be simplified considerably
Render snackbars in edit-site and boot under the content ThemeProvider, since they float over the content and not over the admin color scheme background. Then move Snackbar from $elevation-small to --wpds-shadow-outer-sm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On mobile, the sidebar fills the screen on routes without mobileContent, such as Navigation. Snackbars there now inherit the admin color scheme, so their focus ring keeps its contrast against the sidebar.
Nested providers inherit the admin scheme's primary color, so the content surfaces and snackbars only need the background seed.
Snackbars are fixed to the viewport, so on desktop they can float over the admin background instead of the content. Their focus ring is then tuned for light content.
Button's pressed color comes from the surrounding theme. Under a light provider it turned the action text dark on the dark snackbar.
The Spinner color comes from the surrounding theme. Under a light provider it was gray on the dark snackbar.
…out a canvas On mobile, a route without a preview shows the admin background in edit mode, such as Patterns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7f08f47 to
b56546b
Compare
What?
Follow-up to #87287 (follow-up 4). Part of #75266. Stacked follow-up: #87839.
Snackbar now uses
--wpds-shadow-outer-sminstead of$elevation-small. Inedit-siteandboot, snackbars render under the light contentThemeProvider, except over a full-screen mobile area with the admin background inedit-site, where they keep the admin color scheme. The snackbar action and the upload spinner now stay white under a light provider, which also fixes them in the post editor.Important
Known limitation: the snackbar focus ring can have low contrast on desktop when the snackbar floats over the admin background.
Snackbars are fixed to the bottom center of the viewport, so what sits behind them depends on the screen width, the route and the size of the preview, not on where they render. This PR seeds them for the area they usually cover: the light content. On desktop they can still cover the admin background, for example a long message on a narrow screen, a narrowed preview, or a route with no content area such as Navigation with a classic theme. There, the focus ring is tuned for light content.
With the Blue admin scheme, the ring over the sidebar drops from 5.37:1 (trunk) to 1.59:1, below the 3:1 that WCAG 1.4.11 asks for. With the Modern scheme it stays at 3.54:1. Trunk had the opposite problem in the most common layout: a light ring over light content (1.52:1 with Blue, 2.09:1 with Modern), which this PR fixes. See the "Known limitation" screenshots below and follow-up 1.
Why?
#87287 kept Snackbar on
$elevation-smallbecause in the site editor, snackbars render inside the dark admin color scheme provider but float over light content. With the token, they would get the shadow for a dark background, which is 5× stronger (see the "Token only" screenshots below).How?
edit-site(layout/index.jsx) andboot(root/index.tsx,root/single-page.tsx) wrapSnackbarNoticesin aThemeProviderwith the content colors. This is the pattern from the theme README's Shadows section. The provider's wrapper usesdisplay: contents, so the snackbar position doesn't change.UploadProgressSnackbarrenders nothing, so it stays where it is.edit-siteon mobile, one area fills the screen. When that area has the admin background, the snackbar provider gets no seed and inherits the admin color scheme, so the focus ring keeps trunk's color. This covers the sidebar on routes withoutmobileContent, such as Navigation, and edit mode on routes without a preview, such as Patterns.boot, both root layouts share aCONTENT_COLORconstant for the content surfaces and the snackbars. Nested providers inherit the admin scheme's primary color. Admin UI: Share the content background seed for ThemeProvider #87839 moves this value to@wordpress/admin-ui.box-shadowusesvar(--wpds-shadow-outer-sm).:activecolor) now stays white, and the upload progress spinner inherits the snackbar's white text color. The post editor already rendered snackbars under a light provider, so both were already broken there.edit-siteandbootstate the known limitation.Visible changes:
#8eb0ffwith Modern) to the admin color scheme's focus color for light backgrounds (#3858e9with Modern). The post editor already used#3858e9. Against the#fcfcfccontent, contrast goes from 2.09:1 to 5.47:1 with Modern.#1e1e1eon the dark snackbar), and the upload spinner is white instead of gray (#6e6e6e). The site editors already showed light colors here on trunk, and they still do.Testing Instructions
wp.data.dispatch( 'core/notices' ).createSuccessNotice( 'Changes saved.', { type: 'snackbar' } )document.querySelector( '.components-snackbar' ).focus()in the console. The focus ring should use the admin color scheme's focus color.bootsingle-page layout) and in the post editor. The post editor should look the same as trunk.wp.data.dispatch( 'core/notices' ).createSuccessNotice( 'Page duplicated.', { type: 'snackbar', explicitDismiss: true, actions: [ { label: 'Edit', onClick() {} } ] } ). Focus Edit (for example withdocument.querySelector( '.components-snackbar__action' ).focus()), then hold Space. The label should stay white. Upload an image to check that the upload spinner is white.wp.data.dispatch( 'core/notices' ).createSuccessNotice( 'Navigation menu "Header navigation" moved to the trash.', { type: 'snackbar' } ). Focus it. The part of the ring over the sidebar is hard to see.Testing Instructions for Keyboard
No interaction changes. Snackbars still take focus and dismiss with the keyboard as before. Only the color of the focus ring changes, as described above.
Screenshots
Site editor, Pages, 1280×720 at 2×, Modern admin color scheme. Before is
1c0803be314(trunk), After is this branch.Known limitation
Site editor and extensible site editor, Pages, 800×720 at 2×, Blue admin color scheme, a long focused snackbar. On trunk, the ring is hard to see over the content. On this branch, it is hard to see over the sidebar.
Mobile: Navigation screen with the full-screen sidebar
390×844 at 2×, Blue admin color scheme, focused snackbar. The focus ring matches trunk. The shadow is stronger, because the token adapts to the sidebar.
Pressed action and upload spinner
1280×720 at 2×, Modern admin color scheme. The Edit action is held down with Space, and the second snackbar shows the upload spinner. On trunk, the post editor already had a light provider behind the snackbar: the pressed label turns dark and the spinner is gray. The site editor had the dark provider, so it was fine on trunk and stays the same.
Why the provider move is needed: token only, without the provider move
This shows Snackbar on
--wpds-shadow-outer-smwith trunk'sedit-sitelayout, so the snackbar still renders inside the dark admin color scheme provider. The shadow is 5× stronger, and the focus ring keeps the light blue for dark backgrounds. This state is not part of the PR.Extensible site editor (
boot)Fonts page (
bootsingle-page layout)Post editor (no change at rest)
The post editor renders snackbars under its root provider, which uses the default background. The token resolves to the same layers as
$elevation-small.Full screen: site editor and extensible site editor
Follow-ups
ThemeProviderseed can match everything a viewport-fixed snackbar floats over: light content, the admin background, or the site's own colors in the editing canvas. Snackbar has its own dark fill, so a ring that contrasts with that fill and with any background, such as a two-color ring, would remove the dependency. This changes the Snackbar look in@wordpress/components, so decide it together with follow-up 1b in Theme: Add shadow tokens that adapt to the background seed #87287 (inverted surfaces). Update: Design System: Decide how Tooltip, Snackbar and other "perma dark" overlays should look like in dark themes #87834 settled on option C. Tooltip, Snackbar: Follow the theme instead of staying dark #87863 makes the Snackbar surface follow the theme, and the site editor now gives every snackbar the content colors, including over the mobile sidebar, like tooltips and menus. The ring is still drawn outside the snackbar, so this follow-up still applies, and it now also covers the mobile sidebar.@wordpress/admin-ui, and align thebootroot seed withedit-site: Admin UI: Share the content background seed for ThemeProvider #87839.CanvasTextborder so the surface stays distinct from what's behind it. This was already missing with$elevation-small. Update: Tooltip, Snackbar: Follow the theme instead of staying dark #87863 fixes this. It gives Snackbar a stroke border, which forced-colors mode keeps and draws in the system text color. Check this off when it merges.Use of AI Tools
Written with Claude Code (Claude Opus 5.5): Claude made the code change, captured the screenshots with Playwright against a local
wp-envsite, and wrote this description. A separate agent (Astra 6.2) reviewed the change in four rounds.🤖 Generated with Claude Code