Skip to content

fix(theme): meet AA for dark-mode error label text - #5025

Closed
AKnassa wants to merge 4 commits into
meta:mainfrom
AKnassa:ak-5019-dark-error-contrast
Closed

AKnassa wants to merge 4 commits into
meta:mainfrom
AKnassa:ak-5019-dark-error-contrast

Conversation

@AKnassa

@AKnassa AKnassa commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5019.

What

Two moves, one goal: the error colour meets AA in dark mode without trading one failure for another.

1. The token. The default --color-error now uses #E3193B in both modes — the same shape as --color-success, which already shares one hex across modes. The dark half was #F5394F, which held white label text at 3.76:1, below WCAG AA's 4.5:1 for normal text, so any theme that left the status colours alone rendered a failing destructive button in dark mode. #E3193B is one step darker on the same ramp and is already the dark half of --color-background-error-inverted, so white-on-#E3193B in dark mode was an approved pairing in this palette before this change.

2. The text roles. Measuring every --color-error consumer (43 across core/lab/charts) showed the token also paints text — and no single hex can clear 4.5:1 under white as a fill and 4.5:1 as text on the dark surfaces; the luminance windows don't overlap. The fill token was already below AA as dark text before this change (4.37:1 on the surface, 3.87:1 on the popover). Components rendering supporting/status text in the fill token now use --color-text-red, the pairing FieldStatus and ChatComposer already ship: Chat message metadata ("failed to send"), Chat tool-call stats and errors (the error icon's currentColor tint halo follows its glyph), the TextArea and RichTextEditor over-limit counters, lab's ChatUnreadDivider label (its 1px rule stays on the fill token — a redundant cue that passes 3:1) and Stat's negative delta. Each carries a test pinning the element to the text token. LogStream's derived dark mix retunes 82% → 72% to keep its documented 4.5:1 against the darker token.

A contrast assertion now covers the default pairs that fall through to colorDefaults (error, success, warning, and the default accent), plus the error fill against surface, body, and popover, so a future retone cannot regress silently. The regenerated CLI token doc rides along (generate-token-docs.mjs). All seven shipped themes retone both --color-error and --color-on-error, so none inherits the change.

Measured

Same probe as the issue — the rendered DOM (base tokens, getComputedStyle):

pair (dark) before after
white on --color-error (destructive button) 3.76 4.70
white on --color-error (light mode) 4.70 4.70 (unchanged)
--color-error vs surface / body / popover (destructive focus ring, ≥ 3:1) 4.37 / 5.02 / 3.87 3.50 / 4.02 / 3.09
Chat error metadata text on body 5.02 (fill token) 11.06 (--color-text-red)
TextArea over-limit counter on the input surface 4.37 (already failing) 9.64
LogStream error-level text on its surface 5.28 4.86 (retuned mix)

The dark popover ring pair sits at 3.09:1 with ~0.1 of headroom; a test pins it so a popover retone cannot cross the floor silently.

Deliberately left as-is, for review

  • Destructive DropdownMenuItem label on the dark popover: 3.87 → 3.09. It was below AA before this change; moving it to --color-text-red would also recolour the destructive action's identity in both modes, which feels like its own call. Happy to include it here or split it out.
  • Banner's error icon on the --color-error-muted wash (2.66 vs the composited wash) and CircularProgress's error arc vs its muted track (2.66): the adjacent title names the status and the track is the decorative rail, so both arguably fall under the redundant-cue/rail exemptions the test file already documents. Rebasing the dark wash on the new hue only reaches 2.89–3.03, so there is no clean token-level fix.
  • --color-error-muted dark still derives from the old hue (#F5394F3F vs light's #E3193B33). Text on the wash is always --color-text-red (FieldStatus, ChatComposer, Banner), so nothing reads on it; kept to avoid visual churn.
  • --color-on-accent / --color-accent (3.11:1 dark) is not retoned: --color-accent is also the focus outline, and a dark accent that clears 4.5:1 under white lands at ~3.05:1 against the surface — the ring would sit at the 1.4.11 floor with no margin. The assertion pins the pair at its current floors (light ≥ 4.5, dark ≥ 3); deriving it inside the generator's guarantee is the durable fix, per the issue's own split with Overriding one side of a colour pair silently voids the contrast guarantee #5014.

How to check

  • pnpm exec vitest run packages/core/src/theme/expandColorScale.test.ts — the colorDefaults WCAG contrast on the fall-through pairs (#5019) block fails at 3.763 without the token change and passes with it.
  • Component tests pin each migrated text element to the text token (Chat, TextArea, RichTextEditor, ChatUnreadDivider, Stat).
  • Storybook → Core/Button → Destructive, theme None (base tokens), mode Dark.

Screenshots

5019-dark-destructive-aa

The default --color-error dark half (#F5394F) held white label text at
3.76:1 — below WCAG 1.4.3's 4.5:1 — so any theme that left the status
colours alone rendered a failing destructive button in dark mode. Use
#E3193B in both modes (the --color-success precedent; the hex is already
the dark half of --color-background-error-inverted), which measures
4.70:1 under white and stays above the 3:1 non-text floor against the
dark surfaces for the destructive focus ring.

Adds contrast assertions over the colorDefaults fall-through pairs
(error, success, warning, default accent) so a retone cannot regress
silently. The dark accent stays pinned at the 1.4.11 floor: it is also
the focus outline, and darkening it to clear 4.5:1 under white would
break the ring against dark surfaces — deriving that pair inside the
generator guarantee is tracked with meta#5014.

Fixes meta#5019
@vercel

vercel Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 16, 2026 5:25pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 14, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Aug 14, 2026
github-actions Bot added a commit that referenced this pull request Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Chat (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 5383 -
Complexity N/A Very High (439) -
TextArea (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 421 -
Complexity N/A Very High (66) -
LogStream (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 454 -
Complexity N/A Very High (45) -
Stat (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 203 -
Complexity N/A Medium (7) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 1.2KB
@astryxdesign/lab N/A 3.7KB 1.6KB

Accessibility Audit

Status: 2 accessibility violation(s) found — 2 serious.

Chat - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/9 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
LogStream - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/3 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

Self-review round on the meta#5019 token change.

LogStream's dark error-level text derives from the error token via an
82% color-mix that was tuned to clear 4.5:1 for small text against the
old #F5394F; the darker #E3193B silently invalidated that tuning
(4.21:1 on the surface, 4.06:1 over the 6% row wash). 72% restores
4.86:1 / 4.69:1 and keeps the derivation on the themeable token.

The destructive focus-ring assertion now covers body and popover, not
just the default surface, making the changeset's "against the dark
surfaces" plural literally the asserted guarantee. The dark popover
pair sits at 3.09:1 with ~0.1 of headroom; the test pins it so a
popover retone cannot cross the 3:1 floor silently.

Refs meta#5019
The error fill token is tuned for solid fills under white foregrounds;
as dark-mode text it sat below WCAG AA even before meta#5019 darkened it
(4.37:1 on the surface), and the darkening pushed every text use lower.
Migrate the supporting/status text roles to --color-text-red — the
pairing FieldStatus and ChatComposer already ship — taking those reads
from failing to 8.5-11:1 in dark mode:

- Chat: message metadata error status, tool-call deletions stat and
  error status color (the icon's currentColor tint halo follows), and
  the dead errorText key for consistency
- TextArea and lab RichTextEditor: over-limit counter
- lab ChatUnreadDivider: label (the 1px rule keeps the fill token —
  a redundant cue that passes 3:1 as a fill)
- lab Stat: negative delta

Each migration landed red-first: a test pinning the element's atomic
color rule to the text token's var reference failed against the fill
token, then passed after the one-line change. Also softens the
accent-floor test comment (the ring would sit at the 1.4.11 floor,
not below it) and notes the sweep in the changeset.

Refs meta#5019
@AKnassa
AKnassa marked this pull request as ready for review August 14, 2026 05:44
github-actions Bot added a commit that referenced this pull request Aug 14, 2026
Resolves the PR meta#5025 conflict. Upstream promoted RichTextEditor out of
packages/lab into the new @astryxdesign/richtext package (meta#4678), which is
what GitHub reported as conflicting; git rename detection carried the
--color-text-red counter change to packages/richtext/src/RichTextEditor.tsx
along with its test. No hand edits were needed - the only lines the merge
dropped were unrelated prettier reflow.
@AKnassa
AKnassa requested a review from potatowagon as a code owner August 16, 2026 17:22
@AKnassa

AKnassa commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Merged main in. The conflict was the RichTextEditor move into @astryxdesign/richtext (#4678); rename detection carried the counter change and its test across, so there was nothing to resolve by hand.

Separately, a call I would like from you before review.

Every shipped consumer of --color-text-red pairs it with a tinted backing (FieldStatus and ChatComposer on --color-error-muted, Badge on --color-background-red), and gothic, butter and y2k tune the token as a dark maroon for exactly that wash. The six swept components set color only. Measured on --color-background-surface, before (--color-error) to after (--color-text-red):

theme before after
gothic 8.33 1.40
butter dark 9.16 1.40
y2k dark 11.69 1.22

The other five themes are unaffected or improve, including default dark at 3.50 to 9.64. y2k light improves 1.50 to 9.13; only its dark half regresses.

packages/lab/src/Schedule/shared.tsx:1213 already puts --color-text-red on a near-bare card and measures 1.05:1 in gothic on main, so this is an existing pattern rather than a new one, but this PR would add six more sites to it.

Options as I see them: retone --color-text-red in those three themes, add a token for red text on untinted surfaces, or narrow the sweep and solve dark error text another way. Happy to take whichever you prefer.

@gonzoblasco

Copy link
Copy Markdown
Contributor

Hi @AKnassa, great writeup - the two-move split (retone the fill token + move text consumers to the text token) is exactly the right shape for this problem, because as you note the fill and text luminance windows genuinely don't overlap.

I verified the core numbers independently against WCAG 2.1 (relative luminance, 4.5:1 normal text / 3:1 non-text):

  • white on #E3193B = 4.70:1 dark and light. Confirmed.
  • #E3193B against a #0a0a0a-style surface = 4.21:1, so the destructive focus ring clears the 3:1 non-text floor with margin. Good.

A few things I'd want checked or pinned before this lands:

1. The DropdownMenuItem trade-off deserves a decision, not a deferral.
Leaving the destructive DropdownMenuItem label on the fill token at 3.09:1 (dark popover) is defensible if the intent is "don't recolor the destructive identity", but it's the one place in this PR where a label (normal text) stays under 4.5:1 after the change. Since the PR already establishes that fill-as-text fails and moves other text consumers, this is now an inconsistency: every other text consumer moves to the text token, but this one stays because of color-identity. I'd suggest either moving it to --color-text-red too (treating the identity as carried by the icon/glyph rather than the label tint), or explicitly pinning 3.09:1 in the test as a deliberate exception with the rationale in the comment - so a future retone of the popover doesn't silently cross below it.

2. The accent/on-accent dark pin at 3:1 is the right call, but the test comment could warn louder.
Pinning --color-on-accent/--color-accent at the 1.4.11 floor (dark >= 3:1) rather than 4.5:1 is correct given the focus-ring role, and the rationale is well documented. The only risk: a reader skimming the test sees toBeGreaterThanOrEqual(3) next to a status pair and assumes it's a typo. Consider an explicit // not a typo - see #5014 marker on that assertion, since it's the one place in this file where the floor differs from the others.

3. LogStream retune 82% -> 72%: worth confirming the "failed to send" case.
The 72% mix keeps 4.5:1 on the surface, but it also lowers the contrast of the level text itself. For error-level log lines ("failed to send" style messages), the level label is often the first thing a user scans. Not blocking, just a sanity check.

4. Small thing: the injected-CSS test helper is duplicated across 5 test files.
The injectedCss() + escapeRegExp() helpers appear verbatim in ChatMessageMetadata, ChatToolCalls, TextArea, ChatUnreadDivider, and Stat tests. It's a clean approach, but 5 copies is a maintenance smell - if the StyleX rule format ever changes, all five break independently. Worth hoisting to a shared test util (e.g. __tests__/assertToken.ts) so the token-pinning assertions have a single home.

Overall: this is a strong, well-measured fix. The token-vs-text separation is the correct model and the regression assertions are the right guard. My main ask is to turn the DropdownMenuItem deferral into an explicit decision with a pinned test, and to de-duplicate the CSS-scan helper.

@cixzhang

Copy link
Copy Markdown
Contributor

Thank you for the measured dark-mode contrast work. Color-token and palette changes are now coordinated as owner-led accessibility work rather than parallel implementation PRs. Please follow #4475 for the program direction; we are closing this attempt.

@cixzhang cixzhang closed this Aug 28, 2026
@github-actions
github-actions Bot deleted the ak-5019-dark-error-contrast branch August 28, 2026 18:11

This branch was successfully deployed

1 active deployment
Preview — 3484e948 Deployed Aug 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default error colour fails AA in dark mode (white on #F5394F = 3.76:1)

3 participants