Repository navigation
Global Styles: Show a contrast warning for the site's text color - #86186
im3dabasia wants to merge 6 commits into
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: +212 B (0%) Total Size: 8.66 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. Navigates the list via UP/DOWN arrow keys from action buttons in
|
Test ReportEnvironment
Steps
Results
Works as described. ScreencastScreen-Recording-Gutenberg-PR-86186.mp4 |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Thanks for working on this @im3dabasia 👍
I've taken it for a spin
✅ Preset colours resolve before the check
✅ The warning reuses the block editor's copy
A few cases need addressing before we merge though.
Background gradients
The check skips color.gradient but not background.gradient, so it compares against the colour behind the gradient.
- Readable text on a light gradient over
#222warns #f0f0f0text on a light gradient over black doesn't
Skipping them, like the Background panel, is simplest. getLowestContrastColor() from #86148 could check the worst stop instead and might be better.
Text gradients
With backgroundClip: text, trunk shows the warning on the Gradient control. The root has none, so nothing shows but screen readers still announce it. These could be skipped too.
Unparseable colours
An oklch() text colour reads as black, so light text on black warns. The OTHER_COLOR guard from #86148 would fix this.
Tests
Tests for these and an updated description would be great.
The check skipped gradients in the legacy color.gradient location only, so a gradient in background.gradient was checked against the color behind it.
A text gradient is stored in background.gradient, so it is skipped with the other gradients. The root has no gradient control to show the warning on, so nothing should be announced either.
colord reads a color it cannot parse, such as oklch(), as black, so light text on a black background was reported as poor contrast. Skip the check for those colors instead.
|
Thanks for the review, @aaronrobertshaw! I've addressed the feedback:
Checking against the worst gradient stop is left as a follow-up. Could you take another look? |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Thanks for the updates @im3dabasia 👍
✅ Background and text gradients no longer give a false warning
✅ New tests and an updated description
Background gradients
I don't think there is a great hurry to land this so I think we should go with the better approach suggested and land the worst stop check here instead of a follow-up.
Global Styles stops may need resolving first.
Colours that can't be read
The isValid() checks also change the block inspector. Its oklch(), lab() and color-mix() colours now skip the check. In my testing that removed three false warnings but lost six correct ones.
Could these colours be resolved instead of skipped? Reading them back from a 1×1 canvas gave the right sRGB value each time. That fixes both warnings.
Self-review
Before re-requesting review, could you do a full self-review and post a short summary of what you checked? If you use an AI tool, the prompt below might help.
Example self-review prompt
You are reviewing my Gutenberg pull request as a strict core reviewer, before it goes back to a human: https://github.com/WordPress/gutenberg/pull/86186
Do not add features. Find every problem, fix it, and prove each fix on screen. Do not trust earlier replies, commit messages or your own past summaries. Verify everything in the code and in a running site.
1. Read everything first
- Read the full PR thread, including resolved comments. List each review point, who raised it, and its status (fixed, not fixed, disputed). For each "fixed", give the exact line that fixes it.
- Where a reviewer offered a skip and a better option, implement the better option unless the thread agreed otherwise.
- Read the full diff against trunk and the closest precedent (#86148 and packages/block-editor/src/hooks/contrast-checker.ts). Note every difference and why.
2. Justify every line
- For each changed line, say what it does, why it is needed, and what breaks without it. Remove anything you cannot justify.
- Check that shared code (ContrastChecker, getContrastWarning) changes only what this PR needs. List every other caller and how it is affected.
3. Test every case on screen, against a trunk build
- Site Editor > Styles > Typography > Text > Color in Twenty Twenty-Five: preset and custom colours, a background colour, a background gradient (light and dark stops), a legacy color.gradient, a text gradient, a background image, oklch() and color-mix() colours, transparent text.
- Check the warning text and the screen reader announcement for each.
- Post editor: block text and background colour warnings still behave as on trunk, including oklch() colours.
4. Checks
- npm run test:unit on the touched tests, npm run lint:js on every changed file, npm run typecheck. Break the code each test covers and confirm the test fails.
- Compare any failing CI job with trunk's latest run.
5. Report
Write a short summary for the thread: each review point and how it was addressed, every difference from trunk, open questions (one sentence each), and anything not fixed with the reason. Re-request review only when every case passes or is listed as an open question.
What?
Part of #48055
Shows a contrast warning in Styles > Typography > Text, as suggested in #48055 (comment).
How?
getContrastWarning, now a private API.ContrastCheckernow skips colors it can't read, such asoklch(), instead of treating them as black.Follow-ups
Left out to keep this small:
Testing Instructions
Screenshots or screencast
Screen.Recording.2026-11-02.at.4.35.47.PM.mov
Use of AI Tools
Claude Code helped write the code and tests. I reviewed and tested the changes.