Skip to content

Commit de0bbc2

Browse files
authored
fix(CheckboxListItem): a checked row reflects selected on its row targets (#10146)
* test(CheckboxListItem): a checked row reflects its selected state on its row targets (red) * fix(CheckboxListItem): a checked row reflects selected on its row targets (FR15) A checked, enabled, editable row already paints the checked-row fill; it now also carries data-selected="selected" on the row element that holds its item and list-item targets, so a theme can restyle checked rows and the text on that fill. The record's FR15 gap closes. * docs(CheckboxListItem): close OQ2; FR15's reflected selected state answers it * docs(CheckboxList, CheckboxListItem): the summaries and the list record follow FR15's reflected selected state
1 parent 40ab0ec commit de0bbc2

5 files changed

Lines changed: 64 additions & 14 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] A checked, enabled, editable `CheckboxListItem` row now reflects `data-selected="selected"` on its row, the element that carries its `item` and `list-item` targets, so a theme's `selected` rules for those targets restyle checked rows and the text on their fill.
6+
7+
@cixzhang

‎docs/specs/components/CheckboxList/CheckboxList.spec.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ untargeted spans, so neither delegates to Text nor inherits the row-root
270270
`list-item` target; future exposure remains unsettled. Rich label content and end
271271
content are caller-provided, and end content intentionally stays outside
272272
CheckboxList's public theming ownership. The `Option row` delegation reaches the
273-
row surface, but not a checked-row state (`component:CheckboxListItem` FR15).
273+
row surface and, on a checked, enabled, editable row, its `selected` state
274+
(`component:CheckboxListItem` FR15).
274275

275276
## Family and system relationships
276277

‎docs/specs/components/CheckboxList/CheckboxListItem.spec.md‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ system_specs: [spec:AST-011, spec:AST-021, spec:AST-038, spec:AST-085]
5656
| Public contract | One option row: a native checkbox named by `label` or `aria-label`, described by `description`, with optional `endContent`, rendered through ListItem. Inside a CheckboxList with a `value` array (collection mode), checked state comes from membership and `value` is required. Inside List, or inside a CheckboxList without `value` (standalone mode), the item reads `isChecked` and calls `onCheck`. |
5757
| Behavior | The checkbox is the option's only tab stop. Row-surface clicks delegate to it when the item is editable and sits in a CheckboxList or has `onCheck`, or when it has `onClick`; an item `onClick` fires once per direct, keyboard, or row-surface click. Disabled, read-only, and busy states refuse toggling. |
5858
| End-user impact | People can operate each option by pointer, touch, and keyboard, hear its name, description, and checked, mixed, disabled, read-only, or busy state, and see a spinner while it saves. |
59-
| Builder impact | Where the item sits, and whether its parent list has `value`, selects the mode; `value` is required only in collection mode. Handlerless meaning, checked-row theming and pointer feedback, consumer DOM-prop targets, read-only click propagation, and focus-ring ownership stay open questions (OQ1–OQ6). |
60-
| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. Handlerless items, checked-row state reflection, and the double focus indicator are listed under Current-state impact. |
59+
| Builder impact | Where the item sits, and whether its parent list has `value`, selects the mode; `value` is required only in collection mode. Handlerless meaning, checked-row pointer feedback, consumer DOM-prop targets, read-only click propagation, and focus-ring ownership stay open questions (OQ1, OQ3–OQ6). |
60+
| Compatibility/readiness | A checked, enabled, editable row reflects `selected` (FR15); no API or default change. Handlerless items and the double focus indicator are listed under Current-state impact. |
6161
| Review checks | Reject a second tab stop, a toggle while disabled, read-only, or busy, `isChecked` overriding a parent `value` array, an `onClick` that fires more than once per click, a dropped description relationship, or a new target, state, or event-routing API introduced without an owner decision. |
6262
| Governing rules | `architecture:public-component-api/INV5–INV9`; `architecture:component-theming-surface/INV3–INV6`; `architecture:interaction-modality/INV1–INV5`; `architecture:component-test-sufficiency/INV1–INV7`; `spec:AST-021/FR8–FR10`; `spec:AST-085/FR1, FR7`; `spec:AST-011`; `spec:AST-038/FR7`; WCAG 2.2 1.3.1, 2.1.1, 4.1.2. |
6363

@@ -143,7 +143,7 @@ Consumer migration instructions belong in consumer docs and release notes.
143143
| FR12 | An enabled, editable, checked row MUST paint the `--color-accent-muted` fill, and consumer `xstyle` MUST compose after it. | shipped source and the Chromium accessibility suite |
144144
| FR13 | `ref`, `className`, `style`, `xstyle`, data attributes, ARIA other than `aria-label`, and events other than `onClick` MUST reach the row `<li>`. | shipped source and focused tests |
145145
| FR14 | A standalone item with `isChecked` and no `onCheck` changes nothing on activation. Implementation gap: it declares no read-only state, so the checkbox is exposed as editable (WCAG 2.2 4.1.2); inside a CheckboxList without `value`, its row also delegates clicks and shows pointer feedback. Its meaning is OQ1. | exact `spec:AST-021` known failure `list-item-handlerless-read-only`; WCAG 4.1.2 |
146-
| FR15 | The item paints the checked-row fill itself and reflects no selection state on the row's `list-item` or `item` targets, so a theme cannot restyle checked rows apart from unchecked rows (OQ2). Selection state MUST be reflected on the owning target (`architecture:component-theming-surface` INV6). Implementation gap: no selection state is reflected. | `architecture:component-theming-surface/INV6` |
146+
| FR15 | A checked, enabled, editable row paints the checked-row fill and reflects a `selected` state on the row's `item` and `list-item` targets, so a theme can restyle checked rows and the text on that fill (`architecture:component-theming-surface` INV6). A read-only or disabled row paints no fill and reflects no state; its targets match unchecked rows. | `architecture:component-theming-surface/INV6` |
147147
| FR16 | Shipped behavior, not a requirement until its open question is ruled: consumer DOM inputs split between two elements: data attributes and ARIA reach the row, while `onClick` runs on the checkbox and is typed for the row, so `event.currentTarget` is the checkbox and does not carry the row's data attributes (OQ3). | `architecture:public-component-api/INV5`; `INV9` for any retype or move |
148148
| FR17 | Shipped behavior, not a requirement until its open question is ruled: on a read-only item with `onClick`, the item stops the click's propagation, so React ancestors never receive those clicks, while they do for enabled items (OQ4). The item's own `onClick` still fires once per click (FR10). | Current source; shared clickable-container hook behavior |
149149
| FR18 | Shipped behavior, not a requirement until its open question is ruled: on an enabled, editable, checked row, the checked-row fill replaces the row's hover and pressed overlays, so pointer hover and hold give no row feedback (OQ5). | the Chromium accessibility suite; `design:user-states` leaves hover and selection treatment outside its current claim |
@@ -215,7 +215,7 @@ durable constraints and their verification target.
215215
| Option row | Full-width row with start checkbox, label and description, and end content. | List and Item | Supporting | FR1, FR9, FR13 |
216216
| Checkbox | Presents the option's selection indicator. | CheckboxInput owner and `design:user-states` for its press | Prominent | FR1, FR6–FR8, FR11 |
217217
| Label, description | Name and describe the checkbox. | Item | Primary content | FR2, FR3 |
218-
| Checked-row fill | Supplements the checkbox state on enabled, editable checked rows. | unsettled (FR15, FR18) | Supporting | FR12 |
218+
| Checked-row fill | Supplements the checkbox state on enabled, editable checked rows. | row `selected` state (FR15); FR18 open | Supporting | FR12 |
219219
| Spinner | Replaces the mark while the option is busy. | Spinner | Supporting | FR7 |
220220

221221
This record carries no anatomy-theming map. The composed option anatomy and its
@@ -256,7 +256,8 @@ and CheckboxListItem owns no target of its own.
256256
| FR12, FR18 | `CheckboxList.a11y.chromium.spec.ts` `checked`, `hover-*`, and `pressed-*` cases | Light and dark; unchecked and checked | A missing or misplaced fill fails the row-paint check. Evidence gap: no assertion that `xstyle` composes after the fill. | `audit:CheckboxListItem/visual` |
257257
| FR13, FR16 | `CheckboxList.test.tsx` ref and styling, data-testid, and ARIA cases | Row ref, class, style, data, ARIA | A dropped or misrouted input fails. Evidence gap: no test asserts `event.currentTarget` for `onClick` (FR16). | `audit:CheckboxListItem/api` |
258258
| FR14 | `Checkbox.a11y.test.tsx` known failure `list-item-handlerless-read-only`; `CheckboxList.a11y.chromium.spec.ts` `handlerless` case | Standalone with `isChecked` and no `onCheck` | The recorded known failure stops matching when its gap closes. | `audit:CheckboxListItem/accessibility` |
259-
| FR15, FR19, AR5 | `CheckboxList.a11y.chromium.spec.ts` `focus-visible` and `forced-colors-focus` cases | Keyboard focus; forced colors | A lost focus indicator fails. Evidence gap: no test asserts the absent selection state (FR15) or counts focus indicators (FR19). | `audit:CheckboxListItem/visual` |
259+
| FR15 | `CheckboxList.test.tsx` checked-row state case | checked, unchecked, read-only and disabled rows | A checked, enabled, editable row without `selected` on its row targets fails; a read-only or disabled row with it fails | current source |
260+
| FR19, AR5 | `CheckboxList.a11y.chromium.spec.ts` `focus-visible` and `forced-colors-focus` cases | Keyboard focus; forced colors | A lost focus indicator fails. Evidence gap: no test counts focus indicators (FR19). | `audit:CheckboxListItem/visual` |
260261
| Direction | RTL audit target `core-checkboxlist--rich-descriptions` (`apps/storybook/rtl-audit/targets.json`); `CheckboxList.a11y.chromium.spec.ts` `rtl` case | LTR and RTL | The checkbox and end content fail to swap inline order. | `audit:CheckboxListItem/layout` |
261262
| ORD1–ORD4, PR1 | Covered by the FR4–FR10 and FR13 rows. Evidence gap: no test asserts the absence of observers, timers, or global listeners | — | — | `audit:CheckboxListItem/behavior` |
262263

@@ -269,8 +270,6 @@ and CheckboxListItem owns no target of its own.
269270
- **Mixed state after activation (FR5).** A standalone mixed item whose value
270271
stays mixed loses its native mixed state on activation, as
271272
`component:CheckboxInput` records.
272-
- **Checked-row state (FR15).** No selection state is reflected on the row
273-
targets, against `architecture:component-theming-surface` INV6.
274273
- **Two focus indicators (FR19).** Keyboard focus paints both the row outline
275274
and the checkbox ring, against `architecture:interaction-modality` INV3.
276275

@@ -284,8 +283,6 @@ No component-local decision. CheckboxListItem applies `spec:AST-021` and
284283
- **OQ1 — What does a standalone item with `isChecked` and no `onCheck`
285284
mean?** (`human-api`) Choose read-only, unavailable, or invalid usage,
286285
consistent with the matching CheckboxInput question.
287-
- **OQ2 — How should a theme reach the checked-row fill?** (`human-api`)
288-
Exposing it needs a target or reflected-state decision.
289286
- **OQ3 — Which element owns consumer DOM inputs?** (`human-api`) Data and ARIA
290287
reach the row while `onClick` runs on the checkbox under a row-typed handler.
291288
- **OQ4 — Should read-only item clicks propagate?** (`human-api`) No current

‎packages/core/src/CheckboxList/CheckboxList.test.tsx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,48 @@ describe('CheckboxList', () => {
9292
);
9393
});
9494

95+
it('reflects a checked row as selected on its row targets, so a theme can restyle checked rows (FR15)', () => {
96+
render(
97+
<>
98+
<CheckboxList label="Toppings" value={['cheese']} onChange={() => {}}>
99+
<CheckboxListItem
100+
label="Cheese"
101+
value="cheese"
102+
data-testid="cheese"
103+
/>
104+
<CheckboxListItem
105+
label="Olives"
106+
value="olives"
107+
data-testid="olives"
108+
/>
109+
</CheckboxList>
110+
<CheckboxList
111+
label="Locked"
112+
value={['ham']}
113+
onChange={() => {}}
114+
isReadOnly>
115+
<CheckboxListItem label="Ham" value="ham" data-testid="ham" />
116+
</CheckboxList>
117+
<CheckboxList
118+
label="Off"
119+
value={['egg']}
120+
onChange={() => {}}
121+
isDisabled>
122+
<CheckboxListItem label="Egg" value="egg" data-testid="egg" />
123+
</CheckboxList>
124+
</>,
125+
);
126+
const cheese = screen.getByTestId('cheese');
127+
expect(cheese).toHaveClass('astryx-item');
128+
expect(cheese).toHaveClass('astryx-list-item');
129+
expect(cheese).toHaveAttribute('data-selected', 'selected');
130+
expect(screen.getByTestId('olives')).not.toHaveAttribute('data-selected');
131+
// The state follows the checked-row fill, which a read-only or disabled
132+
// row does not paint.
133+
expect(screen.getByTestId('ham')).not.toHaveAttribute('data-selected');
134+
expect(screen.getByTestId('egg')).not.toHaveAttribute('data-selected');
135+
});
136+
95137
it('renders with label', () => {
96138
render(
97139
<CheckboxList label="Preferences" value={[]} onChange={() => {}}>

‎packages/core/src/CheckboxList/CheckboxListItem.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {CheckboxListContext} from './CheckboxListContext';
3636
import {ItemDescriptionContext} from '../Item/ItemDescriptionContext';
3737
import {joinAriaIDs} from '../utils/inputAria';
3838
import {useMergedRefs} from '../hooks/useMergedRefs';
39+
import {themeDataAttributes} from '../utils/themeProps';
3940
import type {ItemAlign} from '../Item';
4041
import {
4142
registerEnglishFallback,
@@ -352,9 +353,14 @@ export function CheckboxListItem({
352353
}
353354
};
354355

356+
// The state follows the fill, so a theme can restyle the text on it.
357+
const isCheckedRow =
358+
resolvedChecked === true && !effectiveDisabled && !effectiveReadOnly;
359+
355360
return (
356361
<ListItem
357362
{...restProps}
363+
{...themeDataAttributes({selected: isCheckedRow ? 'selected' : null})}
358364
ref={ref}
359365
label={namesFromVisibleLabel ? <span id={labelID}>{label}</span> : label}
360366
description={description}
@@ -376,10 +382,7 @@ export function CheckboxListItem({
376382
// at that strength. So the row brings the release back, and the box
377383
// fades with the row.
378384
rowOwnsPress && interactionOverlayStyles.pressedAlpha,
379-
resolvedChecked === true &&
380-
!effectiveDisabled &&
381-
!effectiveReadOnly &&
382-
styles.selected,
385+
isCheckedRow && styles.selected,
383386
xstyle,
384387
] as StyleXStyles
385388
}

0 commit comments

Comments
 (0)