Skip to content

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

TypeScript

test(a11y): add listbox semantic contract (#6349)

Cindy Zhangb1b24752572b
diff --git a/apps/storybook/stories/ListboxA11y.stories.tsx b/apps/storybook/stories/ListboxA11y.stories.tsx
new file mode 100644
index 0000000000..411de9fcf2
--- /dev/null
+++ b/apps/storybook/stories/ListboxA11y.stories.tsx
@@ -0,0 +1,92 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file ListboxA11y.stories.tsx
+ * @input Uses Selector, MultiSelector, and the bounded Listbox state inventory
+ * @output Stable browser reproductions of existing listbox/group/option states
+ * @position Accessibility contract fixtures; no visual baseline or product change.
+ */
+
+import type {Meta, StoryObj} from '@storybook/react';
+import {Selector} from '@astryxdesign/core/Selector';
+import {MultiSelector} from '@astryxdesign/core/MultiSelector';
+import {LISTBOX_SCENARIOS} from '../../../packages/core/src/Selector/__tests__/Listbox.a11y.states';
+
+function storyFor(id: string): StoryObj {
+ const scenario = LISTBOX_SCENARIOS.find(candidate => candidate.id === id);
+ if (scenario == null) {
+ throw new Error(`Missing Listbox scenario: ${id}`);
+ }
+ return {
+ render: () => (
+ <div
+ dir={scenario.direction ?? 'ltr'}
+ data-listbox-scenario={scenario.id}>
+ {scenario.component === 'Selector' ? (
+ <Selector
+ label="Fruit"
+ options={scenario.options}
+ value={scenario.values[0]}
+ onChange={() => {}}
+ hasSearch={scenario.hasSearch}
+ presentation={scenario.presentation}
+ isLoading={scenario.isLoading}
+ isLabelHidden={scenario.hiddenLabel}
+ renderOption={
+ scenario.customContent
+ ? option => <span>{option.label} details</span>
+ : undefined
+ }
+ isDefaultOpen
+ />
+ ) : (
+ <MultiSelector
+ label="Fruit"
+ options={scenario.options}
+ value={scenario.values}
+ onChange={() => {}}
+ hasSearch={scenario.hasSearch}
+ hasSelectAll={scenario.hasSelectAll}
+ presentation={scenario.presentation}
+ isLoading={scenario.isLoading}
+ isLabelHidden={scenario.hiddenLabel}
+ renderOption={
+ scenario.customContent
+ ? option => <span>{option.label} details</span>
+ : undefined
+ }
+ isDefaultOpen
+ />
+ )}
+ </div>
+ ),
+ };
+}
+
+const meta: Meta = {
+ title: 'a11y/Listbox pattern',
+ tags: ['no-visual'],
+};
+export default meta;
+
+export const SingleUnset = storyFor('single-unset');
+export const SingleSelected = storyFor('single-selected');
+export const SingleDisabledSelected = storyFor('single-disabled-selected');
+export const SingleGrouped = storyFor('single-grouped');
+export const SingleFiltered = storyFor('single-filtered');
+export const SingleCustomRtl = storyFor('single-custom-rtl');
+export const SingleSheet = storyFor('single-sheet');
+export const SingleSheetSearch = storyFor('single-sheet-search');
+export const SingleLoading = storyFor('single-loading');
+export const MultipleUnset = storyFor('multiple-unset');
+export const MultipleSelected = storyFor('multiple-selected');
+export const MultipleDisabledSelected = storyFor('multiple-disabled-selected');
+export const MultipleGrouped = storyFor('multiple-grouped');
+export const MultipleFiltered = storyFor('multiple-filtered');
+export const MultipleCustomRtl = storyFor('multiple-custom-rtl');
+export const MultipleSheet = storyFor('multiple-sheet');
+export const MultipleSheetSearch = storyFor('multiple-sheet-search');
+export const MultipleLoading = storyFor('multiple-loading');
+export const MultipleSelectAllNone = storyFor('multiple-select-all-none');
+export const MultipleSelectAllPartial = storyFor('multiple-select-all-partial');
+export const MultipleSelectAllAll = storyFor('multiple-select-all-all');
diff --git a/internal/a11y-spec/README.md b/internal/a11y-spec/README.md
index 19054baed6..f521cbf790 100644
--- a/internal/a11y-spec/README.md
+++ b/internal/a11y-spec/README.md
@@ -47,7 +47,8 @@ src/
├── text-input.* the native text-input pattern, same four files
├── modal-dialog.* the native modal-dialog pattern, same four files
├── status-message.* live-region and progress status mechanics
- └── tabs.* explicit horizontal ARIA Tabs semantics
+ ├── tabs.* explicit horizontal ARIA Tabs semantics
+ └── listbox.* listbox, group, and option semantics
```
## The patterns
@@ -62,6 +63,20 @@ src/
| `modal-dialog` | [APG dialog (modal)](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/) | Dialog |
| `status-message` | [WCAG 2.2 Status Messages](https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html) | Toast, FieldStatus, Spinner, ChatSystemMessage, ChatTypingIndicator, ProgressBar |
| `tabs` | [APG Tabs](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/) | Explicit `role="tablist"` TabList, Tab, and caller-authored tabpanels |
+| `listbox` | [WAI-ARIA 1.2 Listbox](https://www.w3.org/TR/wai-aria-1.2/#listbox) and WCAG 2.2 semantics | Selector and MultiSelector popup listbox, group, and option parts |
+
+The `listbox` contract is a bounded semantic migration, not blanket APG
+interaction adoption. Its first bindings cover 21 existing scenarios across
+single/multiple selection, disabled options, groups, filtering, custom content,
+RTL, hidden labels, sheet presentations, loading, and select-all states.
+Chromium records two exact existing failures: the no-search bottom-sheet
+listboxes for Selector and MultiSelector have no accessible name. Search-sheet
+variants and the other bound states pass; the exact failures remain visible debt
+under WCAG 2.2 4.1.2, not conformance or remediation.
+Trigger/search semantics, selection algorithms, keyboard/focus policy, empty
+representation, callbacks, forms, styling, and real-AT claims keep their named
+owners. The completeness exemptions make those limits visible rather than
+claiming whole-component conformance.
The `radio-group` contract owns direct-group Tab entry/exit, Space, and adopted
directional selection, including zero-selection entry. DropdownMenu radio roles
diff --git a/internal/a11y-spec/src/index.ts b/internal/a11y-spec/src/index.ts
index e6bf50a0c8..185c9be2b8 100644
--- a/internal/a11y-spec/src/index.ts
+++ b/internal/a11y-spec/src/index.ts
@@ -110,3 +110,5 @@ export {saysInOrder, spokenWords} from './spoken';
export {BUTTON_PATTERN, type ButtonStateFacts} from './patterns/button';
export {TABS_PATTERN, type TabsStateFacts} from './patterns/tabs';
+
+export {LISTBOX_PATTERN, type ListboxStateFacts} from './patterns/listbox';
diff --git a/internal/a11y-spec/src/patterns/listbox-selection.jsdom.test.ts b/internal/a11y-spec/src/patterns/listbox-selection.jsdom.test.ts
new file mode 100644
index 0000000000..0a2bb38f40
--- /dev/null
+++ b/internal/a11y-spec/src/patterns/listbox-selection.jsdom.test.ts
@@ -0,0 +1,63 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+/** @vitest-environment jsdom */
+
+/**
+ * @file listbox-selection.jsdom.test.ts
+ * @input Uses the Listbox contract, DOM harness, and explicit selection fixtures
+ * @output Proof that multiple selections cannot masquerade as single selection
+ * @position Contract self-tests; selection mechanics remain a separate owner.
+ */
+
+import {afterEach, describe, expect, it} from 'vitest';
+import {checkAccessibilitySpec} from '../check';
+import {createJsdomHarness} from '../harness/jsdom';
+import {LISTBOX_PATTERN} from './listbox';
+
+afterEach(() => document.body.replaceChildren());
+
+async function checkSelection(
+ count: number,
+ selectionAttribute: 'aria-selected' | 'aria-checked' = 'aria-selected',
+) {
+ return checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: 'fixture',
+ state: 'single-selection',
+ facts: {
+ part: 'listbox',
+ multiple: false,
+ optionRelations: ['one', 'two'],
+ selectionAttribute,
+ },
+ only: ['listbox.selection.single'],
+ mount: async () => {
+ document.body.innerHTML = `<div id="list" role="listbox" aria-label="Fruit"><div id="one" role="option" ${selectionAttribute}="${count > 0}">Apple</div><div id="two" role="option" ${selectionAttribute}="${count > 1}">Banana</div></div>`;
+ return createJsdomHarness({
+ subject: document.getElementById('list')!,
+ related: {
+ one: document.getElementById('one')!,
+ two: document.getElementById('two')!,
+ },
+ });
+ },
+ unmount: () => document.body.replaceChildren(),
+ });
+}
+
+describe('listbox.selection.single — WCAG 2.2 4.1.2', () => {
+ it.each([0, 1])('accepts %i selected options', async count => {
+ const result = await checkSelection(count);
+ expect(result.results[0]?.status).toBe('pass');
+ });
+
+ it.each(['aria-selected', 'aria-checked'] as const)(
+ 'rejects two selected options through %s',
+ async channel => {
+ const result = await checkSelection(2, channel);
+ expect(result.results[0]?.status).toBe('fail');
+ expect(result.results[0]?.detail).toBe(
+ 'the single-selection listbox exposes 2 selected options',
+ );
+ },
+ );
+});
diff --git a/internal/a11y-spec/src/patterns/listbox.chromium.spec.ts b/internal/a11y-spec/src/patterns/listbox.chromium.spec.ts
new file mode 100644
index 0000000000..b96d8cacbf
--- /dev/null
+++ b/internal/a11y-spec/src/patterns/listbox.chromium.spec.ts
@@ -0,0 +1,90 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file listbox.chromium.spec.ts
+ * @input Uses Playwright, the listbox contract, and real semantic HTML fixtures
+ * @output Browser-backed positive and deliberately violating identity proof
+ * @position Contract fixtures; no component or assistive-technology claim.
+ */
+
+import {expect, test} from '@playwright/test';
+import {checkAccessibilitySpec} from '../check';
+import {createChromiumHarness} from '../harness/chromium';
+import {LISTBOX_PATTERN, type ListboxStateFacts} from './listbox';
+
+const cases: ReadonlyArray<{
+ id: string;
+ part: ListboxStateFacts['part'];
+ html: string;
+ failure: string | null;
+}> = [
+ {
+ id: 'named-listbox',
+ part: 'listbox',
+ html: '<div data-subject role="listbox" aria-label="Fruit"><div role="option" aria-selected="false">Apple</div></div>',
+ failure: null,
+ },
+ {
+ id: 'group-role',
+ part: 'group',
+ html: '<div role="listbox" aria-label="Fruit"><div data-subject role="group"><div role="option" aria-selected="false">Orange</div></div></div>',
+ failure: null,
+ },
+ {
+ id: 'named-option',
+ part: 'option',
+ html: '<div role="listbox" aria-label="Fruit"><div data-subject role="option" aria-selected="false">Apple</div></div>',
+ failure: null,
+ },
+ {
+ id: 'wrong-listbox-role',
+ part: 'listbox',
+ html: '<div data-subject role="button" aria-label="Fruit">Apple</div>',
+ failure: 'the browser exposes button instead of listbox',
+ },
+ {
+ id: 'unnamed-listbox',
+ part: 'listbox',
+ html: '<div data-subject role="listbox"><div role="option" aria-selected="false">Apple</div></div>',
+ failure: 'the browser exposes the listbox without an accessible name',
+ },
+ {
+ id: 'unnamed-option',
+ part: 'option',
+ html: '<div role="listbox" aria-label="Fruit"><div data-subject role="option" aria-selected="false"></div></div>',
+ failure: 'the browser exposes the option without an accessible name',
+ },
+ {
+ id: 'hidden-listbox',
+ part: 'listbox',
+ html: '<div data-subject role="listbox" aria-label="Fruit" aria-hidden="true"><div role="option" aria-selected="false">Apple</div></div>',
+ failure: 'the browser exposes no role instead of listbox',
+ },
+];
+
+for (const fixture of cases) {
+ test(`listbox.exposure.identity — ${fixture.id}`, async ({page}) => {
+ const cdp = await page.context().newCDPSession(page);
+ const result = await checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: 'fixture',
+ state: fixture.id,
+ facts: {part: fixture.part, multiple: false},
+ only: ['listbox.exposure.identity'],
+ mount: async () => {
+ await page.setContent(fixture.html);
+ return createChromiumHarness({
+ page,
+ cdp,
+ subject: page.locator('[data-subject]'),
+ });
+ },
+ });
+ expect(result.results[0]?.status).toBe(
+ fixture.failure === null ? 'pass' : 'fail',
+ );
+ if (fixture.failure !== null) {
+ expect(result.results[0]?.detail).toBe(fixture.failure);
+ }
+ });
+}
diff --git a/internal/a11y-spec/src/patterns/listbox.jsdom.test.ts b/internal/a11y-spec/src/patterns/listbox.jsdom.test.ts
new file mode 100644
index 0000000000..180f3ab430
--- /dev/null
+++ b/internal/a11y-spec/src/patterns/listbox.jsdom.test.ts
@@ -0,0 +1,210 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+/** @vitest-environment jsdom */
+
+/**
+ * @file listbox.jsdom.test.ts
+ * @input Uses real DOM fixtures, the listbox contract, and the jsdom harness
+ * @output Positive and deliberately violating proof through checkAccessibilitySpec
+ * @position Contract self-tests, not component bindings.
+ */
+
+import {afterEach, describe, expect, it} from 'vitest';
+import {checkAccessibilitySpec} from '../check';
+import {createJsdomHarness} from '../harness/jsdom';
+import {LISTBOX_PATTERN} from './listbox';
+
+afterEach(() => document.body.replaceChildren());
+
+async function checkMultiple(attribute: string, multiple = true) {
+ return checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: 'fixture',
+ state: 'multiple',
+ facts: {part: 'listbox', multiple},
+ only: ['listbox.state.multiselectable'],
+ mount: async () => {
+ document.body.innerHTML = `<div role="listbox" aria-label="Fruit" ${attribute}><div role="option" aria-selected="false">Apple</div></div>`;
+ return createJsdomHarness({subject: document.body.firstElementChild!});
+ },
+ unmount: () => document.body.replaceChildren(),
+ });
+}
+
+describe('listbox.state.multiselectable — WCAG 2.2 4.1.2', () => {
+ it('accepts an exposed multiple-selection list', async () => {
+ const result = await checkMultiple('aria-multiselectable="true"');
+ expect(result.results[0]?.status).toBe('pass');
+ });
+
+ it('rejects a single-selection list advertised as multiple', async () => {
+ const result = await checkMultiple('aria-multiselectable="true"', false);
+ expect(result.results[0]?.status).toBe('fail');
+ expect(result.results[0]?.detail).toBe(
+ 'the listbox permits only one selection but aria-multiselectable is not false or absent',
+ );
+ });
+
+ it('accepts the implicit single-selection default', async () => {
+ const result = await checkMultiple('', false);
+ expect(result.results[0]?.status).toBe('pass');
+ });
+
+ it('detects a multiple-selection list that omits its state', async () => {
+ const result = await checkMultiple('');
+ expect(result.results[0]?.status).toBe('fail');
+ expect(result.results[0]?.detail).toBe(
+ 'the listbox permits multiple selection but aria-multiselectable is not true',
+ );
+ });
+});
+
+async function checkOption(selected: boolean, attribute: string) {
+ const facts = {part: 'option' as const, multiple: false, selected};
+ return checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: 'fixture',
+ state: 'option-selection',
+ facts,
+ only: ['listbox.option.selection-state'],
+ mount: async () => {
+ document.body.innerHTML = `<div role="listbox" aria-label="Fruit"><div data-subject role="option" ${attribute}>Apple</div></div>`;
+ return createJsdomHarness({
+ subject: document.querySelector('[data-subject]')!,
+ });
+ },
+ unmount: () => document.body.replaceChildren(),
+ });
+}
+
+describe('listbox.option.selection-state — WCAG 2.2 4.1.2', () => {
+ it('accepts the explicit unselected state of an option', async () => {
+ const result = await checkOption(false, 'aria-selected="false"');
+ expect(result.results[0]?.status).toBe('pass');
+ });
+
+ it('detects an unselected option that omits its state', async () => {
+ const result = await checkOption(false, '');
+ expect(result.results[0]?.status).toBe('fail');
+ expect(result.results[0]?.detail).toBe(
+ 'the option is unselected but aria-selected is absent',
+ );
+ });
+
+ it('accepts the selected option', async () => {
+ const result = await checkOption(true, 'aria-selected="true"');
+ expect(result.results[0]?.status).toBe('pass');
+ });
+
+ it('detects a selected option exposed as unselected', async () => {
+ const result = await checkOption(true, 'aria-selected="false"');
+ expect(result.results[0]?.status).toBe('fail');
+ expect(result.results[0]?.detail).toBe(
+ 'the option is selected but aria-selected is false',
+ );
+ });
+});
+
+async function checkDisabled(disabled: boolean, attribute: string) {
+ const facts = {
+ part: 'option' as const,
+ multiple: false,
+ selected: false,
+ disabled,
+ };
+ return checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: 'fixture',
+ state: 'option-disabled',
+ facts,
+ only: ['listbox.option.disabled-state'],
+ mount: async () => {
+ document.body.innerHTML = `<div role="listbox" aria-label="Fruit"><div data-subject role="option" aria-selected="false" ${attribute}>Apple</div></div>`;
+ return createJsdomHarness({
+ subject: document.querySelector('[data-subject]')!,
+ });
+ },
+ unmount: () => document.body.replaceChildren(),
+ });
+}
+
+describe('listbox.option.disabled-state — WCAG 2.2 4.1.2', () => {
+ it('accepts a disabled option with its state exposed', async () => {
+ const result = await checkDisabled(true, 'aria-disabled="true"');
+ expect(result.results[0]?.status).toBe('pass');
+ });
+
+ it('detects disabled state omitted from an unavailable option', async () => {
+ const result = await checkDisabled(true, '');
+ expect(result.results[0]?.status).toBe('fail');
+ expect(result.results[0]?.detail).toBe(
+ 'the option is disabled but aria-disabled is absent',
+ );
+ });
+});
+
+async function checkOwnership(owned: boolean) {
+ return checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: 'fixture',
+ state: 'option-owner',
+ facts: {part: 'option', multiple: false, selected: false, disabled: false},
+ only: ['listbox.relationship.owned'],
+ mount: async () => {
+ const option =
+ '<div data-subject role="option" aria-selected="false">Apple</div>';
+ document.body.innerHTML = `<div id="list" role="listbox" aria-label="Fruit">${owned ? option : ''}</div>${owned ? '' : option}`;
+ return createJsdomHarness({
+ subject: document.querySelector('[data-subject]')!,
+ related: {listbox: document.getElementById('list')!},
+ });
+ },
+ unmount: () => document.body.replaceChildren(),
+ });
+}
+
+describe('listbox.relationship.owned — WCAG 2.2 1.3.1', () => {
+ it.each([
+ ['dom', 'owns'],
+ ['owns', 'dom'],
+ ['owns', 'owns'],
+ ] as const)(
+ 'accepts an indirect %s → %s group relationship',
+ async (outer, inner) => {
+ const result = await checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: 'fixture',
+ state: 'indirect-owned-option',
+ facts: {part: 'option', multiple: false, ownerGroup: 'group'},
+ only: ['listbox.relationship.owned'],
+ mount: async () => {
+ const option =
+ '<div id="option" role="option" aria-selected="false">Orange</div>';
+ const group = `<div id="group" role="group" aria-label="Citrus" ${inner === 'owns' ? 'aria-owns="option"' : ''}>${inner === 'dom' ? option : ''}</div>`;
+ document.body.innerHTML = `<div id="list" role="listbox" aria-label="Fruit" ${outer === 'owns' ? 'aria-owns="group"' : ''}>${outer === 'dom' ? group : ''}</div>${outer === 'owns' ? group : ''}${inner === 'owns' ? option : ''}`;
+ return createJsdomHarness({
+ subject: document.getElementById('option')!,
+ related: {
+ listbox: document.getElementById('list')!,
+ group: document.getElementById('group')!,
+ },
+ });
+ },
+ unmount: () => document.body.replaceChildren(),
+ });
+ expect(result.results[0]?.status).toBe('pass');
+ },
+ );
+
+ it('accepts an option contained by its listbox', async () => {
+ const result = await checkOwnership(true);
+ expect(result.results[0]?.status).toBe('pass');
+ });
+
+ it('detects an option disconnected from its listbox', async () => {
+ const result = await checkOwnership(false);
+ expect(result.results[0]?.status).toBe('fail');
+ expect(result.results[0]?.detail).toBe(
+ 'the option is neither contained nor owned by its listbox',
+ );
+ });
+});
diff --git a/internal/a11y-spec/src/patterns/listbox.ts b/internal/a11y-spec/src/patterns/listbox.ts
new file mode 100644
index 0000000000..5a7474f965
--- /dev/null
+++ b/internal/a11y-spec/src/patterns/listbox.ts
@@ -0,0 +1,408 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file listbox.ts
+ * @input Uses the shared accessibility contract vocabulary
+ * @output LISTBOX_PATTERN and ListboxStateFacts
+ * @position Standards-derived semantics for listbox, group, and option parts.
+ */
+
+import {definePattern, type WcagCriterion} from '../contract';
+import {MissingBindingCapability} from '../check';
+import type {Subject} from '../harness';
+
+const NAME_ROLE_VALUE: WcagCriterion = {
+ standard: 'wcag',
+ id: '4.1.2',
+ name: 'Name, Role, Value',
+ level: 'A',
+ url: 'https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html',
+};
+
+export interface ListboxStateFacts {
+ readonly part: 'listbox' | 'group' | 'option';
+ readonly multiple: boolean;
+ readonly selected?: boolean;
+ readonly disabled?: boolean;
+ readonly selectionAttribute?: 'aria-selected' | 'aria-checked';
+ readonly ownerGroup?: string;
+ readonly optionRelations?: readonly string[];
+}
+
+export const LISTBOX_PATTERN = definePattern<ListboxStateFacts>({
+ pattern: 'listbox',
+ url: 'https://www.w3.org/TR/wai-aria-1.2/#listbox',
+ scope:
+ 'ARIA-authored listbox, group, and option semantics; native select/option mapping and interaction policy are separate owners.',
+ expectations: [
+ {
+ id: 'listbox.state.multiselectable',
+ outcome:
+ 'The listbox exposes whether more than one option may be selected.',
+ sources: [NAME_ROLE_VALUE],
+ covers: ['4.1.2-name-role-value'],
+ appliesWhen: {
+ condition: 'the subject is a listbox',
+ test: facts => facts.part === 'listbox',
+ },
+ evidenceLayer: 'dom',
+ enforcement: 'required',
+ run: async ({subject, facts}) => {
+ const multiple = await subject.attribute('aria-multiselectable');
+ if (facts.multiple && multiple !== 'true') {
+ throw new Error(
+ 'the listbox permits multiple selection but aria-multiselectable is not true',
+ );
+ }
+ if (!facts.multiple && multiple !== null && multiple !== 'false') {
+ throw new Error(
+ 'the listbox permits only one selection but aria-multiselectable is not false or absent',
+ );
+ }
+ },
+ },
+ {
+ id: 'listbox.option.selection-state',
+ outcome: 'An option exposes the selection state its owner supplies.',
+ sources: [NAME_ROLE_VALUE],
+ covers: ['4.1.2-name-role-value'],
+ appliesWhen: {
+ condition: 'the subject is an option',
+ test: facts => facts.part === 'option',
+ },
+ evidenceLayer: 'dom',
+ enforcement: 'required',
+ run: async ({subject, facts}) => {
+ if (facts.selected == null) {
+ throw new MissingBindingCapability(
+ 'an option binding must declare selected state',
+ );
+ }
+ const attribute = facts.selectionAttribute ?? 'aria-selected';
+ const selected = await subject.attribute(attribute);
+ if (selected !== String(facts.selected)) {
+ throw new Error(
+ `the option is ${facts.selected ? 'selected' : 'unselected'} but ${attribute} is ${selected ?? 'absent'}`,
+ );
+ }
+ },
+ },
+ {
+ id: 'listbox.option.disabled-state',
+ outcome:
+ 'An option exposes its availability without choosing a focus policy.',
+ sources: [NAME_ROLE_VALUE],
+ covers: ['4.1.2-name-role-value'],
+ appliesWhen: {
+ condition: 'the subject is an option',
+ test: facts => facts.part === 'option',
+ },
+ evidenceLayer: 'dom',
+ enforcement: 'required',
+ run: async ({subject, facts}) => {
+ if (facts.disabled == null) {
+ throw new MissingBindingCapability(
+ 'an option binding must declare disabled state',
+ );
+ }
+ const disabled = await subject.attribute('aria-disabled');
+ if (
+ facts.disabled
+ ? disabled !== 'true'
+ : disabled !== null && disabled !== 'false'
+ ) {
+ throw new Error(
+ `the option is ${facts.disabled ? 'disabled' : 'available'} but aria-disabled is ${disabled ?? 'absent'}`,
+ );
+ }
+ },
+ },
+ {
+ id: 'listbox.relationship.owned',
+ outcome: 'Options and groups keep their declared listbox relationship.',
+ sources: [
+ {
+ standard: 'wcag',
+ id: '1.3.1',
+ name: 'Info and Relationships',
+ level: 'A',
+ url: 'https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships.html',
+ },
+ {
+ standard: 'web-standard',
+ specification: 'WAI-ARIA 1.2',
+ requirement:
+ 'Authors MUST ensure elements with role option are contained in, or owned by, an element with the role listbox or group within a listbox.',
+ url: 'https://www.w3.org/TR/wai-aria-1.2/#option',
+ },
+ ],
+ covers: ['1.3.1-info-and-relationships'],
+ appliesWhen: {
+ condition: 'the subject is an option or option group',
+ test: facts => facts.part !== 'listbox',
+ },
+ evidenceLayer: 'dom',
+ enforcement: 'required',
+ run: async ({harness, subject, facts}) => {
+ const listbox = await harness.related('listbox');
+ const owner =
+ facts.part === 'option' && facts.ownerGroup != null
+ ? await harness.related(facts.ownerGroup)
+ : listbox;
+ const owns = async (parent: Subject, child: Subject) =>
+ (await harness.contains(parent, child)) ||
+ (await harness.references(parent, 'aria-owns', child));
+ if (
+ !(await owns(owner, subject)) ||
+ (owner !== listbox && !(await owns(listbox, owner)))
+ ) {
+ throw new Error(
+ `the ${facts.part} is neither contained nor owned by its listbox`,
+ );
+ }
+ },
+ },
+ {
+ id: 'listbox.exposure.identity',
+ outcome:
+ 'The browser exposes each part with its role and any required identifying name.',
+ sources: [NAME_ROLE_VALUE],
+ covers: ['4.1.2-name-role-value'],
+ appliesWhen: {
+ condition: 'the declared semantic part is rendered',
+ test: () => true,
+ },
+ evidenceLayer: 'accessibility-tree',
+ enforcement: 'required',
+ run: async ({subject, facts}) => {
+ const {role, name} = await subject.computed();
+ if (role !== facts.part) {
+ throw new Error(
+ `the browser exposes ${role ?? 'no role'} instead of ${facts.part}`,
+ );
+ }
+ if (facts.part !== 'group' && name.trim() === '') {
+ throw new Error(
+ `the browser exposes the ${facts.part} without an accessible name`,
+ );
+ }
+ },
+ },
+ {
+ id: 'listbox.selection.single',
+ outcome:
+ 'A single-selection listbox does not expose multiple selected options.',
+ sources: [
+ NAME_ROLE_VALUE,
+ {
+ standard: 'web-standard',
+ specification: 'WAI-ARIA 1.2',
+ requirement: 'Only one item can be selected.',
+ url: 'https://www.w3.org/TR/wai-aria-1.2/#aria-multiselectable',
+ },
+ ],
+ covers: ['4.1.2-name-role-value'],
+ appliesWhen: {
+ condition: 'the listbox permits only one selected option',
+ test: facts => facts.part === 'listbox' && !facts.multiple,
+ },
+ evidenceLayer: 'dom',
+ enforcement: 'required',
+ run: async ({harness, facts}) => {
+ if (facts.optionRelations == null) {
+ throw new MissingBindingCapability(
+ 'a single-selection listbox must declare its option relations',
+ );
+ }
+ const attribute = facts.selectionAttribute ?? 'aria-selected';
+ let selected = 0;
+ for (const relation of facts.optionRelations) {
+ if (
+ (await (await harness.related(relation)).attribute(attribute)) ===
+ 'true'
+ ) {
+ selected += 1;
+ }
+ }
+ if (selected > 1) {
+ throw new Error(
+ `the single-selection listbox exposes ${selected} selected options`,
+ );
+ }
+ },
+ },
+ ],
+ exemptions: {
+ '1.1.1-non-text-content': {
+ owner: 'Caller content and Icon/Indicator components',
+ verifiedBy: 'Content review and the existing component-scoped axe audit',
+ reason:
+ 'A semantic part name does not establish the meaning of every image or decorative asset in caller-rendered content.',
+ },
+ '1.3.1-info-and-relationships': {
+ owner: 'Component markup and axe ARIA content-model checks',
+ verifiedBy: 'Existing pr-a11y checks and component composition tests',
+ reason:
+ 'This contract checks the declared listbox ownership; allowed child-role structure and other composed relationships retain their existing checks.',
+ coversRemainderOnly: true,
+ },
+ '1.3.2-meaningful-sequence': {
+ owner: 'Selector/MultiSelector ordering and caller content',
+ verifiedBy:
+ 'Component sorting/filtering suites and browser reading-order review',
+ reason:
+ 'This semantic slice does not choose a sorting or visual-order policy.',
+ },
+ '1.3.5-identify-input-purpose': {
+ owner: 'Form callsite and combobox input',
+ verifiedBy: 'Form-purpose and autocomplete review',
+ reason:
+ 'A popup option container does not determine which personal-information purpose the surrounding field collects.',
+ },
+ '1.4.1-use-of-color': {
+ owner: 'Component and theme selection indicators',
+ verifiedBy:
+ 'Indicator tests and visual review of selected/unselected states',
+ reason:
+ 'Programmatic selection exposure does not prove a non-color visual cue.',
+ },
+ '1.4.3-contrast-minimum': {
+ owner: 'Component themes and caller content',
+ verifiedBy: 'Existing contrast audit and rendered theme review',
+ reason:
+ 'Contrast needs rendered pixels and is not established by DOM or accessibility-tree semantics.',
+ },
+ '1.4.11-non-text-contrast': {
+ owner: 'Component themes and indicator/focus styling',
+ verifiedBy: 'Existing contrast audit and rendered selected/focus states',
+ reason:
+ 'The semantic contract does not measure painted controls or graphics.',
+ },
+ '2.1.1-keyboard': {
+ owner: 'Selector/MultiSelector interaction and combobox contracts',
+ verifiedBy:
+ 'Existing component keyboard suites; separate real-browser interaction review',
+ reason:
+ 'This first slice does not adopt a shared focus/selection model. Its results are not keyboard-conformance evidence.',
+ },
+ '2.1.2-no-keyboard-trap': {
+ owner: 'Combobox, Popover, and BottomSheet lifecycle',
+ verifiedBy:
+ 'Popup keyboard/dismissal suites and native-browser Tab checks',
+ reason:
+ 'Entry and exit belong to the active host presentation rather than the static option semantics bound here.',
+ },
+ '2.4.2-page-titled': {
+ owner: 'Page shell',
+ verifiedBy: 'Page-level accessibility review',
+ reason: 'Neither a listbox nor an option owns the document title.',
+ },
+ '2.4.3-focus-order': {
+ owner: 'Combobox and popup focus owners',
+ verifiedBy: 'Existing focus suites and real-browser presentation review',
+ reason:
+ 'Selection state and focus are distinct; this contract does not choose or attest a focus movement model.',
+ },
+ '2.4.4-link-purpose': {
+ owner: 'Link and caller content',
+ verifiedBy: 'Navigation-destination contract and content review',
+ reason: 'An option selects a value; it is not a navigation link.',
+ },
+ '2.4.6-headings-and-labels': {
+ owner: 'Caller labels and component content review',
+ verifiedBy: 'Review of field, group, and option wording',
+ reason:
+ 'A nonempty computed name does not prove that its wording describes the intended topic.',
+ },
+ '2.4.7-focus-visible': {
+ owner: 'Component themes and interaction-modality system',
+ verifiedBy: 'Rendered keyboard-focus review and the existing visual lane',
+ reason: 'No pixel or focus-ring claim is made by these semantic checks.',
+ },
+ '2.4.11-focus-not-obscured': {
+ owner: 'Popup host and application layout',
+ verifiedBy: 'Constrained-viewport real-browser focus review',
+ reason:
+ 'Geometry and occlusion depend on the presentation and surrounding layout.',
+ },
+ '2.5.2-pointer-cancellation': {
+ owner: 'Selector/MultiSelector option interaction',
+ verifiedBy: 'Separate real-browser press/abort/release regression checks',
+ reason:
+ 'The binding observes state without adopting or claiming a pointer-selection transition contract.',
+ },
+ '2.5.3-label-in-name': {
+ owner: 'Component rendering and caller option content',
+ verifiedBy: 'Rendered-label versus computed-name review',
+ reason:
+ 'Identity presence is narrower than matching painted label text; custom option content remains separately reviewed.',
+ },
+ '2.5.8-target-size': {
+ owner: 'Component themes and composition',
+ verifiedBy: 'Browser target geometry and WCAG exception review',
+ reason:
+ 'Target dimensions and spacing cannot be proved from semantic state.',
+ },
+ '3.1.1-language-of-page': {
+ owner: 'Page shell and localization provider',
+ verifiedBy: 'Document-language and locale integration checks',
+ reason: 'The popup does not own the document language.',
+ },
+ '3.2.2-on-input': {
+ owner: 'Component interaction and application response to selection',
+ verifiedBy: 'Component interaction suites and end-to-end task review',
+ reason:
+ 'This contract does not activate options or decide what the application does with a selected value.',
+ },
+ '3.2.4-consistent-identification': {
+ owner: 'Design system and application content',
+ verifiedBy: 'Cross-control content/design review',
+ reason:
+ 'One popup fixture cannot establish consistent identification across an application.',
+ },
+ '3.3.1-error-identification': {
+ owner: 'Field validation and status-message owners',
+ verifiedBy: 'Existing input/status suites and textual-error review',
+ reason:
+ 'Validation feedback belongs to the surrounding field, not each option.',
+ },
+ '3.3.2-labels-or-instructions': {
+ owner: 'Field and caller instructions',
+ verifiedBy: 'Field-label and form-content review',
+ reason:
+ 'A named popup does not establish every instruction needed by its enclosing task.',
+ },
+ '4.1.3-status-messages': {
+ owner: 'Status-message contract and component live-region owners',
+ verifiedBy: 'Status-message bindings; AST-009 for speech/timing claims',
+ reason:
+ 'Loading, result-count, empty, and selection announcements are not static listbox identity.',
+ },
+ 'apg-interaction': {
+ owner:
+ 'Current component interaction authority and future bounded migration',
+ verifiedBy: 'Current-record review plus component keyboard suites',
+ reason:
+ 'WAI-ARIA semantics apply here, but this slice does not adopt APG selection-follows-focus, unavailable-option navigation, Home/End, or typeahead policy.',
+ },
+ 'forced-colors': {
+ owner: 'Component themes and indicators',
+ verifiedBy: 'Real-browser forced-color paint review',
+ reason:
+ 'State exposure does not prove that a selection mark or focus indicator remains visible.',
+ },
+ 'reduced-motion': {
+ owner: 'Popover/BottomSheet and component themes',
+ verifiedBy: 'Existing reduced-motion tests and browser review',
+ reason:
+ 'The semantic part contract owns no opening or closing animation.',
+ },
+ 'at-facing-strings': {
+ owner: 'Component localization and caller labels',
+ verifiedBy:
+ 'Catalog checks and localized component tests; AST-009 for speech claims',
+ reason:
+ 'The binding uses deterministic labels without claiming translation completeness or spoken output.',
+ },
+ },
+});
diff --git a/packages/core/src/MultiSelector/MultiSelector.test.tsx b/packages/core/src/MultiSelector/MultiSelector.test.tsx
index 54c0e75886..0329947b2d 100644
--- a/packages/core/src/MultiSelector/MultiSelector.test.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.test.tsx
@@ -478,39 +478,6 @@ describe('MultiSelector', () => {
expect(trigger).toHaveAttribute('aria-required', 'true');
});
- it('renders listbox with aria-multiselectable', async () => {
- const user = userEvent.setup();
- render(
- <MultiSelector
- label="Fruit"
- options={defaultOptions}
- value={[]}
- onChange={() => {}}
- />,
- );
-
- await user.click(screen.getByRole('combobox'));
- const listbox = screen.getByRole('listbox', h);
- expect(listbox).toHaveAttribute('aria-multiselectable', 'true');
- });
-
- it('marks selected options with aria-selected', async () => {
- const user = userEvent.setup();
- render(
- <MultiSelector
- label="Fruit"
- options={defaultOptions}
- value={['Apple']}
- onChange={() => {}}
- />,
- );
-
- await user.click(screen.getByRole('combobox'));
- const options = screen.getAllByRole('option', h);
- expect(options[0]).toHaveAttribute('aria-selected', 'true');
- expect(options[1]).toHaveAttribute('aria-selected', 'false');
- });
-
it('shows error status with aria-invalid', () => {
render(
<MultiSelector
@@ -1393,8 +1360,7 @@ describe('MultiSelector', () => {
await user.click(screen.getByRole('combobox'));
const options = screen.getAllByRole('option', h);
expect(options).toHaveLength(3);
- const group = screen.getByRole('group', h);
- expect(group).toHaveAttribute('aria-label', 'Citrus');
+ expect(screen.getByText('Citrus')).toBeInTheDocument();
});
it('shows loading state with a spinner and aria-busy', () => {
diff --git a/packages/core/src/MultiSelector/__tests__/MultiSelector.listbox.a11y.test.tsx b/packages/core/src/MultiSelector/__tests__/MultiSelector.listbox.a11y.test.tsx
new file mode 100644
index 0000000000..5d26a0b86d
--- /dev/null
+++ b/packages/core/src/MultiSelector/__tests__/MultiSelector.listbox.a11y.test.tsx
@@ -0,0 +1,128 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file MultiSelector.listbox.a11y.test.tsx
+ * @input Uses MultiSelector, its part/state inventory, and the shared Listbox contract
+ * @output DOM evidence for real multi-select listbox, group, and option parts
+ * @position Component-facing binding; API, form, composition, and styling stay local.
+ */
+
+import {cleanup, render, screen, within} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import {describe, expect, it} from 'vitest';
+import {
+ expectAccessibilitySpec,
+ LISTBOX_PATTERN,
+} from '@astryxdesign/a11y-spec';
+import {MultiSelector} from '../MultiSelector';
+import {
+ LISTBOX_SCENARIOS,
+ listboxParts,
+} from '../../Selector/__tests__/Listbox.a11y.states';
+import {installListboxDialogStubs} from '../../Selector/__tests__/Listbox.a11y.dom';
+
+installListboxDialogStubs();
+
+const scenarios = LISTBOX_SCENARIOS.filter(
+ scenario => scenario.component === 'MultiSelector',
+);
+
+describe('MultiSelector Listbox semantic binding', () => {
+ it.each(scenarios)('$id', async scenario => {
+ for (const part of listboxParts(scenario)) {
+ await expectAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: `MultiSelector.${part.role}`,
+ state: part.state,
+ facts: part.facts,
+ render: async () => {
+ render(
+ <div dir={scenario.direction ?? 'ltr'}>
+ <MultiSelector
+ label="Fruit"
+ options={scenario.options}
+ value={scenario.values}
+ onChange={() => {}}
+ hasSearch={scenario.hasSearch}
+ hasSelectAll={scenario.hasSelectAll}
+ presentation={scenario.presentation}
+ isLoading={scenario.isLoading}
+ isLabelHidden={scenario.hiddenLabel}
+ renderOption={
+ scenario.customContent
+ ? option => <span>{option.label} details</span>
+ : undefined
+ }
+ isDefaultOpen
+ />
+ </div>,
+ );
+ await screen.findByRole('listbox', {hidden: true});
+ if (scenario.query != null) {
+ await userEvent
+ .setup()
+ .type(
+ screen.getByRole('combobox', {hidden: true}),
+ scenario.query,
+ );
+ }
+ },
+ subject: () =>
+ part.role === 'listbox'
+ ? screen.getByRole('listbox', {hidden: true})
+ : part.role === 'group'
+ ? within(
+ screen.getByRole('listbox', {hidden: true}),
+ ).getAllByRole('group', {hidden: true})[
+ scenario.groups.indexOf(part.name ?? '')
+ ]
+ : within(screen.getByRole('listbox', {hidden: true})).getByRole(
+ 'option',
+ {name: part.name, hidden: true},
+ ),
+ related: () => {
+ const listbox = screen.getByRole('listbox', {hidden: true});
+ expect(
+ within(listbox).getAllByRole('option', {hidden: true}),
+ ).toHaveLength(scenario.expectedOptions.length);
+ return {
+ listbox,
+ ...Object.fromEntries(
+ scenario.expectedOptions.map(option => [
+ `option:${option.value}`,
+ within(listbox).getByRole('option', {
+ name: option.name,
+ hidden: true,
+ }),
+ ]),
+ ),
+ ...Object.fromEntries(
+ scenario.groups.map((name, index) => [
+ `group:${name}`,
+ within(listbox).getAllByRole('group', {hidden: true})[index],
+ ]),
+ ),
+ };
+ },
+ cleanup,
+ });
+ }
+ });
+
+ it('keeps the bounded state matrix and select-all states explicit', () => {
+ expect(scenarios.map(scenario => scenario.id)).toEqual([
+ 'multiple-unset',
+ 'multiple-selected',
+ 'multiple-disabled-selected',
+ 'multiple-grouped',
+ 'multiple-filtered',
+ 'multiple-custom-rtl',
+ 'multiple-sheet',
+ 'multiple-sheet-search',
+ 'multiple-loading',
+ 'multiple-select-all-none',
+ 'multiple-select-all-partial',
+ 'multiple-select-all-all',
+ ]);
+ });
+});
diff --git a/packages/core/src/Selector/Selector.spec.md b/packages/core/src/Selector/Selector.spec.md
index 5337f0c0c8..7ae2f66341 100644
--- a/packages/core/src/Selector/Selector.spec.md
+++ b/packages/core/src/Selector/Selector.spec.md
@@ -14,6 +14,8 @@ verified_by:
[
packages/core/src/Selector/Selector.test.tsx,
packages/core/src/Selector/Selector.source-build.test.mjs,
+ packages/core/src/Selector/__tests__/Selector.listbox.a11y.test.tsx,
+ packages/core/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts,
]
modules: []
families: [family:input-fields]
@@ -274,15 +276,16 @@ in `spec:AST-004` as current runtime behavior.
## Verification map
-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
-| --------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | -------------------------------- |
-| FR1, AR2, AR3 | `Selector.test.tsx` selection, focus, and keyboard suites | closed/open, search/non-search, disabled option | Removing selection wiring, focus movement, or keyboard behavior fails the named interaction tests | `audit:Selector/behavior` |
-| FR2 | placement and selected-item geometry tests | default, explicit, RTL, transformed entry | Using the wrong positioning model fails the expected position-area or margin | `audit:Selector/behavior` |
-| FR3, AV1 | `itemMarkColumn` source inspection plus indicator-position and replacement-indicator tests | start/end, selected/unselected, check/radio | Removing the wrapper fails row-structure tests; changing its reserved width requires source/layout review | `audit:Selector/design-rendered` |
-| FR4, AR1, AR2 | presentation tests plus `aria-haspopup` source review | pointer, compact coarse pointer, search/non-search | Wrong Popover/dialog roles or focus destinations fail tests; `aria-haspopup` values require source/a11y review | `audit:Selector/accessibility` |
-| FR5 | loading, empty-state, and live-region tests | empty options, unmatched search, loading | Empty/no-results output appears or is announced while loading | `audit:Selector/behavior` |
-| FR6, AR4 | read-only interaction, form, ARIA, and theme-state tests | search/non-search, clearable, open→read-only, disabled precedence | A value changes, popup or edit affordance remains, form value disappears, or read-only semantics are absent | `audit:Selector/accessibility` |
-| source-build contract | `Selector.source-build.test.mjs` | package source compiled by consumer Babel | Moving evaluated StyleX values outside the supported source form fails compilation | `audit:Selector/code-health` |
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| --------------------- | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
+| FR1, AR2, AR3 | `Selector.test.tsx` selection, focus, and keyboard suites | closed/open, search/non-search, disabled option | Removing selection wiring, focus movement, or keyboard behavior fails the named interaction tests | `audit:Selector/behavior` |
+| FR2 | placement and selected-item geometry tests | default, explicit, RTL, transformed entry | Using the wrong positioning model fails the expected position-area or margin | `audit:Selector/behavior` |
+| FR3, AV1 | `itemMarkColumn` source inspection plus indicator-position and replacement-indicator tests | start/end, selected/unselected, check/radio | Removing the wrapper fails row-structure tests; changing its reserved width requires source/layout review | `audit:Selector/design-rendered` |
+| FR4, AR1, AR2 | presentation tests plus `aria-haspopup` source review | pointer, compact coarse pointer, search/non-search | Wrong Popover/dialog roles or focus destinations fail tests; `aria-haspopup` values require source/a11y review | `audit:Selector/accessibility` |
+| AR1, AV2 | `Selector.listbox.a11y.test.tsx` and `Listbox.a11y.chromium.spec.ts` against the shared Listbox contract | popover/sheet, flat/grouped, selected/unselected, disabled, search, loading, custom RTL | A new or wider loss of role, listbox/option name, state, or ownership gates; the exact unnamed no-search sheet state remains known debt | `audit:Selector/accessibility` |
+| FR5 | loading, empty-state, and live-region tests | empty options, unmatched search, loading | Empty/no-results output appears or is announced while loading | `audit:Selector/behavior` |
+| FR6, AR4 | read-only interaction, form, ARIA, and theme-state tests | search/non-search, clearable, open→read-only, disabled precedence | A value changes, popup or edit affordance remains, form value disappears, or read-only semantics are absent | `audit:Selector/accessibility` |
+| source-build contract | `Selector.source-build.test.mjs` | package source compiled by consumer Babel | Moving evaluated StyleX values outside the supported source form fails compilation | `audit:Selector/code-health` |
## Decision log
diff --git a/packages/core/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts b/packages/core/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts
new file mode 100644
index 0000000000..54c5f78047
--- /dev/null
+++ b/packages/core/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts
@@ -0,0 +1,130 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Listbox.a11y.chromium.spec.ts
+ * @input Uses the Listbox contract, browser harness, state inventory, and checked-in stories
+ * @output DOM/accessibility-tree evidence for each real Listbox binding part
+ * @position Browser binding; keyboard policy, pixels, and real AT remain separate owners.
+ */
+
+import {expect, test} from '@playwright/test';
+import {
+ LISTBOX_PATTERN,
+ checkAccessibilitySpec,
+ blockingResults,
+ formatFailures,
+ formatReport,
+ summarize,
+ neverExercised,
+ unmatchedKnownFailures,
+ type BindingResult,
+} from '@astryxdesign/a11y-spec';
+import {
+ createChromiumHarness,
+ holdMotionStill,
+} from '@astryxdesign/a11y-spec/chromium';
+import {
+ serveStorybook,
+ DEFAULT_STORYBOOK_DIR,
+ type StaticServer,
+} from '@astryxdesign/a11y-spec/storybook';
+import {LISTBOX_KNOWN_FAILURES} from './Listbox.a11y.known-failures';
+import {LISTBOX_SCENARIOS, listboxParts} from './Listbox.a11y.states';
+
+let storybook: StaticServer;
+const observedResults: BindingResult[] = [];
+test.beforeAll(async () => {
+ storybook = await serveStorybook(
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
+ );
+});
+test.afterAll(async () => {
+ await storybook?.close();
+ expect(
+ unmatchedKnownFailures(LISTBOX_KNOWN_FAILURES, observedResults),
+ ).toEqual([]);
+});
+
+for (const scenario of LISTBOX_SCENARIOS) {
+ test(`${scenario.component} — ${scenario.id}`, async ({page}) => {
+ test.setTimeout(2 * 60 * 1000);
+ const cdp = await page.context().newCDPSession(page);
+ const results: BindingResult[] = [];
+ const mount = async () => {
+ await page.goto(
+ `${storybook.origin}/iframe.html?id=a11y-listbox-pattern--${scenario.id}&viewMode=story&globals=direction:${scenario.direction ?? 'ltr'}`,
+ {waitUntil: 'load'},
+ );
+ await holdMotionStill(page);
+ await expect(
+ page.locator(`[data-listbox-scenario="${scenario.id}"]`),
+ ).toBeAttached();
+ await page.getByRole('listbox').waitFor({state: 'visible'});
+ if (scenario.query != null) {
+ await page.getByRole('combobox').fill(scenario.query);
+ }
+ await expect(page.getByRole('listbox').getByRole('option')).toHaveCount(
+ scenario.expectedOptions.length,
+ );
+ };
+
+ for (const part of listboxParts(scenario)) {
+ results.push(
+ await checkAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: `${scenario.component}.${part.role}`,
+ state: part.state,
+ facts: part.facts,
+ knownFailures: LISTBOX_KNOWN_FAILURES,
+ mount: async () => {
+ await mount();
+ const listbox = page.getByRole('listbox');
+ const subject =
+ part.role === 'listbox'
+ ? listbox
+ : part.role === 'group'
+ ? listbox
+ .getByRole('group')
+ .nth(scenario.groups.indexOf(part.name ?? ''))
+ : listbox.getByRole('option', {
+ name: part.name,
+ exact: true,
+ });
+ return createChromiumHarness({
+ page,
+ cdp,
+ subject,
+ related: {
+ listbox,
+ ...Object.fromEntries(
+ scenario.expectedOptions.map(option => [
+ `option:${option.value}`,
+ listbox.getByRole('option', {
+ name: option.name,
+ exact: true,
+ }),
+ ]),
+ ),
+ ...Object.fromEntries(
+ scenario.groups.map((name, index) => [
+ `group:${name}`,
+ listbox.getByRole('group').nth(index),
+ ]),
+ ),
+ },
+ });
+ },
+ }),
+ );
+ }
+
+ observedResults.push(...results);
+ const report = summarize(LISTBOX_PATTERN, results);
+ console.log(formatReport(report));
+ expect(formatFailures(blockingResults(results))).toBe('');
+ expect(report.counts.unrun).toBe(0);
+ if (scenario.component === 'Selector' && scenario.groups.length > 0) {
+ expect(neverExercised(results)).toEqual([]);
+ }
+ });
+}
diff --git a/packages/core/src/Selector/__tests__/Listbox.a11y.dom.ts b/packages/core/src/Selector/__tests__/Listbox.a11y.dom.ts
new file mode 100644
index 0000000000..59ade8afbe
--- /dev/null
+++ b/packages/core/src/Selector/__tests__/Listbox.a11y.dom.ts
@@ -0,0 +1,38 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Listbox.a11y.dom.ts
+ * @input Uses Vitest lifecycle hooks and the DOM Dialog prototype
+ * @output Scoped stubs for Dialog methods missing from jsdom
+ * @position DOM-only binding setup; these stubs prove no native modal behavior.
+ */
+
+import {afterAll, beforeAll} from 'vitest';
+
+export function installListboxDialogStubs(): void {
+ const originals = new Map<string, PropertyDescriptor | undefined>();
+ beforeAll(() => {
+ for (const name of ['show', 'showModal', 'close']) {
+ originals.set(
+ name,
+ Object.getOwnPropertyDescriptor(HTMLDialogElement.prototype, name),
+ );
+ Object.defineProperty(HTMLDialogElement.prototype, name, {
+ configurable: true,
+ writable: true,
+ value: function (this: HTMLDialogElement) {
+ this.open = name !== 'close';
+ },
+ });
+ }
+ });
+ afterAll(() => {
+ for (const [name, descriptor] of originals) {
+ if (descriptor == null) {
+ Reflect.deleteProperty(HTMLDialogElement.prototype, name);
+ } else {
+ Object.defineProperty(HTMLDialogElement.prototype, name, descriptor);
+ }
+ }
+ });
+}
diff --git a/packages/core/src/Selector/__tests__/Listbox.a11y.inventory.test.ts b/packages/core/src/Selector/__tests__/Listbox.a11y.inventory.test.ts
new file mode 100644
index 0000000000..83194c1ff8
--- /dev/null
+++ b/packages/core/src/Selector/__tests__/Listbox.a11y.inventory.test.ts
@@ -0,0 +1,63 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Listbox.a11y.inventory.test.ts
+ * @input Uses the locked Listbox migration matrix and checklist
+ * @output Coverage-boundary and part-inventory regression checks
+ * @position Binding metadata proof, separate from runtime conformance results.
+ */
+
+import {describe, expect, it} from 'vitest';
+import {LISTBOX_PATTERN, unansweredDimensions} from '@astryxdesign/a11y-spec';
+import {LISTBOX_KNOWN_FAILURES} from './Listbox.a11y.known-failures';
+import {
+ LISTBOX_SCENARIOS,
+ LISTBOX_EXCLUSIONS,
+ listboxParts,
+} from './Listbox.a11y.states';
+
+describe('Listbox migration inventory', () => {
+ it('accounts for every checklist dimension without claiming other evidence layers', () => {
+ expect(unansweredDimensions(LISTBOX_PATTERN)).toEqual([]);
+ expect(LISTBOX_EXCLUSIONS).toHaveLength(5);
+ });
+
+ it('binds 21 scenarios and all six real semantic parts', () => {
+ expect(LISTBOX_SCENARIOS).toHaveLength(21);
+ const parts = LISTBOX_SCENARIOS.flatMap(scenario =>
+ listboxParts(scenario).map(part => ({
+ binding: `${scenario.component}.${part.role}`,
+ state: part.state,
+ })),
+ );
+ expect(parts).toHaveLength(89);
+ expect(new Set(parts.map(part => part.state)).size).toBe(89);
+ expect([...new Set(parts.map(part => part.binding))].sort()).toEqual([
+ 'MultiSelector.group',
+ 'MultiSelector.listbox',
+ 'MultiSelector.option',
+ 'Selector.group',
+ 'Selector.listbox',
+ 'Selector.option',
+ ]);
+ });
+
+ it('pins each known failure to one exact inventory part', () => {
+ const parts = LISTBOX_SCENARIOS.flatMap(scenario =>
+ listboxParts(scenario).map(part => ({
+ binding: `${scenario.component}.${part.role}`,
+ state: part.state,
+ })),
+ );
+
+ expect(LISTBOX_KNOWN_FAILURES).toHaveLength(2);
+ for (const record of LISTBOX_KNOWN_FAILURES) {
+ expect(
+ parts.filter(
+ part =>
+ part.binding === record.binding && part.state === record.state,
+ ),
+ ).toHaveLength(1);
+ }
+ });
+});
diff --git a/packages/core/src/Selector/__tests__/Listbox.a11y.known-failures.ts b/packages/core/src/Selector/__tests__/Listbox.a11y.known-failures.ts
new file mode 100644
index 0000000000..861e7a5912
--- /dev/null
+++ b/packages/core/src/Selector/__tests__/Listbox.a11y.known-failures.ts
@@ -0,0 +1,37 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Listbox.a11y.known-failures.ts
+ * @input Uses KnownFailure from @astryxdesign/a11y-spec
+ * @output Exact public-safe Selector and MultiSelector listbox migration failures
+ * @position AST-021 debt records; operational ownership remains outside public source.
+ */
+
+import type {KnownFailure} from '@astryxdesign/a11y-spec';
+
+export const LISTBOX_KNOWN_FAILURES: ReadonlyArray<KnownFailure> = [
+ {
+ expectation: 'listbox.exposure.identity',
+ binding: 'Selector.listbox',
+ state: 'single-sheet:listbox',
+ evidenceLayer: 'accessibility-tree',
+ failureEquals: 'the browser exposes the listbox without an accessible name',
+ standardsReference: 'WCAG 2.2 4.1.2 Name, Role, Value (Level A)',
+ userImpact:
+ 'An accessibility consumer encounters an unnamed listbox in the bottom-sheet presentation and cannot identify what set of choices it contains.',
+ reason:
+ 'The no-search bottom-sheet presentation renders a visible sheet heading without assigning that heading, or another label, as the listbox accessible name. This migration records the existing behavior without changing the component.',
+ },
+ {
+ expectation: 'listbox.exposure.identity',
+ binding: 'MultiSelector.listbox',
+ state: 'multiple-sheet:listbox',
+ evidenceLayer: 'accessibility-tree',
+ failureEquals: 'the browser exposes the listbox without an accessible name',
+ standardsReference: 'WCAG 2.2 4.1.2 Name, Role, Value (Level A)',
+ userImpact:
+ 'An accessibility consumer encounters an unnamed multi-select listbox in the bottom-sheet presentation and cannot identify what set of choices it contains.',
+ reason:
+ 'The no-search bottom-sheet presentation renders a visible sheet heading without assigning that heading, or another label, as the listbox accessible name. This migration records the existing behavior without changing the component.',
+ },
+];
diff --git a/packages/core/src/Selector/__tests__/Listbox.a11y.states.ts b/packages/core/src/Selector/__tests__/Listbox.a11y.states.ts
new file mode 100644
index 0000000000..45e15daf2f
--- /dev/null
+++ b/packages/core/src/Selector/__tests__/Listbox.a11y.states.ts
@@ -0,0 +1,232 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Listbox.a11y.states.ts
+ * @input Uses public Selector option types and the shared Listbox facts
+ * @output A bounded, explicit inventory of existing listbox/group/option states
+ * @position Test-only migration ledger shared by component tests and browser stories.
+ */
+
+import type {ListboxStateFacts} from '@astryxdesign/a11y-spec';
+import type {SelectorOptionType} from '../types';
+
+export interface ListboxScenario {
+ readonly id: string;
+ readonly component: 'Selector' | 'MultiSelector';
+ readonly options: SelectorOptionType[];
+ readonly values: string[];
+ readonly expectedOptions: ReadonlyArray<{
+ value: string;
+ name: string;
+ disabled: boolean;
+ selected?: boolean;
+ group?: string;
+ }>;
+ readonly groups: ReadonlyArray<string>;
+ readonly hasSearch?: boolean;
+ readonly query?: string;
+ readonly presentation?: 'popover' | 'bottom-sheet';
+ readonly customContent?: boolean;
+ readonly hiddenLabel?: boolean;
+ readonly direction?: 'ltr' | 'rtl';
+ readonly isLoading?: boolean;
+ readonly hasSelectAll?: boolean;
+}
+
+const flatOptions: SelectorOptionType[] = [
+ {value: 'apple', label: 'Apple'},
+ {value: 'banana', label: 'Banana'},
+ {value: 'cherry', label: 'Cherry', disabled: true},
+];
+const flatExpected = [
+ {value: 'apple', name: 'Apple', disabled: false},
+ {value: 'banana', name: 'Banana', disabled: false},
+ {value: 'cherry', name: 'Cherry', disabled: true},
+];
+const groupedOptions: SelectorOptionType[] = [
+ {
+ type: 'section',
+ title: 'Citrus',
+ options: [
+ {value: 'orange', label: 'Orange'},
+ {value: 'lemon', label: 'Lemon'},
+ ],
+ },
+ {type: 'divider'},
+ {
+ type: 'section',
+ title: 'Berries',
+ options: [{value: 'blueberry', label: 'Blueberry', disabled: true}],
+ },
+];
+const groupedExpected = [
+ {value: 'orange', name: 'Orange', disabled: false, group: 'Citrus'},
+ {value: 'lemon', name: 'Lemon', disabled: false, group: 'Citrus'},
+ {value: 'blueberry', name: 'Blueberry', disabled: true, group: 'Berries'},
+];
+
+function scenarios(component: ListboxScenario['component']): ListboxScenario[] {
+ const prefix = component === 'Selector' ? 'single' : 'multiple';
+ const base = {
+ component,
+ options: flatOptions,
+ expectedOptions: flatExpected,
+ groups: [],
+ };
+ return [
+ {...base, id: `${prefix}-unset`, values: []},
+ {
+ ...base,
+ id: `${prefix}-selected`,
+ values: component === 'Selector' ? ['apple'] : ['apple', 'banana'],
+ },
+ {...base, id: `${prefix}-disabled-selected`, values: ['cherry']},
+ {
+ ...base,
+ id: `${prefix}-grouped`,
+ options: groupedOptions,
+ values: ['orange'],
+ expectedOptions: groupedExpected,
+ groups: ['Citrus', 'Berries'],
+ },
+ {
+ ...base,
+ id: `${prefix}-filtered`,
+ options: groupedOptions,
+ values: ['orange'],
+ expectedOptions: [
+ {value: 'lemon', name: 'Lemon', disabled: false, group: 'Citrus'},
+ ],
+ groups: ['Citrus'],
+ hasSearch: true,
+ query: 'lem',
+ },
+ {
+ ...base,
+ id: `${prefix}-custom-rtl`,
+ values: ['banana'],
+ customContent: true,
+ hiddenLabel: true,
+ direction: 'rtl',
+ expectedOptions: [
+ {value: 'apple', name: 'Apple details', disabled: false},
+ {value: 'banana', name: 'Banana details', disabled: false},
+ {value: 'cherry', name: 'Cherry details', disabled: true},
+ ],
+ },
+ {
+ ...base,
+ id: `${prefix}-sheet`,
+ values: ['apple'],
+ presentation: 'bottom-sheet',
+ },
+ {
+ ...base,
+ id: `${prefix}-sheet-search`,
+ values: ['banana'],
+ presentation: 'bottom-sheet',
+ hasSearch: true,
+ },
+ {...base, id: `${prefix}-loading`, values: ['apple'], isLoading: true},
+ ];
+}
+
+export const LISTBOX_SCENARIOS: ReadonlyArray<ListboxScenario> = [
+ ...scenarios('Selector'),
+ ...scenarios('MultiSelector'),
+ ...(['none', 'partial', 'all'] as const).map(state => ({
+ id: `multiple-select-all-${state}`,
+ component: 'MultiSelector' as const,
+ options: flatOptions,
+ values:
+ state === 'none'
+ ? []
+ : state === 'partial'
+ ? ['apple']
+ : ['apple', 'banana'],
+ groups: [],
+ hasSelectAll: true,
+ expectedOptions: [
+ {
+ value: 'select-all',
+ name:
+ state === 'partial' ? 'Select all, partially selected' : 'Select all',
+ disabled: false,
+ selected: state === 'all',
+ },
+ ...flatExpected,
+ ],
+ })),
+];
+
+export interface ListboxBindingPart {
+ readonly role: 'listbox' | 'group' | 'option';
+ readonly name?: string;
+ readonly state: string;
+ readonly facts: ListboxStateFacts;
+}
+
+export function listboxParts(
+ scenario: ListboxScenario,
+): ReadonlyArray<ListboxBindingPart> {
+ const multiple = scenario.component === 'MultiSelector';
+ return [
+ {
+ role: 'listbox',
+ state: `${scenario.id}:listbox`,
+ facts: {
+ part: 'listbox',
+ multiple,
+ optionRelations: scenario.expectedOptions.map(
+ option => `option:${option.value}`,
+ ),
+ },
+ },
+ ...scenario.groups.map(name => ({
+ role: 'group' as const,
+ name,
+ state: `${scenario.id}:group:${name}`,
+ facts: {part: 'group' as const, multiple},
+ })),
+ ...scenario.expectedOptions.map(option => ({
+ role: 'option' as const,
+ name: option.name,
+ state: `${scenario.id}:option:${option.value}`,
+ facts: {
+ part: 'option' as const,
+ multiple,
+ selected: option.selected ?? scenario.values.includes(option.value),
+ disabled: option.disabled,
+ ownerGroup: option.group == null ? undefined : `group:${option.group}`,
+ },
+ })),
+ ];
+}
+
+export const LISTBOX_EXCLUSIONS = [
+ {
+ owner: 'Selector/MultiSelector trigger and search input',
+ reason:
+ 'Combobox, field validation, required/read-only/disabled trigger state, and opening/closing are separate contracts. This slice observes active popup parts.',
+ },
+ {
+ owner: 'Selector/MultiSelector existing interaction suites',
+ reason:
+ 'Keyboard selection, selection-follows-focus, disabled-option discovery, Home/End, typeahead, and callback policy are not newly adopted here.',
+ },
+ {
+ owner: 'Selector/MultiSelector empty-state and live-region owners',
+ reason:
+ 'Zero-result representation and announcement timing require their own authority/evidence. No required option is invented for an empty listbox.',
+ },
+ {
+ owner: 'Typeahead, Tokenizer, PowerSearch, ComplexSelector, CommandPalette',
+ reason:
+ 'Later bounded adopters; this first migration is limited to Selector and MultiSelector.',
+ },
+ {
+ owner: 'Component-specific suites',
+ reason:
+ 'Public ID forwarding, callback payloads, forms, value formatting, sorting, required/error status, and styling stay local. Selector has no independent uncontrolled selected-value owner; an omitted value is the unset state.',
+ },
+] as const;
diff --git a/packages/core/src/Selector/__tests__/Selector.listbox.a11y.test.tsx b/packages/core/src/Selector/__tests__/Selector.listbox.a11y.test.tsx
new file mode 100644
index 0000000000..f20cacc82d
--- /dev/null
+++ b/packages/core/src/Selector/__tests__/Selector.listbox.a11y.test.tsx
@@ -0,0 +1,121 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Selector.listbox.a11y.test.tsx
+ * @input Uses Selector, its explicit part/state inventory, and the Listbox contract
+ * @output DOM evidence for real single-select listbox, group, and option parts
+ * @position Component-facing binding; keyboard, callbacks, forms, and styles stay local.
+ */
+
+import {cleanup, render, screen, within} from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import {describe, expect, it} from 'vitest';
+import {
+ expectAccessibilitySpec,
+ LISTBOX_PATTERN,
+} from '@astryxdesign/a11y-spec';
+import {Selector} from '../Selector';
+import {LISTBOX_SCENARIOS, listboxParts} from './Listbox.a11y.states';
+import {installListboxDialogStubs} from './Listbox.a11y.dom';
+
+installListboxDialogStubs();
+
+const scenarios = LISTBOX_SCENARIOS.filter(
+ scenario => scenario.component === 'Selector',
+);
+
+describe('Selector Listbox semantic binding', () => {
+ it.each(scenarios)('$id', async scenario => {
+ for (const part of listboxParts(scenario)) {
+ await expectAccessibilitySpec({
+ spec: LISTBOX_PATTERN,
+ binding: `Selector.${part.role}`,
+ state: part.state,
+ facts: part.facts,
+ render: async () => {
+ render(
+ <div dir={scenario.direction ?? 'ltr'}>
+ <Selector
+ label="Fruit"
+ options={scenario.options}
+ value={scenario.values[0]}
+ onChange={() => {}}
+ hasSearch={scenario.hasSearch}
+ presentation={scenario.presentation}
+ isLoading={scenario.isLoading}
+ isLabelHidden={scenario.hiddenLabel}
+ renderOption={
+ scenario.customContent
+ ? option => <span>{option.label} details</span>
+ : undefined
+ }
+ isDefaultOpen
+ />
+ </div>,
+ );
+ await screen.findByRole('listbox', {hidden: true});
+ if (scenario.query != null) {
+ await userEvent
+ .setup()
+ .type(
+ screen.getByRole('combobox', {hidden: true}),
+ scenario.query,
+ );
+ }
+ },
+ subject: () =>
+ part.role === 'listbox'
+ ? screen.getByRole('listbox', {hidden: true})
+ : part.role === 'group'
+ ? within(
+ screen.getByRole('listbox', {hidden: true}),
+ ).getAllByRole('group', {hidden: true})[
+ scenario.groups.indexOf(part.name ?? '')
+ ]
+ : within(screen.getByRole('listbox', {hidden: true})).getByRole(
+ 'option',
+ {name: part.name, hidden: true},
+ ),
+ related: () => {
+ const listbox = screen.getByRole('listbox', {hidden: true});
+ expect(
+ within(listbox).getAllByRole('option', {hidden: true}),
+ ).toHaveLength(scenario.expectedOptions.length);
+ return {
+ listbox,
+ ...Object.fromEntries(
+ scenario.expectedOptions.map(option => [
+ `option:${option.value}`,
+ within(listbox).getByRole('option', {
+ name: option.name,
+ hidden: true,
+ }),
+ ]),
+ ),
+ ...Object.fromEntries(
+ scenario.groups.map((name, index) => [
+ `group:${name}`,
+ within(listbox).getAllByRole('group', {hidden: true})[index],
+ ]),
+ ),
+ };
+ },
+ cleanup,
+ });
+ }
+ });
+
+ it('keeps the bounded state matrix explicit', () => {
+ expect(scenarios.map(scenario => scenario.id)).toEqual([
+ 'single-unset',
+ 'single-selected',
+ 'single-disabled-selected',
+ 'single-grouped',
+ 'single-filtered',
+ 'single-custom-rtl',
+ 'single-sheet',
+ 'single-sheet-search',
+ 'single-loading',
+ ]);
+ });
+});