Skip to content

Commit 7afde05

Browse files
authored
Indeterminate mixed option (#637)
@virginiacc I took a look at the spec for the indeterminate checkbox: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-checked When isIndeterminate is true, aria-checked should be "mixed" so it isn’t overwritten by the boolean checked value in controlled mode. I think this should take care of it.
1 parent 048eccc commit 7afde05

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/components/checkbox/checkbox.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,20 @@ describe('Checkbox', () => {
106106
const checkbox = screen.getByTestId(inputTestId);
107107
expect(checkbox.matches(':indeterminate')).toBe(true);
108108
});
109+
110+
it('sets aria-checked to mixed when isIndeterminate is true', () => {
111+
render(<Checkbox {...defaultProps} isIndeterminate />);
112+
113+
const checkbox = screen.getByTestId(inputTestId);
114+
expect(checkbox).toHaveAttribute(attributeAria, 'mixed');
115+
});
116+
117+
it('sets aria-checked to mixed in controlled mode when isIndeterminate is true', () => {
118+
render(
119+
<Checkbox {...defaultProps} checked={false} isIndeterminate />,
120+
);
121+
122+
const checkbox = screen.getByTestId(inputTestId);
123+
expect(checkbox).toHaveAttribute(attributeAria, 'mixed');
124+
});
109125
});

src/components/checkbox/checkbox.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export const Checkbox = ({
112112
});
113113
}
114114

115+
if (isIndeterminate) {
116+
Object.assign(inputProperties, { 'aria-checked': 'mixed' });
117+
}
118+
115119
useEffect(() => {
116120
if (typeof ref === 'object' && ref.current !== null) {
117121
ref.current.indeterminate = isIndeterminate

0 commit comments

Comments
 (0)