fix(site): increase Switch off-state contrast to meet WCAG 1.4.11 (#30547)
The unchecked `Switch` track and its hover state did not reach the 3:1 non-text contrast required by WCAG 1.4.11 against the page or the thumb in either theme (1.18:1 to 1.91:1 in dark, 1.15:1 to 1.48:1 in light). This adds a `surface-control` token for the unchecked track (dark: zinc-500 `#71717A`; light: `240 5% 57%` `#8C8C97`, the lightest zinc-hue grey that keeps 3:1 against `surface-secondary`, so unchecked tracks stay easy to tell apart from checked ones), and uses the existing `surface-invert-secondary` for unchecked hover, matching checked hover. Checked and disabled states are unchanged, and `surface-quaternary` keeps its value, so nothing else in the app changes. Fixes DEQ-406, DEQ-358, DEQ-391, DEQ-55 | State | Theme | Before | After | |---|---|---|---| | Off, rest | Dark | <img width="415" alt="before dark rest" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/before-dark-rest.png" /> | <img width="415" alt="after dark rest" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/after-dark-rest.png" /> | | Off, hover | Dark | <img width="415" alt="before dark hover" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/before-dark-hover.png" /> | <img width="415" alt="after dark hover" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/after-dark-hover.png" /> | | Off, rest | Light | <img width="415" alt="before light rest" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/before-light-rest.png" /> | <img width="415" alt="after light rest" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/after-light-rest.png" /> | | Off, hover | Light | <img width="415" alt="before light hover" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/before-light-hover.png" /> | <img width="415" alt="after light hover" src="https://raw.githubusercontent.com/coder/coder/assets/a11y-switch-off-contrast/pr2/after-light-hover.png" /> | Screenshots are from `/settings/notifications` in the running app. <details> <summary>Contrast measurements and decision log</summary> Computed colors measured in the browser on `/settings/notifications` and on the template builder (`step=module-settings`, `#mod-vscode-desktop-open_recent`), identical on both: | State | Theme | Track / thumb / behind | Track vs behind | Thumb vs track | |---|---|---|---|---| | Off, rest | Dark | `#71717A` / `#09090B` / `#18181B` | 3.67:1 (was 1.70) | 4.12:1 (was 1.91) | | Off, hover | Dark | `#A1A1AA` / `#09090B` / `#18181B` | 6.91:1 (was 1.18) | 7.76:1 (was 1.33) | | Off, rest | Light | `#8C8C97` / `#FFFFFF` / `#F4F4F5` | 3.03:1 (was 1.34) | 3.33:1 (was 1.48) | | Off, hover | Light | `#3F3F46` / `#FFFFFF` / `#F4F4F5` | 9.50:1 (was 1.15) | 10.44:1 (was 1.27) | In light theme the unchecked track (`#8C8C97`) is 4.48:1 against the checked track (`#27272A`); with zinc-500 it was only 3.08:1, which made on and off hard to scan. Alternatives considered: - Change `surface-quaternary` globally to zinc-600 (dark) / zinc-400 (light): still under 3:1 for the switch (about 2.3 to 2.6:1), and drops the Template Insights progress bar fill below 3:1 against its track. - Use `surface-tertiary` for the off track: lowers contrast further and matches the disabled state. - Use `surface-invert-secondary` for the off track at rest: passes, but makes rest and hover identical. - zinc-500 in light theme: passes (4.40:1) but sits close to the checked track. zinc-400 fails (2.33:1). No zinc step exists between them, so light theme uses `240 5% 57%` (suggested in review); `240 4% 54%` (3.33:1) was considered for extra margin. - The value differs per theme and is role-based, so it gets its own token rather than reusing a decorative surface token. Frontend self-review (FE1 to FE10): pass. Existing `Switch` stories (`DefaultOff`, `SmallOff`, disabled variants) cover the changed visual states; there is no behavior change. </details> --- _Generated by Coder Agents on behalf of @chrifro._ --------- Co-authored-by: Andrew Aquino <dawneraq@gmail.com>
This commit is contained in:
1 parent
899d25a5b1
commit
bef7ba8023
2 files changed
+5
-2
No files matched your search
@@ -13,8 +13,8 @@ const switchVariants = cva(
|
||||
focus-visible:ring-offset-2 focus-visible:ring-offset-surface-primary
|
||||
disabled:cursor-not-allowed
|
||||
data-[state=checked]:disabled:bg-surface-tertiary data-[state=unchecked]:disabled:bg-surface-tertiary
|
||||
data-[state=checked]:hover:bg-surface-invert-secondary data-[state=unchecked]:hover:bg-surface-tertiary
|
||||
data-[state=checked]:bg-surface-invert-primary data-[state=unchecked]:bg-surface-quaternary`,
|
||||
data-[state=checked]:hover:bg-surface-invert-secondary data-[state=unchecked]:hover:bg-surface-invert-secondary
|
||||
data-[state=checked]:bg-surface-invert-primary data-[state=unchecked]:bg-surface-control`,
|
||||
{
|
||||
variants: {
|
||||
size: {
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
--color-surface-secondary: hsl(var(--surface-secondary));
|
||||
--color-surface-tertiary: hsl(var(--surface-tertiary));
|
||||
--color-surface-quaternary: hsl(var(--surface-quaternary));
|
||||
--color-surface-control: hsl(var(--surface-control));
|
||||
--color-surface-invert-primary: hsl(var(--surface-invert-primary));
|
||||
--color-surface-invert-secondary: hsl(var(--surface-invert-secondary));
|
||||
--color-surface-destructive: hsl(var(--surface-destructive));
|
||||
@@ -445,6 +446,7 @@
|
||||
--surface-secondary: 240 5% 96%;
|
||||
--surface-tertiary: 240 6% 90%;
|
||||
--surface-quaternary: 240 5% 84%;
|
||||
--surface-control: 240 5% 57%;
|
||||
--surface-invert-primary: 240 4% 16%;
|
||||
--surface-invert-secondary: 240 5% 26%;
|
||||
--surface-destructive: 0 93% 94%;
|
||||
@@ -528,6 +530,7 @@
|
||||
--surface-secondary: 240 6% 10%;
|
||||
--surface-tertiary: 240 4% 16%;
|
||||
--surface-quaternary: 240 5% 26%;
|
||||
--surface-control: 240 4% 46%;
|
||||
--surface-invert-primary: 240 6% 90%;
|
||||
--surface-invert-secondary: 240 5% 65%;
|
||||
--surface-destructive: 0 75% 15%;
|
||||
|
||||
Reference in new issue
Block a user