Repository navigation
Theme: Improve contrast for brand text, fills, and focus rings - #86614
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: +1.58 kB (+0.02%) Total Size: 8.72 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. keeps the default tab when a tab is added before it in
|
7b6ad05 to
45c34b7
Compare
|
Update: I split the code changes across 4 different PRs:
|
|
I actually checked how far off the primary colors could be, and was relieved to see that there isn't going to be much noticeable change anyway. It helps that most of the changes are in dark background, and at least in current Gutenberg the dark background UI is very limited. I think it's mostly under first-party control. So the conclusion here is that I was overestimating the impact. The only risk is probably the foreground text colors flipping, but given the limited amount of dark background UI, we should be able to check them all for any issues. |
mirka
left a comment
There was a problem hiding this comment.
Ok, I have checked the sidebar UI for any issues, and it seems fine. I found one issue in the experimental sidebar, but that is preexisting.
For cases in the future where we want the ability for users to create custom color schemes even if they don't meet accessibility standards, I'm assuming we're going to add a new prop to stop the auto-adjustments.
I think we're good to go 👍
|
Thank you! I'll merge once the rest of the stack / dependent PRs are also merged |
Check emitted primary colors against the actual contrast targets when reusing the seed or picking fill text, and keep the closest passing seed when the search ends on a failing sample.
When a searched primary color falls below its target once serialized, use the search endpoint if it still meets the actual targets.
Apply the gamut-mapping endpoint only to steps whose search reached its target, so forced brand surfaces keep their tint. Use the passing seed sample closest to the supplied seed whenever the search finds one.
The seed search can stop on a passing seed far from the supplied one when another step's deficit is close to zero there. Bisect between the supplied seed and the passing sample to keep the closest passing seed.
The primary surfaces keep the lightness pinned from the background ramp, so build them before the fills and list them as references for the fills, focus ring, and brand text. This removes the separate brand surface check. Stop the seed search at its first passing sample and end the refinement once it reaches the emitted color resolution.
Reference the neutral surface and the public brand surface for the fills, focus ring, and brand text, instead of every primary surface. The other surfaces are not checked as pairs, and requiring them moved seeds that already passed.
Snap primary seed trials to their emitted color so seeds that emit the same color produce the same ramp. Refine only the steps that failed at the supplied seed, then check the complete ramp, and refine every step only if that check fails.
Start the primary seed search from the emitted seed, as its trials do, so a seed and its hex value produce the same ramp. When gamut mapping pushes an emitted color below its target, move it toward the endpoint only as far as needed, keeping its tint.
Seed searches query the gamut's maximum chroma at the same lightness and hue many times. Cache sRGB results by their exact inputs, capped at 1,000 entries, so ramps stay identical.
|
I pushed a few changes after the approval, and rebased on trunk now that #87174 and #87175 have landed.
Compared with the approved revision ( I also added a follow-up section to the PR description, which I'm going to tackle soon. Comparison with the approved revisionThe v2 sidebar with keyboard focus on Dashboard, captured at the same density as the approval screenshots. The left and middle columns are those screenshots (trunk at Brand tokens for each scheme, in the same layout as the approval comparison. The left column is |
|
CC: @WordPress/gutenberg-components |
|
In short, that's not strictly a bug, but the result of the additional (and necessary) contrast constrains that we recently added. Intuitively, for dark themes, if the provided brand seed color doesn't reach 3:1 contrast against the background seed, the algorithm will lighten it until it does. As the brand color gets lighter, it may reach a point where white text won't have enough contrast against it (especially its hover state, which gets even lighter), causing the algo to choose dark text. A few thoughts:
Having said all of this, and assuming that showing dark text is not an option we're willing to settle on, I think that the easiest workaround is to tweak the theme seeds (mostly darkening the background seed color) to "make room" for white foreground color when paired on brand background color. I opened #87673 to implement those changes |





Follow-up to #86052. Builds on #87174 (WCAG luminance) and #87175 (background and divider saturation), both merged. The List View changes are in #87177, which should merge first. The DatePicker fix shipped in #86809.
What?
Adjust brand text, fills, and focus rings when the chosen theme colors produce too little contrast. In a menu using the Sunrise colors, the keyboard highlight goes from 1.92:1 to 3.77:1 against the popup.
Why?
A menu can use a solid fill as its only keyboard focus indicator. Reporting a warning leaves that highlight hard to see.
How?
The color ramp builder checks brand colors against three neutral backgrounds and the brand background. It targets 3:1 for focus rings and strong fills, and 4.5:1 for brand text. The primary ramp builds its surfaces first, adjusts the fills, focus ring, and text against them, and moves the seed when the text on the fills or the active fill still falls short. If a pair still falls short,
onColorWarningsreports it.The provider keeps the supplied primary seed in
--wp-admin-theme-color. With the Sunrise colors, that value stays#ad631ewhile the resting WPDS brand fill becomes#e79858. Legacy controls and WPDS controls can therefore show different accent colors side by side. Moving those consumers to WPDS tokens removes the mismatch.Testing Instructions
#cc4541and primary#ad631e.#e79858. The surrounding provider should still expose#ad631eas its legacy admin accent.Testing Instructions for Keyboard
In the @wordpress/ui → Menu → Default story, set the same Sunrise colors. Tab to the trigger, press Enter, and move through the enabled items with the arrow keys. On Archive, the highlight should be
#fbaa6bagainst the#ac1b21popup (3.77:1).Screenshots or screencast
Before is the saturation PR (#87175,
56671c7). After is this PR at7da305e; the current head produces the same colors in these examples, except Custom Charcoal, whose fill is one hex level off. Each Color Scales capture shows the background ramp above the primary ramp. Red outlines mark contrast warnings. In the Example Application, compare the Save button with its header.Sunrise
Background
#cc4541, primary#ad631e. The Save button fill changes from#ad631eto#e79858. Its contrast against the header goes from 1.56:1 to 3.08:1. In the menu, the keyboard highlight on Archive goes from 1.92:1 to 3.77:1 against the popup.Blue
Background
#3876a8, primary#437aa8. The Save button fill changes from#437aa8to#76afe0. Its contrast against the header goes from 1.57:1 to 3.08:1.Ectoplasm
Background
#4f386e, primary#646c3e. The Save button fill changes from#636b3dto#929b6b. Its contrast against the header goes from 1.60:1 to 3.07:1.Coffee
Background
#5b534d, primary#916745. The Save button fill changes from#976d4bto#cea07d. Its contrast against the header goes from 1.58:1 to 3.07:1.Ocean
Background
#5f787f, primary#567958. The Save button fill changes from#5b7e5dto#8eb390. Its contrast against the header goes from 1.57:1 to 3.08:1.Custom Teal
Background
#13a586, primary#3858e9. The Save button fill changes from#3858e9to#2132c4. Its contrast against the header goes from 2.25:1 to 3.63:1.Custom Charcoal
Background
#1e1e1e, primary#3858e9. The Save button fill changes from#3757e8to#4367f9(#4468fain the capture). Its contrast against the header goes from 2.69:1 to 3.32:1. The Save label switches from white to black.Comparisons from the original combined PR, before the review changes
In Sunrise, 16 of the 22 primary steps change. The Save button's contrast against the header rises from 1.56:1 to 3.08:1.
Sunrise and Blue get lighter brand fills
The same blue seed on teal and charcoal
Original ramp comparison
Follow-ups
ADMIN_THEME_COLORSbackgrounds produce chrome colors that drift from Core's sidebar colors:#99171cinstead of#8a312d, and#11507einstead of#245278. Background seeds#933330and#24567erestore the match and leave the brand colors unchanged.--wp-admin-theme-colorand--wp-components-color-*consumers to WPDS tokens, then remove the legacy bridge inuse-theme-provider-styles.ts. Until then, legacy and WPDS controls can show different accents on dark backgrounds.#183ad6,#0096dd) instead of the scheme. This predates this PR.#ff007aon white.ThemeProviderprop that turns off these adjustments, for custom schemes that intentionally miss the targets.The admin scheme primaries don't need to change. They already pass on light content, and for most schemes no single color passes on both the dark sidebar and white content.
Use of AI Tools
Codex implemented and tested the changes, captured the Storybook comparisons, and prepared the PR updates. After approval, Claude Code rebased the PR, addressed findings from Codex review passes, and captured the comparison against the approved revision.