Repository navigation
Support forced colors mode - #4244
Conversation
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]>
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]>
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 Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
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]>
… colors mode CanvasText is not guaranteed to contrast with the SelectedItem background. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
This has a white background for text unlike in Firefox, is that expected?
The black on blue in Firefox is kinda hard to read 🤔
There was a problem hiding this comment.
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.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
SelectedItemTextfor the focus outline on selected rows, and regenerate the screenshotsWhy forced colors support matters
Forced colors mode is an OS-level accessibility setting.
In the grid today, as the baseline screenshots show:
aria-selected, but not sighted users.background-color.From reading the code (screenshots don't cover these, since a drag can't be held mid-drag):
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.background-color: SelectedItem, set on the selected-row rule itself--rdg-selection-color: active cell outline, row focus outline, drag handle, text editor focus borderCanvasText;SelectedItemTexton selected rows--rdg-checkbox-focus-colorCanvasText;SelectedItemTexton selected rows--rdg-selection-color: CanvasText, even on selected rows, because the editor's own background is forced toCanvasoutline: 1px solid Canvas, so it stands out on bothCanvasandSelectedItembackgroundsbackground-color: MarkHighlightoutline (it replaces the dragged header's focus outline during the drag)background-color: SelectedItemDesign notes:
SelectedItem, and its similarMarkhighlight rules note that "the browser draws a backplate behind the text to keep it readable".CanvasTextonSelectedItem, which is readable in the tested palettes but not guaranteed for every theme.SelectedItemTextfor outlines on selected rows, becauseCanvasTextisn't guaranteed to contrast withSelectedItem. The backplate is only drawn behind text, so outlines are unaffected.SelectedItemis 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 withCanvas, 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.--rdg-selection-coloror--rdg-checkbox-focus-coloralso overrides their forced colors values outside selected rows, and suggests wrapping such overrides in@media not (forced-colors: active).Alternatives considered:
color: SelectedItemText: this made text invisible in CI's Chromium palette, whereSelectedItemTextis white and is drawn on the white backplate.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:
Visual tests
test/visual/forcedColors.test.tsxtakes screenshots in forced colors mode of:How it works:
emulateMediabrowser command (Playwright'spage.emulateMedia) turns on forced colors. After each test it restores Playwright's defaults (forcedColors: 'none',colorScheme: 'light').:focus-visiblematches and no hover styles end up in the screenshots.(forced-colors: active)when emulated but doesn't force any colors;Testing
vp run typecheck,vp check,vp run eslintandvp packpass.SelectedItembackground and readable link text.--rdg-row-selected-background-color. Selected rows still computed toSelectedItemand stayed distinct from unselected rows, in Chromium and Firefox.mainon the same machine.🤖 Generated with Claude Code