Repository navigation
Theme: Warn about focus ring and brand fill contrast - #85449
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: +76 B (0%) Total Size: 8.56 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. As a user I want to be able to add multiple close buttons so that users can close the overlay from different positions in
|
| // Fit the seed to the original ramp targets first. A focus constraint must | ||
| // not move the seed and change otherwise accessible fill/foreground pairs. | ||
| const additionalReferenceColors = | ||
| getAdditionalReferenceColors?.( bestRamp ); | ||
| const needsFinalConstraints = Object.entries( | ||
| additionalReferenceColors ?? {} | ||
| ).some( ( [ rawStep, extraRefs ] ) => { | ||
| const step = rawStep as keyof Ramp; | ||
| const contrast = config[ step ].contrast; | ||
| const internalRefs = [ | ||
| contrast.reference, | ||
| ...( contrast.additionalReferences ?? [] ), | ||
| ].map( ( name ) => | ||
| name === 'seed' ? getColorString( finalSeed ) : bestRamp[ name ] | ||
| ); | ||
| return [ ...internalRefs, ...( extraRefs ?? [] ) ].some( | ||
| ( reference ) => | ||
| getContrast( bestRamp[ step ], reference ) < contrast.target | ||
| ); | ||
| } ); | ||
| if ( needsFinalConstraints ) { | ||
| const finalResult = calculateRamp( { | ||
| seed: finalSeed, | ||
| sortedSteps, | ||
| config, | ||
| mainDir, | ||
| oppDir, | ||
| pinLightness, | ||
| additionalReferenceColors, | ||
| } ); | ||
| bestRamp = finalResult.rampResults; | ||
| bestWarnings = finalResult.warnings; | ||
| } |
There was a problem hiding this comment.
I couldn't find an input where this second pass changes the ramp. Against trunk, 1,500 random primary/background pairs and 3,888 mid-lightness backgrounds gave identical colors, and the ring never fell below 3:1 against the four surfaces. The tests only reach it by overwriting neutral.ramp.surface3, which buildBgRamp can't produce.
Would it make sense to drop the correction and the serialized-contrast mode, and guard the invariant with a test over generated ramps instead? The new warnings already report a failure at runtime.
There was a problem hiding this comment.
Agreed, I removed the correction pass and serialized-contrast mode. The final-color warnings stay, with a regression test over generated ramps.
| // These colors identify focus through a ring or a solid item highlight. Check | ||
| // every supported neutral surface and the public brand surface using the final | ||
| // colors, including any focus-ring correction. | ||
| export const SEMANTIC_FOCUS_CONTRAST_PAIRS = ( |
There was a problem hiding this comment.
With the default primary on #1e1e1e (the README's dark example), this now reports brand-strong (#3858e9) at 2.97:1 against surface.neutral and 2.76:1 against surface.neutral-strong. Fills are never adjusted, so anyone using the default brand color in a dark theme gets warnings they can only clear by changing the brand color.
This contrast problem is already known, as we discussed, but the new warning perhaps makes the consumer experience worse by being confusing. Until we fix the contrast issue, we probably need some kind of guidance to let them know that the default primary doesn't work in dark mode.
There was a problem hiding this comment.
Added README guidance for the resting-fill warnings in the default dark example, including a passing background alternative. It also clarifies that the ring, active fill, and text still meet their targets.
|
|
||
| ### Enhancements | ||
|
|
||
| - Enforce the 3:1 focus-ring contrast target against neutral and brand surfaces after seed adjustment while preserving fill and foreground colors ([#85449](https://github.com/WordPress/gutenberg/pull/85449)). |
There was a problem hiding this comment.
If the correction goes, this entry goes with it. If it stays, "while preserving fill and foreground colors" describes unchanged behavior, so I'd drop that part.
There was a problem hiding this comment.
Removed the correction entry, leaving only the new contrast warnings in the changelog.
* Theme: Enforce focus ring contrast against theme surfaces * Theme: Document focus contrast enforcement * Theme: Warn about final popup fill contrast * Theme: Trim overlapping contrast test cases * Theme: Keep final contrast warnings without automatic correction --- Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org>
Supersedes #85448. See #84087.
What?
Report focus-ring and strong brand fill colors below 3:1 contrast against neutral and brand surfaces through
ThemeProvider.onColorWarnings.Why?
Readable text on a solid popup highlight does not guarantee that the highlight is distinguishable from its surroundings.
How?
Check the final generated ring, resting fill, and active fill against all three neutral surfaces and the public brand surface after seed adjustments. These checks report failures without changing the colors. Existing text checks keep their 4.5:1 target.
The README explains the default resting-fill contrast failures on background
#1e1e1eand how to choose a different primary or background seed. A focused regression checks the existing ring contrast across generated light, dark, and colored ramps.Testing Instructions
#3858e9with background#fcfcfcshould report no warnings.#1e1e1e. Expect resting strong brand fill warnings at approximately 2.97:1 against the neutral surface and 2.76:1 against the neutral strong surface. The focus ring remains#8eb0ff; the ring, active fill, and text checks pass.#000000. The warnings should clear.#608010and background to#4f386e. Expect a warning for the final active fill#6e8f26against neutral strong#563b79, at approximately 2.45:1.#ffff00and background to#fcfcfc. Expect 3:1 warnings for the solid fills while their text remains readable.Verification
All 291 tests selected by
packages/themepassed, including Chromium. The production build, theme typecheck, JavaScript lint, and changelog validation passed. Coverage includes the unrounded 3:1 warning threshold, final fills after seed adjustment, provider callback delivery, and ring contrast across generated ramps.Use of AI Tools
Codex was used to investigate the contrast checks, implement the final-color warnings, tests, and documentation, run verification, and draft this description.