Repository navigation
fix(theme-neutral): Badge error label meets WCAG AA (#4414) - #4446
Merged
cixzhang merged 2 commits intoAug 24, 2026
Merged
Conversation
`<Badge variant="error">` rendered white on the neutral theme's light-mode red `#e33f4a` at 4.14:1. The label is 12px at weight 500, so WCAG 2.1 AA asks for 4.5:1 — the 3:1 large-text allowance does not apply. This is the `color-contrast` violation the a11y audit reported as "Badge, affects 2/5 stories" on every PR touching `packages/core/src/Badge/`; those two stories are exactly the ones containing an error badge. Flipping the label to dark does not work either — `#171717` on `#e33f4a` is 4.33:1, still short. So the fill moves one tonal step down to `#c9303a`, which reaches 5.29:1 against white while holding the hue (OKLCH H 21.9 -> 22.8, C 0.200 -> 0.189). StatusDot and the ProgressBar `--color-error` rebinding move with it. Both are commented in this file as tracking the badge fill so a dot and its badge read as one status language; leaving them behind would have broken that stated invariant. Dark mode is untouched — dark text on `#ff705d` is 6.60:1. `--shadow-inset-error` deliberately keeps `#e33f4a4D`: it is a 30%-alpha focus ring, not a text surface, so the 4.5:1 threshold never applied to it. The file header claimed "All 9 saturated badge values pass WCAG AA (5.6-9.6 contrast range)", which was not true of error. It now points at the guard. Adds `scripts/check-badge-contrast.test.mjs`: it resolves every theme's badge label/fill pair through `light-dark()`, `var()` indirection and alpha compositing over the theme's own surface, then holds all of them to 4.5:1. The pairing cannot be read off the global `--color-*` tokens, because each theme re-binds the fill inside its own `components.badge` block. Running it across all seven themes surfaced four pre-existing shortfalls beyond the reported one, recorded as an exact known-gap list so no new shortfall can land and no fixed one can linger: butter/light+dark variant:info #ffffff on #4883fd 3.54:1 butter/light+dark variant:neutral #225BFF on #ffee7b 4.43:1 butter/light+dark variant:error #ffffff on #fc473b 3.44:1 gothic/light+dark variant:warning #6c5010 on #d3c490 4.32:1 Those fills are pinned to brand values from a spec, so moving them is a design call rather than a bug fix and is left to maintainers. The regenerated CLI theme template is larger than the source change because it had already drifted: it was missing the `statusdot` block entirely. Fixes meta#4414
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
github-actions
Bot
requested review from
cvkxx,
ernestt,
kentonquatman and
rubyycheung
July 28, 2026 05:48
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
AKnassa
marked this pull request as ready for review
July 30, 2026 04:57
AKnassa
requested review from
cixzhang,
ejhammond,
imdreamrunner and
josephfarina
as code owners
July 30, 2026 04:57
Regenerated packages/cli/assets/templates/themes/neutral/neutralTheme.ts via pnpm bundle:cli-themes from the merged theme source (templates moved to assets/ in the cli restructure; upstream's regenerated template had the statusdot block with the pre-fix red).
cixzhang
approved these changes
Aug 24, 2026
cixzhang
left a comment
Contributor
There was a problem hiding this comment.
Thanks — 4.14:1 to 5.29:1 with the hue held, dark mode untouched, and a test that holds every theme to it. Landing.
[Reviewed by Robohands]
cixzhang
pushed a commit
that referenced
this pull request
Aug 24, 2026
* fix(theme): give syntax punctuation its own AA-passing colour Fixes #5386. --color-syntax-punctuation borrowed --color-text-disabled, a token WCAG deliberately exempts from the normal-text contrast requirement. Three themes measured under 4.5:1 against their syntax background: neutral (2.42:1 light, 2.53:1 dark), chocolate (3.06:1/2.56:1), matcha (3.83:1/2.73:1). butter/gothic/stone/y2k already had a passing punctuation colour of their own. The shared default now points at --color-text-secondary (already used for --color-syntax-comment, already AA). The three failing themes get a dedicated punctuation colour instead of inheriting the default, since each defines its own syntax palette: neutral #6e6e6e / #a0a0a0 (4.89:1 / 7.57:1) chocolate #9e622e / #cb884d (4.84:1 / 6.12:1) matcha #566a39 / #92af6a (5.19:1 / 7.02:1) Adds scripts/check-syntax-punctuation-contrast.test.mjs, resolving --color-syntax-punctuation/background through light-dark()/var() indirection (the pattern from #4446's badge contrast guard) and holding every theme to AA in both colour schemes. Regenerated the CLI theme template bundle (pnpm bundle:cli-themes) for the three changed themes. * fix(theme): fail loud on an unresolvable colour format in the contrast guard Per @gonzoblasco's review on #5414: resolve() returned null for anything that wasn't hex, so a theme using oklch()/hsl()/rgb() would silently drop out of the resolved rows with no clue why — the length guard would just report the wrong count with no hint which theme or format broke it. Throw with the actual unresolvable value instead. All seven themes still resolve cleanly through hex/light-dark()/var() today, so this is a no-op change in current behavior.
This branch was successfully deployed
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.
Summary
Fixes #4414.
<Badge variant="error">renders white on the neutral theme's light-mode red#e33f4aat 4.14:1. The label is 12px at weight 500, so WCAG 2.1 AA asks for 4.5:1 — the 3:1 large-text allowance doesn't apply. This is thecolor-contrastviolation the a11y audit reports as "Badge, affects 2/5 stories" on essentially every PR that touchespackages/core/src/Badge/; those two stories are exactly the ones containing an error badge.Flipping the label to dark doesn't rescue it either —
#171717on#e33f4ais 4.33:1, still short. So the fill moves one tonal step down.#e33f4a#ffffff#c9303a#ffffff#c9303aholds the hue — OKLCH H 21.9 → 22.8, C 0.200 → 0.189. Dark mode is untouched: dark text on#ff705dis 6.60:1.What else moved, and what didn't
StatusDot and the ProgressBar
--color-errorrebinding move with it. Both are commented inneutralTheme.tsas tracking the badge fill so "a dot and its badge read as one status language". Leaving them on the old red would have broken that stated invariant.--shadow-inset-errordeliberately keeps#e33f4a4D. It's a 30%-alpha focus ring, not a text surface, so the 4.5:1 threshold never applied to it and changing it would be a visual change with no accessibility gain.The file header claimed "All 9 saturated badge values pass WCAG AA (5.6–9.6 contrast range)", which wasn't true of error. It now points at the guard instead of restating a number.
The guard
scripts/check-badge-contrast.test.mjsresolves every theme's badge label/fill pair throughlight-dark(),var()indirection (recursively, with a cycle guard) and alpha compositing over the theme's own surface token, then holds all of them to 4.5:1.Resolution has to go through the component block: each theme re-binds the fill inside its own
components.badge, so the pairing that actually ships cannot be read off the global--color-*tokens. Reading the tokens is what makes this bug easy to misdiagnose.Pre-existing shortfalls this surfaced
The issue asked for the check to be run per theme. Doing that found four more, in themes I have not touched:
info#ffffffon#4883fdneutral#225BFFon#ffee7berror#ffffffon#fc473bwarning#6c5010on#d3c490Both themes pin those fills to brand values from a spec ("pinned to the brand colors from the spec"), so moving them is a design call rather than a bug fix — left for maintainers. They're recorded as an exact known-gap list, so a new shortfall fails the build and a fixed one fails until it's removed from the list. Happy to follow up with values if you want them changed.
chocolateandmatchadefine no badge block and inherit core's defaults, so they have no pair to resolve; the guard asserts that set explicitly rather than silently covering fewer themes than it looks like.Note on the regenerated template
packages/cli/assets/templates/themes/neutral/neutralTheme.tsis generated bypnpm bundle:cli-themes. After merging main (which moved the templates intoassets/and regenerated them, picking up the previously-driftedstatusdotblock), the template diff mirrors the source change exactly.Tests
scripts/check-badge-contrast.test.mjs— 4 tests. Mutation-checked: restoring#e33f4afails 3 of them.Badge, StatusDot and
scriptssuites green.pnpm check:repoclean.