Skip to content

Commit 7c642fa

Browse files
authored
Increase contrast for disabled toggles and label radio button groups (#560)
* Use a darker color for disabled text to improve contrast ratios * Add darker neutral color to use for disabled text in settings This balances the need for toggles in a disabled state to have a visually different text formatting while still meeting the WCAG AA requirement for 4.5:1. * Group associated radio buttons and assign the existing label as a label for each group Since the radio button groupings aren't using standard HTML radio button groups (<fieldset> with <legend>), this uses the ARIA method of role="radiogroup" and aria-labelledby={id} to associate each radio grouping with the label. Visually there's no change. * Formatted with prettier --write
1 parent b0f3869 commit 7c642fa

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/pages/settings/RadioGroup.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { createContext, type ReactNode, useContext, useMemo } from "react";
1+
import {
2+
createContext,
3+
type ReactNode,
4+
useContext,
5+
useMemo,
6+
useId,
7+
} from "react";
28
import "./RadioGroup.css";
39

410
type TypeRadioContext = {
@@ -64,11 +70,16 @@ export function RadioGroup<T extends string>({
6470
() => ({ name, selectedValue: defaultValue, isDisabled, onChange }),
6571
[name, defaultValue, isDisabled, onChange]
6672
);
73+
const id = useId();
6774

6875
return (
6976
<RadioContext.Provider value={contextValue}>
70-
<div className={`RadioGroup ${isDisabled ? "disabled" : ""}`}>
71-
{label}
77+
<div
78+
className={`RadioGroup ${isDisabled ? "disabled" : ""}`}
79+
role="radiogroup"
80+
aria-labelledby={id}
81+
>
82+
<label id={id}>{label}</label>
7283
<div className="options">{children}</div>
7384
</div>
7485
</RadioContext.Provider>

src/pages/settings/Toggle.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
}
55

66
.Toggle.disabled label {
7-
color: var(--neutral-500);
7+
color: var(--neutral-600);
88
}
99

1010
.Toggle button {

src/pages/settings/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
--orange-700: #c2410c;
2323
--blue-600: #2563eb;
2424
--neutral-500: #a3a3a3;
25+
--neutral-600: #757575;
2526
}
2627

2728
html {

0 commit comments

Comments
 (0)