Skip to content

fix(a11y): add destructive-muted-foreground so error descriptions meet WCAG AA - #94

Open
navajyoth-puthalath13 wants to merge 1 commit into
ohcnetwork:mainfrom
navajyoth-puthalath13:fix/destructive-description-contrast
Open

navajyoth-puthalath13 wants to merge 1 commit into
ohcnetwork:mainfrom
navajyoth-puthalath13:fix/destructive-description-contrast

Conversation

@navajyoth-puthalath13

Copy link
Copy Markdown

Closes #93

The intent

In the destructive Alert and the Attachment error state, the description is designed to sit quieter than the title. The title says what went wrong; the description is supporting detail. This PR keeps that hierarchy.

The problem

The quietness came from opacity: text-destructive/90 (Alert) and text-destructive/80 (Attachment). Opacity makes text see-through, so the red gets lighter. --destructive (red-600) only passes on white at 4.76:1, so the faded text fell below WCAG AA's 4.5:1:

Component Before
Alert description 4.49:1 ❌
Attachment description, light 4.11:1 ❌
Attachment description, dark 4.37:1 ❌

The Alert gap is tiny and hard to see by eye, but WCAG doesn't round, and these are error messages the user needs to read.

The solution

Keep the red's lightness and hue, and lower only its saturation to 90%. Contrast depends on lightness, so it holds. The colour is solid, so it doesn't depend on the background. And the description still reads a little quieter than the title.

Lightness Saturation Hue Contrast
Title (red-600) 57.7% 0.245 27.3 4.76:1
Description before (90% opacity) lighter ~ 27.3 4.49:1 ❌
Description after (90% saturation) 57.7% 0.2205 27.3 4.85:1 ✅

New token: --destructive-muted-foreground, the red counterpart of --muted-foreground:

Mode Value Contrast on card
Light oklch(from var(--color-red-600) l calc(c * 0.9) h) (≈ #de2022) 4.85:1 ✅
Dark oklch(from var(--color-red-400) l calc(c * 0.9) h) (≈ #f86c6d) 6.30:1 ✅
High contrast, light var(--color-red-700) 6.42:1 ✅
High contrast, dark var(--color-red-300) 9.33:1 ✅
Protanopia, light var(--color-yellow-800) 6.87:1 ✅
Protanopia, dark var(--color-yellow-300) 13.54:1 ✅

Tritanopia inherits the light and dark values.

What changed

  • src/index.css: the token in :root, .dark, both high-contrast blocks and both protanopia blocks, plus the @theme inline mapping
  • alert.tsx: text-destructive/90 → text-destructive-muted-foreground
  • attachment.tsx: text-destructive/80 → text-destructive-muted-foreground
  • colors-page.tsx: the token documented in the Text swatches, the Pairings table and the High Contrast note
  • public/registry/…/alert.json, attachment.json: regenerated

Unchanged: --destructive, titles, icons, borders, rings, buttons, menus, font weight and size.

Why a new token: structure for the destructive colours

Before this PR, one token (--destructive) did every red job: borders, rings, tinted backgrounds, icons, titles and descriptions. Grey text has a structure (foreground, muted-foreground, soft-foreground); red didn't, so the descriptions improvised with opacity. This adds the missing text level:

Token Job
--destructive Red for shapes and titles (unchanged)
--destructive-muted-foreground (new) Quieter red for description text
  • Red text gets its own role, like grey text, so red text never needs opacity again.
  • High-contrast mode now strengthens red text. It didn't before.
  • Protanopia mode gets proper text shades.
  • Text contrast is independent of the shape red, so a future change to --destructive can't silently break it.
  • It follows .claude/skills/better-colors: solid colour for text, one token per role. It's built from a palette token with relative colour, as bubble.tsx already does (oklch(from var(--primary) 0.93 calc(c*0.4) h)). For Figma, the values are #de2022 (light) and #f86c6d (dark).

How I tested it

I compared the original and the new version in Storybook using a switch between the two, in light and dark mode, to make sure the description still reads as quieter than the title. axe reports no color-contrast violations on the Alert or Attachment examples in light mode, and I verified the dark-mode values by calculation. Lint, format, typecheck, registry:check and build pass.

Notes

  • In light mode the token is meant for card and page backgrounds (4.85 / 4.64). Like today's red titles, it doesn't reach 4.5:1 on muted-background (4.44) or on red tints (4.06), and neither component uses those.
  • Open questions: is the token name OK? Should the registry ship this token (via cssVars) so installs get it?

🤖 Generated with Claude Code

…t WCAG AA

The destructive Alert and Attachment error descriptions are meant to sit
quieter than the title. That quietness came from opacity (/90, /80), which
lightened red-600 below 4.5:1 (4.49 and 4.11 in light, 4.37 in dark).

Add a red text token, --destructive-muted-foreground: the destructive red
at 90% chroma, keeping its lightness and hue. It's a solid colour, so the
description stays a little quieter than the title while contrast holds
(4.85:1 light, 6.30:1 dark). High contrast uses red-700 / red-300 and
protanopia uses yellow-800 / yellow-300. Both descriptions use it.

--destructive, titles, icons, borders and buttons are unchanged.

Document the token on the Colors page.

Closes ohcnetwork#93

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destructive Alert and Attachment error descriptions fail WCAG AA colour contrast

1 participant