Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(checkbox): drop redundant aria-checked=mixed on native indeterminate checkbox (forms-16) (#3408)

Cindy Zhang6b21da385a7f
diff --git a/.changeset/checkbox-indeterminate-aria.md b/.changeset/checkbox-indeterminate-aria.md
new file mode 100644
index 0000000000..b82ce8db9e
--- /dev/null
+++ b/.changeset/checkbox-indeterminate-aria.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] CheckboxInput: stop setting a redundant `aria-checked="mixed"` on the native `<input type="checkbox">` for the indeterminate state. The native `indeterminate` DOM property (which browsers already map to `aria-checked="mixed"`) is authoritative; the extra attribute could desync from or override the native state (#3343).
+@cixzhang
diff --git a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx b/packages/core/src/CheckboxInput/CheckboxInput.test.tsx
index a3f592cc6c..32d89f4e2d 100644
--- a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx
+++ b/packages/core/src/CheckboxInput/CheckboxInput.test.tsx
@@ -17,33 +17,21 @@ import {CheckboxInput} from './CheckboxInput';
describe('CheckboxInput', () => {
it('renders with label', () => {
render(
- <CheckboxInput
- label="Accept terms"
- value={false}
- onChange={() => {}}
- />,
+ <CheckboxInput label="Accept terms" value={false} onChange={() => {}} />,
);
expect(screen.getByLabelText('Accept terms')).toBeInTheDocument();
});
it('renders as unchecked by default', () => {
render(
- <CheckboxInput
- label="Accept terms"
- value={false}
- onChange={() => {}}
- />,
+ <CheckboxInput label="Accept terms" value={false} onChange={() => {}} />,
);
expect(screen.getByRole('checkbox')).not.toBeChecked();
});
it('renders as checked when value prop is true', () => {
render(
- <CheckboxInput
- label="Accept terms"
- value={true}
- onChange={() => {}}
- />,
+ <CheckboxInput label="Accept terms" value={true} onChange={() => {}} />,
);
expect(screen.getByRole('checkbox')).toBeChecked();
});
@@ -182,11 +170,7 @@ describe('CheckboxInput', () => {
it('shows label visually by default', () => {
render(
- <CheckboxInput
- label="Accept terms"
- value={false}
- onChange={() => {}}
- />,
+ <CheckboxInput label="Accept terms" value={false} onChange={() => {}} />,
);
const label = screen.getByText('Accept terms');
expect(label).toBeVisible();
@@ -204,7 +188,7 @@ describe('CheckboxInput', () => {
expect(screen.getByRole('checkbox')).toHaveAttribute('aria-busy', 'true');
});
- it('sets aria-checked="mixed" for indeterminate state', () => {
+ it('exposes indeterminate state via the native indeterminate property', () => {
render(
<CheckboxInput
label="Select all"
@@ -212,10 +196,15 @@ describe('CheckboxInput', () => {
onChange={() => {}}
/>,
);
- expect(screen.getByRole('checkbox')).toHaveAttribute(
- 'aria-checked',
- 'mixed',
- );
+ const checkbox = screen.getByRole('checkbox');
+ // Native checkboxes expose mixed state through the DOM indeterminate
+ // property, which browsers map to aria-checked="mixed". A redundant
+ // aria-checked attribute is intentionally NOT set (forms-16).
+ expect(checkbox).toBeInstanceOf(HTMLInputElement);
+ if (checkbox instanceof HTMLInputElement) {
+ expect(checkbox.indeterminate).toBe(true);
+ }
+ expect(checkbox).not.toHaveAttribute('aria-checked');
});
it('renders semantic labelIcon names as icons', () => {
diff --git a/packages/core/src/CheckboxInput/CheckboxInput.tsx b/packages/core/src/CheckboxInput/CheckboxInput.tsx
index f6d143c2fa..197114471c 100644
--- a/packages/core/src/CheckboxInput/CheckboxInput.tsx
+++ b/packages/core/src/CheckboxInput/CheckboxInput.tsx
@@ -376,7 +376,10 @@ export function CheckboxInput({
const isChecked = optimisticValue === true;
const isCheckedOrIndeterminate = isChecked || isIndeterminate;
- // Sync the native indeterminate DOM property (can't be set via JSX attribute)
+ // Sync the native indeterminate DOM property (can't be set via JSX
+ // attribute). On a native checkbox this is the authoritative way to expose
+ // the mixed state — a separate aria-checked="mixed" would be redundant and
+ // can desync from / override the native state (forms-16), so it is omitted.
const indeterminateRef = useCallback(
(el: HTMLInputElement | null) => {
if (el) {
@@ -436,7 +439,6 @@ export function CheckboxInput({
}}
onFocus={onFocus}
onBlur={onBlur}
- aria-checked={isIndeterminate ? 'mixed' : undefined}
aria-readonly={isReadOnly || undefined}
aria-describedby={ariaDescribedBy}
aria-invalid={status?.type === 'error' ? true : undefined}
diff --git a/packages/core/src/CheckboxList/CheckboxList.test.tsx b/packages/core/src/CheckboxList/CheckboxList.test.tsx
index 36535a1671..9267eebbc1 100644
--- a/packages/core/src/CheckboxList/CheckboxList.test.tsx
+++ b/packages/core/src/CheckboxList/CheckboxList.test.tsx
@@ -39,10 +39,7 @@ describe('CheckboxList', () => {
it('checks the correct items based on value prop', () => {
render(
- <CheckboxList
- label="Preferences"
- value={['a', 'c']}
- onChange={() => {}}>
+ <CheckboxList label="Preferences" value={['a', 'c']} onChange={() => {}}>
<CheckboxListItem label="Option A" value="a" />
<CheckboxListItem label="Option B" value="b" />
<CheckboxListItem label="Option C" value="c" />
@@ -58,10 +55,7 @@ describe('CheckboxList', () => {
const user = userEvent.setup();
const handleChange = vi.fn();
render(
- <CheckboxList
- label="Preferences"
- value={['a']}
- onChange={handleChange}>
+ <CheckboxList label="Preferences" value={['a']} onChange={handleChange}>
<CheckboxListItem label="Option A" value="a" />
<CheckboxListItem label="Option B" value="b" />
</CheckboxList>,
@@ -272,11 +266,7 @@ describe('CheckboxList', () => {
isChecked={false}
onCheck={handleSelectAll}
/>
- <CheckboxListItem
- label="Name"
- isChecked={true}
- onCheck={handleCheck}
- />
+ <CheckboxListItem label="Name" isChecked={true} onCheck={handleCheck} />
<CheckboxListItem
label="Email"
isChecked={false}
@@ -347,8 +337,15 @@ describe('CheckboxListItem standalone mode', () => {
<CheckboxListItem label="Partial" isChecked="indeterminate" />
</List>,
);
+ // The inner native checkbox exposes mixed state via the indeterminate DOM
+ // property (not a redundant aria-checked, forms-16); the list row still
+ // carries aria-checked="mixed" for its own listitem semantics.
const checkbox = screen.getByRole('checkbox');
- expect(checkbox).toHaveAttribute('aria-checked', 'mixed');
+ expect(checkbox).toBeInstanceOf(HTMLInputElement);
+ if (checkbox instanceof HTMLInputElement) {
+ expect(checkbox.indeterminate).toBe(true);
+ }
+ expect(checkbox).not.toHaveAttribute('aria-checked');
});
it('calls onCheck with true when clicking indeterminate item', async () => {