Skip to content

fix(themes): WCAG 2.1 AA colour contrast across all palettes + automated contrast check - #3677

Closed
AKnassa wants to merge 2 commits into
meta:mainfrom
AKnassa:fix/3654-wcag-aa-contrast
Closed

AKnassa wants to merge 2 commits into
meta:mainfrom
AKnassa:fix/3654-wcag-aa-contrast

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3654

What this does

Makes text and icons readable again, everywhere. Every theme that ships with Astryx (plus the default palette) now meets the WCAG 2.1 AA contrast standard in both light and dark mode — and a new automated check keeps it that way on every future PR.

Why

The issue showed muted text failing the 4.5:1 contrast requirement across the design system. A full audit found it was bigger than the screenshots: 258 failing colour pairings across the 8 palettes. Products built on Astryx would fail accessibility audits out of the box.

What changed

  • Colour palettes retuned. The default palette and all 7 themes (butter, chocolate, gothic, matcha, neutral, stone, y2k) had their failing colours nudged just far enough to pass — smallest possible visual change, each theme keeps its personality. Example: neutral's muted text went from #737373 (4.2:1 on its grey background — fail) to #616161 (4.8:1 — pass).
  • Six component bugs fixed that failed in every theme:
    • Tool-call rows and the chat composer's placeholder were painted with the "disabled" colour even though they're active content.
    • Calendar days from the previous/next month were double-faded to near-invisibility (1.4:1) by two stacked opacity rules.
    • Coloured cards (e.g. the blue "Engineering" card) kept grey text that's unreadable on the tint — they now use the matching hue text colour, the same way Banner already does.
    • Lightbox captions and controls floated directly over the photo; they now sit on a dark strip so they're readable over any image.
  • A new automated contrast check (internal/theme-contrast/) runs as part of the normal test suite on every PR. It computes real WCAG ratios from the theme tokens — including see-through colours layered on surfaces and per-theme component restyling — so a regression fails CI with the exact offending pair and numbers. 0 failures across all 16 theme/mode combinations today.
default-dark-badge-variants default-dark-button-destructive default-dark-button-primary default-dark-calendar-selected default-light-badge-variants neutral-dark-badge-variants neutral-dark-button-primary neutral-light-avatargroup neutral-light-badge-variants neutral-light-blockquote neutral-light-calendar neutral-light-card-callout neutral-light-card-colors neutral-light-chattoolcalls neutral-light-checkboxlist neutral-light-lightbox-caption neutral-light-segmented-disabled neutral-light-segmented-icons

One deliberate look change

In dark mode, the default theme's primary buttons and info/success/error badges now use near-black labels on their bright fills instead of white (white only reached 3.1:1 on the bright dark-mode blue). This follows the same rule the warning badge and the neutral theme already use.

How to see it

  • Annotated before/after screenshots with measured ratios are attached below (18 comparisons covering every screenshot from the issue plus the dark-mode change).
  • Locally: CONTRAST_REPORT=1 pnpm vitest run internal/theme-contrast prints the full audit table for every theme and mode.

Not in this PR (follow-ups)

  • Hairline border colours vs. the 3:1 non-text rule (a separate design decision most systems fail today).
  • Table sort/filter icons shown at 35% opacity.
  • The CI axe audit currently never triggers on theme-only changes (check-components filters out theme/ paths) — the new test covers that gap, but the filter may be worth revisiting.
  • Two import-hint-correctness.test.mjs failures exist on main and are unrelated.

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

@AKnassa is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 8, 2026
@AKnassa
AKnassa marked this pull request as ready for review July 8, 2026 04:41
@cixzhang cixzhang added area:cli needs:design-review Affects visuals — Design should review labels Jul 8, 2026
@rubyycheung

rubyycheung commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

I have some distinct palette colors used for each theme. I’ll have a separate PR for this issue. Thanks for flagging :)

We also might introduce different contrast modes to hit different color accessibility ratings

@github-actions github-actions Bot added needs:code-review High-risk change (new package/component/API) — needs human code review before merge community Authored by a community contributor (not on the eng/design team) labels Jul 11, 2026
@humbertovirtudes

Copy link
Copy Markdown
Contributor

The approach here is exactly right and the bulk still applies cleanly to main (I tried the rebase: 29 of 31 files auto-merge). Two spots need a careful, not mechanical, rebase because main moved under them:

  • packages/themes/neutral/src/neutralTheme.ts: your --color-text-secondary / --color-icon-secondary AA fixes (#616161 / #acacac) are still needed and should stay. But the punctuation syntax value here (#737373 / #a3a3a3) is now behind main: fix(theme-neutral): match StatusDot fills to filled Badge colors #4047 (Jul 17) changed it to #a3a3a3 / #525252, so please take main's value there rather than reverting it, or re-audit if it fails AA.
  • packages/core/src/Card/Card.doc.mjs: feat(core): add elevation prop to configurable surfaces #4251 added a transparent variant (and elevation docs) after this branched. Your rewrite drops the transparent description, so on rebase please preserve main's transparent + elevation wording and layer your WCAG re-bind note on top.

Everything else (the internal/theme-contrast audit, the WCAG math + contract, and the component fixes) is unshipped and still wanted, so this is not redundant, just a couple of weeks behind. Rebase reconciling those two files and re-run the contrast audit, and I think it is good to go.

Retune the core default palette and all 7 shipped themes so every real
foreground/background pairing clears WCAG 2.1 AA (4.5:1 text, 3:1
non-text UI) in both light and dark modes — 258 measured failures to 0.

Component fixes independent of any theme: ChatToolCalls, the
ChatComposer placeholder, and dictation interim text no longer paint
active content with the disabled token; Calendar outside-month days no
longer stack disabled opacity on top of their own de-emphasis; tinted
Card variants re-bind text tokens to the matching hue colour (Banner's
existing pattern); Lightbox captions/controls sit on a fixed dark chip
so they stay readable over any media.

Adds internal/theme-contrast: a cross-theme contrast contract that
resolves every theme's tokens (alpha compositing, light-dark(), var()
chains, per-theme component overrides included) and fails CI on any
regression — the automated check requested in the issue.

Fixes meta#3654
)

This branch was cut before main migrated to Vitest 4 and split the config
into `ui` and `node` projects. Under the old flat config, the root
`resolve.alias` mapped `@astryxdesign/core/*` to source for every test, so
internal/theme-contrast/contrast.test.ts resolved fine.

The `node` project deliberately does not `extends: true`, so it inherits
neither that alias nor the StyleX babel plugin — and `internal/**` is in its
include list. After rebasing onto main the suite failed to collect:

    Cannot find package '@astryxdesign/core/theme'

and, once pointed at source directly, failed again on

    Unexpected 'stylex.defineVars' call at runtime

because `@astryxdesign/core/theme` reaches theme/tokens.stylex.ts through
defineTheme.ts:53. The suite genuinely needs StyleX compilation, so it
belongs in `ui`. Claimed there and excluded from `node`, scoped to this one
directory so no other internal/ suite changes projects.

Restores the pre-migration behaviour rather than changing what is tested:
43 tests across the 3 theme-contrast files pass again.
@vercel

vercel Bot commented Jul 27, 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, Comment Jul 27, 2026 12:06am

Request Review

@AKnassa

AKnassa commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto main (25def2f10) and force-pushed. Pre-rebase commit was bb5ae0d04.

Three conflicts, none mechanical:

  • neutralTheme.ts (3 hunks): main reformatted, this branch changed values. Kept the values. --color-text-secondary: ['#616161', '#acacac'] is intact.
  • Card.doc.mjs: main added a transparent variant and renamed --color-<name>-background to --color-background-<name>; this branch added the text re-bind note. Kept both, plus main's new elevation entry. Card.tsx auto-merged with both changes.
  • ChatToolCalls.tsx (2 hunks): main added a prefers-reduced-motion guard, this branch changed the colour. Kept both.

The second commit fixes a break the rebase exposed. This branch predates the Vitest 4 split. The node project does not set extends: true, so it has neither the @astryxdesign/core/* alias nor the StyleX plugin, and internal/** is in its include list. contrast.test.ts failed to collect with Cannot find package '@astryxdesign/core/theme', and pointing it at source instead hit stylex.defineVars uncompiled, reached via defineTheme.ts:53. Moved internal/theme-contrast/** into the ui project and excluded it from node, scoped to that one folder. Any long-lived branch with tests under internal/ or scripts/ that import @astryxdesign/core will hit the same thing.

After the rebase: internal/theme-contrast 43/43, Card/Chat/Calendar/Lightbox/theme plus contrast 877/877, CI green. The audit above reports Card with zero violations, where it reports 8 of 14 stories failing on PRs without this fix.

Does not fix Badge variant="error" (4.14:1), filed as #4414. That issue also notes effective.ts models the badge error pair here yet reports no failure.

Still needs the annotated before and after screenshots.

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Modified Components

Calendar
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1319 -
Complexity N/A Very High (127) -
Card
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 223 -
Complexity N/A High (18) -
Chat
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 5336 -
Complexity N/A Very High (437) -
Lightbox
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 581 -
Complexity N/A Very High (62) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 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/8 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Generated by PR Enrichment workflow | View full report

@cixzhang

Copy link
Copy Markdown
Contributor

Thanks @AKnassa — this was a big, careful audit and both halves of it are now true on main, just not through this PR.

The tokens landed in #4557 (neutral's light secondary darkened past AA), and #3654 closed on 31 July. The automated check you proposed also exists now — packages/core/src/theme/contrast.ts and its test — so future palettes are guarded the way you argued they should be.

Closing as superseded rather than as anything you got wrong. You were right about the problem and right about needing a check rather than a one-off fix.

Reopening is welcome any time — merge main in first, since the branch has aged. Discord if you'd rather talk it through with a person.

[Reviewed by Robohands]

@cixzhang cixzhang closed this Aug 24, 2026
@github-actions
github-actions Bot deleted the fix/3654-wcag-aa-contrast branch August 24, 2026 06:53

This branch was successfully deployed

1 active deployment
Preview — ea820886 Deployed Jul 27, 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.

[Bug] Widespread WCAG 2.1 AA colour contrast failures across Design System, accessibility

4 participants