Skip to content

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

TypeScript

fix(CheckboxList): an error status makes every checkbox aria-invalid (#9634)

Cindy Zhangc76b17b56c5f
diff --git a/.changeset/checkboxlist-aria-invalid.md b/.changeset/checkboxlist-aria-invalid.md
new file mode 100644
index 0000000000..cd1eedb103
--- /dev/null
+++ b/.changeset/checkboxlist-aria-invalid.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A `CheckboxList` with an error `status` now makes every checkbox `aria-invalid`, so a screen reader announces the list as invalid as each checkbox takes focus, as `Switch` and the text inputs already do. The message still renders once, from the list.
+
+@cixzhang @duytbp
diff --git a/docs/specs/components/CheckboxList/CheckboxList.spec.md b/docs/specs/components/CheckboxList/CheckboxList.spec.md
index c13d9a7041..5ab59ba60c 100644
--- a/docs/specs/components/CheckboxList/CheckboxList.spec.md
+++ b/docs/specs/components/CheckboxList/CheckboxList.spec.md
@@ -56,8 +56,8 @@ system_specs: [spec:AST-011, spec:AST-021, spec:AST-038, spec:AST-085]
| Public contract | `CheckboxList` is a labeled `role="group"` of `CheckboxListItem` rows. A `value` array selects controlled collection mode (`onChange`, `changeAction`); without it, its items are standalone. The group owns naming, description, disabled, disabled-reason, read-only, pending values, and status. Each option's behavior is `component:CheckboxListItem`. |
| Behavior | The group names and describes its options, tracks every value whose `changeAction` is pending so each saving option stays busy while the others stay interactive, and applies disabled, read-only, and status to every option. |
| End-user impact | People can identify the group, operate every option by pointer, touch, and keyboard, learn why a group is unavailable, and see which options are still saving. |
-| Builder impact | Builders choose collection mode by passing `value`, and then supply stable item `value`s. Invalid-status meaning stays an open question here (OQ3); per-option open questions are in `component:CheckboxListItem`. |
-| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. An error status exposes no invalid state; listed under Current-state impact. |
+| Builder impact | Builders choose collection mode by passing `value`, and then supply stable item `value`s. The rendering of a status without a message stays an open question here (OQ3); per-option open questions are in `component:CheckboxListItem`. |
+| Compatibility/readiness | Records shipped behavior. Each checkbox gains `aria-invalid` under an error status; no API or default change. |
| Review checks | Reject a pending value that loses its busy state or re-toggle guard when another option is toggled, dropped group naming or description ids, a toggle while the group is disabled or read-only, or new target or state API introduced without an owner decision. Per-option checks are in `component:CheckboxListItem`. |
| Governing rules | `architecture:public-component-api/INV1–INV9`; `architecture:component-theming-surface/INV3–INV6`; `architecture:interaction-modality/INV1–INV5`; `architecture:component-test-sufficiency/INV1–INV7`; `architecture:knowledge-contracts/INV2`; `spec:AST-021/FR8–FR10`; `spec:AST-038/FR7`; `spec:AST-085/FR1, FR7`; `family:input-fields/FR10`; WCAG 2.2 1.3.1, 2.1.1, 4.1.2. |
@@ -72,8 +72,8 @@ touch, keyboard, and assistive technology.
## Compatibility and migration
- Released default preserved: `yes`
-- Compatibility class: records shipped behavior; no public prop, default,
- export, or DOM change
+- Compatibility class: records shipped behavior; no public prop, default, or
+ export change; each checkbox gains `aria-invalid` under an error status
- Controlled/uncontrolled behavior: collection mode is controlled by `value`;
standalone items follow `component:CheckboxListItem`; no uncontrolled mode
exists
@@ -111,17 +111,17 @@ Consumer migration instructions belong in consumer docs and release notes.
## Public concepts
-| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |
-| ---------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ------------------------- | ---------------------- | -------------------------------------- | ------------------------------------------------------------ |
-| group naming | `label`, `isLabelHidden`, `description` | Names and describes the `role="group"`; a hidden label still names it. | All states. | label required; visible | caller and Field | stable | rejected by the public type |
-| collection value | `value` array present or absent | Present: the group owns checked membership and change handling for its items. Absent: its items are standalone. | All states. | absent | caller and component | stable | an item without `value` in collection mode throws (item FR4) |
-| change path | `onChange`, `changeAction`, both, neither | Reports the next value array; `changeAction` runs after `onChange` in a transition with an optimistic value. | Collection mode. | neither | caller and component | shipped; handlerless meaning unsettled | no handler means no component-owned mutation |
-| availability | enabled, `isDisabled`, `isDisabled` with `disabledMessage` | Blocks toggling on every item, which stays focusable through `aria-disabled`; a reason adds a group tooltip. | Reason applies only with `isDisabled`. | enabled | component | stable | a reason without `isDisabled` renders nothing |
-| read-only | `isReadOnly` | Makes every item read-only. | Group-wide. | false | component | stable | boolean only |
-| pending values | the values whose `changeAction` is pending | Each pending value's item renders busy; toggling another item does not clear it; concurrent values settle together. | Collection mode with `changeAction`. | none | component | stable | transition state only |
-| status | `warning`, `error`, `success`, optional message | A message renders a detached FieldStatus after the list and describes the group. | All states. | none | caller and FieldStatus | shipped; invalid semantics unsettled | a status without a message renders nothing |
-| row layout | `density` compact/balanced/spacious; `hasDividers`; `width` | Density reaches the List and its rows; dividers separate rows; width sizes the label, list, and status together. | All states. | balanced; none; intrinsic | component and List | stable | rejected by the public types |
-| pass-through | CheckboxList rest, `ref`, `container*`, `control*` | Base props and `ref` reach the `role="group"`; `container*` the Field box; `control*` the group element. | All states. | none | component | stable | root `xstyle`, `className`, `style` are not accepted |
+| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |
+| ---------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ------------------------- | ---------------------- | -------------------------------------- | ------------------------------------------------------------ |
+| group naming | `label`, `isLabelHidden`, `description` | Names and describes the `role="group"`; a hidden label still names it. | All states. | label required; visible | caller and Field | stable | rejected by the public type |
+| collection value | `value` array present or absent | Present: the group owns checked membership and change handling for its items. Absent: its items are standalone. | All states. | absent | caller and component | stable | an item without `value` in collection mode throws (item FR4) |
+| change path | `onChange`, `changeAction`, both, neither | Reports the next value array; `changeAction` runs after `onChange` in a transition with an optimistic value. | Collection mode. | neither | caller and component | shipped; handlerless meaning unsettled | no handler means no component-owned mutation |
+| availability | enabled, `isDisabled`, `isDisabled` with `disabledMessage` | Blocks toggling on every item, which stays focusable through `aria-disabled`; a reason adds a group tooltip. | Reason applies only with `isDisabled`. | enabled | component | stable | a reason without `isDisabled` renders nothing |
+| read-only | `isReadOnly` | Makes every item read-only. | Group-wide. | false | component | stable | boolean only |
+| pending values | the values whose `changeAction` is pending | Each pending value's item renders busy; toggling another item does not clear it; concurrent values settle together. | Collection mode with `changeAction`. | none | component | stable | transition state only |
+| status | `warning`, `error`, `success`, optional message | A message renders a detached FieldStatus after the list and describes the group; an error makes each checkbox `aria-invalid`. | All states. | none | caller and FieldStatus | shipped | a status without a message renders nothing |
+| row layout | `density` compact/balanced/spacious; `hasDividers`; `width` | Density reaches the List and its rows; dividers separate rows; width sizes the label, list, and status together. | All states. | balanced; none; intrinsic | component and List | stable | rejected by the public types |
+| pass-through | CheckboxList rest, `ref`, `container*`, `control*` | Base props and `ref` reach the `role="group"`; `container*` the Field box; `control*` the group element. | All states. | none | component | stable | root `xstyle`, `className`, `style` are not accepted |
Item props (`label`, `aria-label`, `description`, `endContent`, `isChecked`,
`onCheck`, item `isDisabled`, `isLoading`, and item pass-through) are concepts
@@ -139,7 +139,7 @@ of `component:CheckboxListItem`.
| FR9 | Group `isDisabled` MUST make every checkbox focusable-disabled through `aria-disabled` (`component:CheckboxInput` FR4) and refuse toggling. With `disabledMessage`, the reason tooltip opens on group hover and keyboard focus, and the reason MUST describe each focusable checkbox (`spec:AST-085` FR5, FR7). Implementation gap: the reason describes only the `role="group"`, so a focused checkbox is not described by it. | `spec:AST-085` FR1, FR7; shipped source, focused tests, and shared checkbox binding |
| FR10 | Group `isReadOnly` MUST make every item in the group read-only (`component:CheckboxListItem` FR8 and FR10). | shipped source; shared checkbox binding; `spec:AST-011` read-only vocabulary |
| FR13 | `density` MUST reach the List and its rows (the checkbox size follows `component:CheckboxListItem` FR11); `hasDividers` MUST separate rows without a divider after the last row; `width` MUST size the label, list, and status together. | shipped source, docs, and the Chromium accessibility suite |
-| FR14 | An error `status` with a message renders it (FR4). Implementation gap: an error exposes no programmatic invalid state on the group or its checkboxes, and a status without a message renders nothing; their meaning is OQ3. | shipped source; `spec:AST-002/FR15` |
+| FR14 | An error `status` with a message renders it (FR4), and an error `status` makes every checkbox `aria-invalid="true"`, so a screen reader announces the invalid state as each checkbox takes focus. Implementation gap: a status without a message renders nothing; its meaning is OQ3. | shipped source; `spec:AST-002/FR15` |
| FR15 | Base props, including ARIA and `ref`, MUST reach the `role="group"`; a caller `aria-labelledby` joins the group label and a caller `aria-describedby` comes first. `container*` MUST reach the Field box where one renders (in a `horizontal-labels` FormLayout none renders, and `container*` has no effect and warns), and `control*` the group element; root `xstyle`, `className`, and `style` are not accepted. | `family:input-fields` FR10; `CheckboxList.fr10.test.tsx` |
Per-option requirements are owned by `component:CheckboxListItem`
@@ -292,7 +292,7 @@ row surface, but not a checked-row state (`component:CheckboxListItem` FR15).
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| FR1, AR1 | `CheckboxList.test.tsx` group-role, group-description, and disabledMessage cases | Named group; description plus status; disabled reason | A missing group name, or a description and status out of order, fails. Evidence gap: no test asserts the caller description first or the disabled reason last. | `audit:CheckboxList/accessibility` |
| FR2, FR15 | `CheckboxList.test.tsx` ref and container case; `CheckboxList.fr10.test.tsx` | Standalone; `horizontal-labels` FormLayout | A ref off the group, `container*` off the Field box, or a base prop off the group fails. | `audit:CheckboxList/api` |
-| FR4, FR14 | `CheckboxList.test.tsx` error-status case | Error with message | A missing status message fails. Evidence gap: no test asserts the absent invalid state or the empty render without a message. | `audit:CheckboxList/accessibility` |
+| FR4, FR14 | `CheckboxList.test.tsx` error-status cases, including every checkbox's `aria-invalid`; `CheckboxListErrorStatus.a11y.chromium.spec.ts` | Error with message | A missing status message fails. Evidence gap: no test asserts the empty render without a message. | `audit:CheckboxList/accessibility` |
| FR6, FR7 | `CheckboxList.test.tsx` add, remove, and pending cases; `CheckboxList.a11y.chromium.spec.ts` `pending-single`, `pending-concurrent`, and `pending-settled` cases | Add; remove; one and two pending values; settled | A wrong array, a cleared earlier pending value, or a busy state that outlives settlement fails. | `audit:CheckboxList/behavior` |
| FR9, FR10, AR4 | `CheckboxList.test.tsx` group-disabled, disabledMessage, and read-only cases; shared checkbox bindings | Group disabled; with reason; read-only item | A lost tab stop, a toggle while disabled, or a read-only toggle fails. Evidence gap: no test asserts that a focused checkbox is not described by the reason. | `audit:CheckboxList/accessibility` |
| FR13 | `CheckboxList.test.tsx` density cases; `CheckboxList.a11y.chromium.spec.ts` density, divider, 320-pixel, and RTL cases | Compact, balanced, spacious; dividers; narrow; RTL | A density, divider, overflow, or direction sensor fails. Evidence gap: no test asserts `width` sizing the label, list, and status together. | `audit:CheckboxList/layout` |
@@ -310,9 +310,8 @@ CheckboxInput, Spinner, and FieldStatus targets.
- **Group reason (FR9).** A group `disabledMessage` describes only the
`role="group"`, so a focused disabled checkbox is not described by it,
against `spec:AST-085` FR5 and FR7.
-- **Error status (FR14).** An error `status` sets no invalid state on the group
- or its checkboxes, and a status without a message renders nothing; the
- meaning is OQ3.
+- **Status without a message (FR14).** A status without a message renders
+ nothing; its meaning is OQ3.
## Decision log
@@ -321,8 +320,7 @@ No component-local decision. CheckboxList applies `spec:AST-021`,
## Open questions
-- **OQ3 — Should an error status expose invalid state, and what should a status
- without a message render?** (`human-api`)
+- **OQ3 — What should a status without a message render?** (`human-api`)
Per-option questions live in `component:CheckboxListItem`.
## Content boundary
diff --git a/packages/core/src/CheckboxList/CheckboxList.doc.mjs b/packages/core/src/CheckboxList/CheckboxList.doc.mjs
index eb81ebfccc..ca3f2075ee 100644
--- a/packages/core/src/CheckboxList/CheckboxList.doc.mjs
+++ b/packages/core/src/CheckboxList/CheckboxList.doc.mjs
@@ -178,12 +178,14 @@ export const docs = {
{
name: 'containerClassName',
type: 'string',
- description: 'Class name for the field container. Same targeting as `containerXstyle`.',
+ description:
+ 'Class name for the field container. Same targeting as `containerXstyle`.',
},
{
name: 'containerStyle',
type: 'CSSProperties',
- description: 'Inline styles for the field container. Same targeting as `containerXstyle`.',
+ description:
+ 'Inline styles for the field container. Same targeting as `containerXstyle`.',
},
{
name: 'controlXstyle',
diff --git a/packages/core/src/CheckboxList/CheckboxList.test.tsx b/packages/core/src/CheckboxList/CheckboxList.test.tsx
index 9d1ff645c3..fc84866369 100644
--- a/packages/core/src/CheckboxList/CheckboxList.test.tsx
+++ b/packages/core/src/CheckboxList/CheckboxList.test.tsx
@@ -1247,3 +1247,38 @@ describe('CheckboxListItem ARIA props', () => {
});
});
});
+
+describe('CheckboxList error status', () => {
+ it('makes every checkbox aria-invalid', () => {
+ render(
+ <CheckboxList
+ label="Toppings"
+ status={{type: 'error', message: 'Choose at least one topping'}}>
+ <CheckboxListItem value="cheese" label="Cheese" />
+ <CheckboxListItem value="olives" label="Olives" />
+ </CheckboxList>,
+ );
+ for (const checkbox of screen.getAllByRole('checkbox')) {
+ expect(checkbox).toHaveAttribute('aria-invalid', 'true');
+ }
+ // The message still renders once, from the list.
+ expect(screen.getAllByText('Choose at least one topping')).toHaveLength(1);
+ });
+
+ it('leaves checkboxes valid for a warning or no status', () => {
+ const {rerender} = render(
+ <CheckboxList
+ label="Toppings"
+ status={{type: 'warning', message: 'Few left'}}>
+ <CheckboxListItem value="cheese" label="Cheese" />
+ </CheckboxList>,
+ );
+ expect(screen.getByRole('checkbox')).not.toHaveAttribute('aria-invalid');
+ rerender(
+ <CheckboxList label="Toppings">
+ <CheckboxListItem value="cheese" label="Cheese" />
+ </CheckboxList>,
+ );
+ expect(screen.getByRole('checkbox')).not.toHaveAttribute('aria-invalid');
+ });
+});
diff --git a/packages/core/src/CheckboxList/CheckboxList.tsx b/packages/core/src/CheckboxList/CheckboxList.tsx
index ed0b678deb..2d9c47d55c 100644
--- a/packages/core/src/CheckboxList/CheckboxList.tsx
+++ b/packages/core/src/CheckboxList/CheckboxList.tsx
@@ -246,6 +246,7 @@ export function CheckboxList({
? disabledMessageTooltip.describedBy
: undefined,
isReadOnly,
+ isInvalid: status?.type === 'error',
loadingValues,
}),
[
@@ -256,6 +257,7 @@ export function CheckboxList({
showsDisabledMessage,
disabledMessageTooltip.describedBy,
isReadOnly,
+ status?.type,
loadingValues,
],
);
diff --git a/packages/core/src/CheckboxList/CheckboxListContext.tsx b/packages/core/src/CheckboxList/CheckboxListContext.tsx
index 349c4bf2f8..9609bd94ce 100644
--- a/packages/core/src/CheckboxList/CheckboxListContext.tsx
+++ b/packages/core/src/CheckboxList/CheckboxListContext.tsx
@@ -37,6 +37,12 @@ export interface CheckboxListContextValue {
*/
disabledMessageID?: string;
isReadOnly: boolean;
+ /**
+ * True when the list has an error `status`. Each checkbox is then
+ * `aria-invalid`. Some screen readers skip a group's invalid state when a
+ * checkbox takes focus.
+ */
+ isInvalid?: boolean;
/**
* Values of the items whose `changeAction` is pending. Each matching item
* renders an in-checkbox spinner and blocks re-toggling; the list is empty
diff --git a/packages/core/src/CheckboxList/CheckboxListItem.tsx b/packages/core/src/CheckboxList/CheckboxListItem.tsx
index aacc3aa90a..caf171e1a0 100644
--- a/packages/core/src/CheckboxList/CheckboxListItem.tsx
+++ b/packages/core/src/CheckboxList/CheckboxListItem.tsx
@@ -24,6 +24,7 @@ import {colorVars} from '../theme/tokens.stylex';
import type {BaseProps} from '../BaseProps';
import {CheckboxInput} from '../CheckboxInput/CheckboxInput';
import type {CheckboxInputProps} from '../CheckboxInput/CheckboxInput';
+import type {InputStatus} from '../Field/types';
import {ListItem} from '../List/ListItem';
import {ListContext} from '../List/ListContext';
import {CheckboxListContext} from './CheckboxListContext';
@@ -149,6 +150,8 @@ export interface CheckboxListItemProps extends BaseProps<HTMLLIElement> {
// Component
// =============================================================================
+const ERROR_STATUS: InputStatus = {type: 'error'};
+
/**
* The row's visible description is the checkbox's accessible description. Item
* renders that element and owns its id, and publishes the id through
@@ -167,11 +170,17 @@ function DescribedCheckboxInput(
props: Omit<CheckboxInputProps, 'aria-describedby'>,
) {
const describedBy = use(ItemDescriptionContext);
- const reasonID = use(CheckboxListContext)?.disabledMessageID;
+ const listContext = use(CheckboxListContext);
return (
<CheckboxInput
{...props}
- aria-describedby={joinAriaIDs(describedBy ?? undefined, reasonID)}
+ aria-describedby={joinAriaIDs(
+ describedBy ?? undefined,
+ listContext?.disabledMessageID,
+ )}
+ // The status has no message, so CheckboxInput renders nothing. The list
+ // renders the message.
+ status={listContext?.isInvalid ? ERROR_STATUS : undefined}
/>
);
}
diff --git a/packages/core/src/CheckboxList/__tests__/CheckboxListErrorStatus.a11y.chromium.spec.ts b/packages/core/src/CheckboxList/__tests__/CheckboxListErrorStatus.a11y.chromium.spec.ts
new file mode 100644
index 0000000000..34c85f4bf6
--- /dev/null
+++ b/packages/core/src/CheckboxList/__tests__/CheckboxListErrorStatus.a11y.chromium.spec.ts
@@ -0,0 +1,56 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+// @pr-a11y scope core/CheckboxList
+
+/**
+ * @file CheckboxListErrorStatus.a11y.chromium.spec.ts
+ * @input The built Core/CheckboxList WithErrorStatus story; Chromium's
+ * accessibility tree through the DevTools protocol
+ * @output Browser evidence that every checkbox in a list with an error status
+ * is exposed as invalid
+ * @position Chromium proof for CheckboxList's per-checkbox invalid state
+ */
+
+import {expect, test} from '@playwright/test';
+import {holdMotionStill} from '@astryxdesign/a11y-spec/chromium';
+import {
+ DEFAULT_STORYBOOK_DIR,
+ serveStorybook,
+ type StaticServer,
+} from '@astryxdesign/a11y-spec/storybook';
+
+let storybook: StaticServer;
+test.beforeAll(async () => {
+ storybook = await serveStorybook(
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
+ );
+});
+test.afterAll(async () => {
+ await storybook?.close();
+});
+
+interface AXNode {
+ role?: {value?: string};
+ properties?: {name: string; value: {value?: unknown}}[];
+}
+
+test('every checkbox of a list with an error status is invalid', async ({
+ page,
+}) => {
+ await page.goto(
+ `${storybook.origin}/iframe.html?id=core-checkboxlist--with-error-status&viewMode=story`,
+ );
+ await holdMotionStill(page);
+ await expect(page.getByRole('checkbox').first()).toBeVisible();
+ const cdp = await page.context().newCDPSession(page);
+ const {nodes} = (await cdp.send('Accessibility.getFullAXTree')) as {
+ nodes: AXNode[];
+ };
+ const checkboxes = nodes.filter(node => node.role?.value === 'checkbox');
+ expect(checkboxes.length).toBeGreaterThan(0);
+ for (const checkbox of checkboxes) {
+ const invalid = checkbox.properties?.find(
+ property => property.name === 'invalid',
+ )?.value.value;
+ expect(invalid).toBe('true');
+ }
+});