Skip to content

Support forced colors mode - #4244

Merged
amanmahajan7 merged 16 commits into
mainfrom
forced-colors
Oct 27, 2026
Merged

amanmahajan7 merged 16 commits into
mainfrom
forced-colors

Conversation

@amanmahajan7

@amanmahajan7 amanmahajan7 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds support for forced colors mode (Windows contrast themes and Firefox's color override). Today, row selection, the fill handle and the column drag-over target become invisible in this mode.

This PR is built in steps, so the screenshot diffs show exactly what each change does:

  1. ✅ Add visual tests for forced colors mode
  2. ✅ Generate baseline screenshots for the light palette
  3. ✅ Add the dark palette
  4. ✅ Generate the dark palette baseline screenshots
  5. ✅ Add the forced colors styles
  6. ✅ Regenerate the screenshots
  7. ✅ Use SelectedItemText for the focus outline on selected rows, and regenerate the screenshots
  8. ✅ Address review feedback: editor, checkbox focus ring, drag handle, fill drag, theme overrides
  9. ✅ Regenerate the screenshots: drag handle outline, checkbox focus ring on selected rows, and the new editor screenshots
  10. ✅ Show the current page in the website nav (website only, no screenshot changes)

Why forced colors support matters

Forced colors mode is an OS-level accessibility setting.

  • Who uses it: people with low vision, light sensitivity, migraines or some cognitive disabilities, often all day and in every app, including the data-heavy apps where this grid is embedded.
  • What it does: the user picks a small palette and the browser applies it to every page. It replaces author colors and removes box shadows and background gradients.
  • No opt-out: apps can't turn it off on the user's behalf, so a component that shows state only through a background color loses that state entirely.

In the grid today, as the baseline screenshots show:

  • Selected rows look unselected. Selection still reaches screen readers through aria-selected, but not sighted users.
  • The fill handle disappears. It's an 8px square drawn only with background-color.

From reading the code (screenshots don't cover these, since a drag can't be held mid-drag):

  • The column drag-over target gives no feedback. It's shown only with a background tint.
  • The cells covered by a fill drag aren't highlighted.

Focus outlines were already visible, because the browser forces outline colors to a system color.

Fixing this inside the shared grid fixes every downstream app. Apps can't reasonably patch it themselves without reverse-engineering the grid's internals.

Changes

All the new rules are inside @media (forced-colors: active), so nothing changes outside forced colors mode. The demo website's nav gets the same treatment, so the current page stays visible.

Element Forced colors style
Selected rows, including on hover background-color: SelectedItem, set on the selected-row rule itself
--rdg-selection-color: active cell outline, row focus outline, drag handle, text editor focus border CanvasText; SelectedItemText on selected rows
--rdg-checkbox-focus-color CanvasText; SelectedItemText on selected rows
Text editor (edit cell) --rdg-selection-color: CanvasText, even on selected rows, because the editor's own background is forced to Canvas
Drag handle outline: 1px solid Canvas, so it stands out on both Canvas and SelectedItem backgrounds
Cells covered by a fill drag background-color: Mark
Column drag-over target, and the column being dragged dashed Highlight outline (it replaces the dragged header's focus outline during the drag)
Website nav: current page link, including on hover background-color: SelectedItem

Design notes:

  • Selected rows set only a background color, not a text color, so their text keeps its forced color. AG Grid's selected-row rule also sets only SelectedItem, and its similar Mark highlight rules note that "the browser draws a backplate behind the text to keep it readable".
    • Chromium draws a backplate behind text in forced colors mode, so the text stays readable on any palette.
    • Firefox draws no backplate. It renders the text in CanvasText on SelectedItem, which is readable in the tested palettes but not guaranteed for every theme.
  • SelectedItemText for outlines on selected rows, because CanvasText isn't guaranteed to contrast with SelectedItem. The backplate is only drawn behind text, so outlines are unaffected.
  • SelectedItem is set on the property, not on the public --rdg-row-selected-* variables. An app's own (unlayered) override of those variables would otherwise win, and the browser would then replace it with Canvas, hiding the selection again. This follows AG Grid, which keys its forced value on the selected-row selector. I checked it locally with an app override in Chromium and Firefox.
  • The README has a new "Forced Colors Mode" section. It explains that overriding --rdg-selection-color or --rdg-checkbox-focus-color also overrides their forced colors values outside selected rows, and suggests wrapping such overrides in @media not (forced-colors: active).

Alternatives considered:

  • Also setting color: SelectedItemText: this made text invisible in CI's Chromium palette, where SelectedItemText is white and is drawn on the white backplate.
  • Opting out with forced-color-adjust: none, as React Spectrum's TableView does for its whole table: this avoids the backplate, but the grid would then have to map every border and control color itself. Custom cell content would also stop following the user's palette.

Known trade-offs:

  • Selected-row text gets backplate boxes. In Chromium, selected-row text shows the browser's backplate (small boxes behind the text). It's readable, just not seamless.
  • Firefox's text contrast on selected rows depends on the palette, as described above.

Visual tests

test/visual/forcedColors.test.tsx takes screenshots in forced colors mode of:

  • the active cell, with the drag handle, on a selected row;
  • the active cell on an unselected row;
  • the text editor on a selected row (new in step 8, so it has no "before" screenshot);
  • the focused checkbox on a selected row;
  • the focused checkbox on an unselected row.

How it works:

  • A new emulateMedia browser command (Playwright's page.emulateMedia) turns on forced colors. After each test it restores Playwright's defaults (forcedColors: 'none', colorScheme: 'light').
  • The tests navigate with the keyboard, so :focus-visible matches and no hover styles end up in the screenshots.
  • Light and dark palettes: Windows contrast themes come in both, so the tests run against each. Chromium switches to its dark forced colors palette when dark mode is also emulated.
  • Skipped browsers:
    • WebKit, which matches (forced-colors: active) when emulated but doesn't force any colors;
    • Firefox for the dark palette, since it ignores the emulated color scheme.
  • Accuracy: emulation uses the system palette of the browser and OS running the tests (Linux in CI), not a real Windows contrast theme. The screenshots catch state that disappears or text that becomes unreadable, but a manual check with a Windows contrast theme in Edge is still worthwhile.
  • Not covered by screenshots: the column drag-over outline and the fill-drag highlight, since a drag can't be held mid-drag.

Testing

  • vp run typecheck, vp check, vp run eslint and vp pack pass.
  • Local screenshots in Chromium (light and dark palettes) and Firefox show:
    • visible selected rows and readable text;
    • a visible drag handle and focus outlines;
    • a visible text editor on a selected row.
  • Website nav: local screenshots of the dev server in Chromium (light and dark palettes) and Firefox show the current page link with a SelectedItem background and readable link text.
  • Theme override check: a temporary local test overrode --rdg-row-selected-background-color. Selected rows still computed to SelectedItem and stayed distinct from unselected rows, in Chromium and Firefox.
  • Chromium browser test suite: run locally. The only failures are 3 sorting tests that also fail on main on the same machine.
  • Independent review: an independent review of the earlier version found the editor, checkbox, drag handle, fill-drag and theme-override issues fixed in step 8.
  • Not tested: a real Windows contrast theme.

🤖 Generated with Claude Code

Covers the active cell (with the fill handle) and the focused checkbox,
on selected and unselected rows. Adds an `emulateMedia` browser command
to emulate forced colors. WebKit is skipped, as it matches the media
query when emulated but does not force any colors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
amanmahajan7 and others added 2 commits October 26, 2026 02:38
Windows contrast themes are light or dark, so also test Chromium's dark
forced colors palette. Instead of always skipping WebKit, skip the tests
when the browser does not actually force colors, or ignores the emulated
color scheme (Firefox), so any browser that supports them is covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
amanmahajan7 and others added 2 commits October 26, 2026 02:43
Replaces the runtime color detection with explicit browser checks, as each
browser's behavior is known: WebKit does not force colors, and Firefox
ignores the emulated color scheme. The same tests run and skip as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov-commenter

codecov-commenter commented Oct 26, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.27%. Comparing base (5de8ae4) to head (4e13b30).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4244      +/-   ##
==========================================
+ Coverage   99.23%   99.27%   +0.04%     
==========================================
  Files          44       44              
  Lines        2215     2216       +1     
  Branches      974      974              
==========================================
+ Hits         2198     2200       +2     
+ Misses         17       16       -1     
Files with missing lines Coverage Δ
src/Cell.tsx 100.00% <ø> (ø)
src/EditCell.tsx 99.00% <100.00%> (+0.01%) ⬆️
src/HeaderCell.tsx 98.36% <ø> (ø)
src/style/cell.ts 100.00% <ø> (ø)
src/style/core.ts 100.00% <ø> (ø)
src/style/row.ts 100.00% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Forced colors mode replaces non-system colors, so selected rows looked
unselected, the drag handle disappeared, and the column drag-over target
gave no feedback. Map the selection, focus, and selected row tokens to
system colors, and outline header cells during column drag-and-drop.

Selected rows only set a SelectedItem background: the browser draws a
backplate behind text, which keeps it readable on any palette.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
amanmahajan7 and others added 2 commits October 26, 2026 03:34
… colors mode

CanvasText is not guaranteed to contrast with the SelectedItem background.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@amanmahajan7
amanmahajan7 marked this pull request as ready for review October 26, 2026 03:48
- Set the SelectedItem background on selected rows directly instead of on
  the public selected row tokens, so the selection stays visible when apps
  override those tokens
- Keep the text editor's focus border CanvasText on selected rows, as its
  background is forced to Canvas
- Use SelectedItemText for the checkbox focus ring on selected rows, and
  outline the drag handle with Canvas so it stays visible on any background
- Highlight the cells covered by a fill drag with Mark
- Add an editor screenshot, and restore the context's media defaults
  after each test

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a white background for text unlike in Firefox, is that expected?
The black on blue in Firefox is kinda hard to read 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's expected. Chromium draws a backplate behind text in forced colors mode: the text keeps its forced CanvasText color on a Canvas box, which keeps it readable on any background. Firefox doesn't draw backplates, so the text sits directly on SelectedItem.

We can't set color: SelectedItemText to get white on blue in both browsers. Chromium still draws its Canvas backplate, so the text ends up white on white. I tried that in an earlier iteration of this PR. The only way to remove the backplate is forced-color-adjust: none. It's inherited, so it would also stop forcing colors in custom cell renderers inside selected rows, where an app's own colors could become unreadable.

Firefox's black on blue looks off because we expect white selection text, but the contrast is fine: black on Firefox's default #3399ff is about 7:1, which meets AAA. On Windows, the user's contrast theme supplies its own SelectedItem color.

Comment thread test/globals.d.ts Resolved
@amanmahajan7
amanmahajan7 merged commit aaa1997 into main Oct 27, 2026
6 checks passed
@amanmahajan7
amanmahajan7 deleted the forced-colors branch October 27, 2026 14:36
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.

3 participants