Repository navigation
fix(a11y): make white button labels readable in every state, not just at rest - #711
Merged
Merged
Conversation
… at rest Thirty-five white-on-fill combinations were below WCAG AA, and almost all of them were the *hover* state rather than the resting one. A button sat at a perfectly legible `bg-brand-600` and then lightened to `bg-brand-500` on hover, dropping to 3.68:1 — legible right up until you reached for it. Hover is the state a person is in at the moment they are reading the label to decide whether to click it. Resting colours are left alone wherever they already passed, so the app looks the same until you point at something. Hovers move a rung darker instead of a rung lighter. Three resting states did fail and moved up: the Run button, the kill-process button, and the error boundary's retry. The trap this encodes: the rung that carries white text is not the same across hues. Red and blue manage it at 600; green, amber and yellow do not until 700, because a saturated mid-green is far lighter than a mid-red at the same number. `bg-green-600` reads as the safe choice and is not one — it is 3.22:1, and it was painting the Run button, which is the most-pressed control in the product. #703 said this was 38 places on the brand ramp. That was wrong twice over: the count double-counted, because `bg-brand-500` matches inside `hover:bg-brand-500`, and the worst offenders were not brand colours at all but hardcoded greens and ambers, which the issue attributed to #706. The test walks every component source, finds each `text-white` element's fill class, and computes the contrast from the palette's real sRGB values — read out of the compiled stylesheet, because Tailwind v4 restated its palette in OKLCH and the numbers moved. A class it does not have a value for fails a test of its own rather than being skipped, so the guard cannot rot into a no-op. Verified it fails: putting one button back produces "ErrorBoundary.tsx:51 resting bg-brand-500 is 3.68:1". It caught that for real during this change, when a `git checkout` quietly reverted the fix to that file. Closes #703.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wave 3 of the UI review.
Closes #703.
The finding, which is not what #703 said
35 white-on-fill combinations were below AA, and almost all of them were the
hover state, not the resting one:
A button sat at a perfectly legible
bg-brand-600and then lightened onhover to 3.68:1 — legible right up until you reached for it. Hover is the state
a person is in at the moment they're reading the label to decide whether to
click.
So resting colours are left alone wherever they already passed: the app looks
identical until you point at something. Hovers move a rung darker instead of
lighter. Three resting states did fail and moved up — Run, kill-process, and
the error boundary's retry.
Where #703 was wrong
I wrote it, and it was wrong twice:
bg-brand-500matchesinside
hover:bg-brand-500. The real resting-state count was one.bg-green-600 text-white— a hardcoded palette class at 3.22:1 — which theissue had filed under [P2][convention] 340 hardcoded palette colours in 46 files bypass the theme tokens #706.
The trap: the rung that carries white text differs by hue. Red and blue
manage it at 600; green, amber and yellow don't until 700, because a saturated
mid-green is far lighter than a mid-red at the same number.
bg-green-600reads as the safe choice and isn't one — and it was painting the most-pressed
control in the product.
The guard
src/__tests__/button-contrast.test.tswalks every component source, findseach
text-whiteelement's fill class, and computes contrast from thepalette's real sRGB values — read out of the compiled stylesheet, because
Tailwind v4 restated its palette in OKLCH and the numbers moved.
Three properties worth noting:
finding nothing.
skipped, so it can't rot into a no-op.
bg-red-500/20tints are excluded — those are panel backgrounds with nolabel on them.
Verified it fails: reverting one button gives
ErrorBoundary.tsx:51 resting bg-brand-500 is 3.68:1. It caught that for realmid-change, when a
git checkoutquietly reverted the fix to that file.Verification
from 35
🤖 Generated with Claude Code