# Accessibility and performance

> WAI-ARIA patterns, screen reader announcements, forced colors, contrast, touch and focus rules, and the performance budgets the dropdowns are gated on.

Canonical: https://salmonui.dev/docs/dropdowns/dropdown-accessibility

## Accessibility

Each component follows one WAI-ARIA Authoring Practices pattern: `Select`
the select-only combobox, `Combobox` the editable combobox with list
autocomplete (a `grid` popup with `columns`), `Listbox` the listbox (the
grid with `layout="grid"`), `Mention` combobox semantics on its field and
`TreeSelect` a combobox with a tree popup.

- Conformance: `npm run test:a11y` runs axe-core over every
  dropdown, closed and open, in light, dark and right-to-left layouts, with
  zero violations, and keeps ARIA snapshots of the open lists.
- Screen readers: virtual options carry `aria-setsize` and
  `aria-posinset` ("12 of 10,000"); a polite live region announces the
  result count after a search and the selection limit of `maxSelected`
  (`localeText.resultCount` and `localeText.limitReached` on `Select` and
  `Combobox`; `resultCount` and `selectionLimit` on `Listbox`).
- Virtual focus: DOM focus stays on the trigger, input or list
  (or the popup search field of `searchable`), and the active option is `aria-activedescendant`. The active option is
  always mounted, even when the list is scrolled away from it.
- High contrast: under `forced-colors: active` selected options
  use `Highlight`, the active option an outline, disabled options
  `GrayText`, and chips and fields keep their borders.
- Color contrast: every color comes from the theme variables
  derived from the five seeds ([Theme](https://salmonui.dev/docs/data-grid/appearance)), whose
  text and boundary contrast is guaranteed; no stylesheet has a literal
  color.
- Touch: options, triggers and chip remove buttons
  are at least 24 × 24 px, nothing appears on hover only, and the popup
  flips and shifts to stay on screen when an on-screen keyboard shortens the
  viewport. `popupMode="sheet"` on `Select` and `TreeSelect` (or `"auto"`
  on phones) opens a full-screen sheet.
- Focus: opening and closing keep focus on the trigger or
  input; after a pointer pick focus returns there; the focused control
  shows the theme focus ring.

The keyboard tables are on each component page:
[Select](https://salmonui.dev/docs/dropdowns/select), [Combobox](https://salmonui.dev/docs/dropdowns/combobox),
[Listbox](https://salmonui.dev/docs/dropdowns/listbox), [Mention](https://salmonui.dev/docs/dropdowns/mention) and
[TreeSelect](https://salmonui.dev/docs/dropdowns/tree-select).

### Live demo: Dropdown accessibility

Live demo: https://salmonui.dev/demos/dropdowns/dropdown-accessibility

A Select, a Combobox with chips and a Listbox with selected, active and disabled options for keyboard, screen reader, forced-colors, touch and server-rendering checks.

`Demo.tsx`:

```tsx
'use client';

import { useState } from 'react';
import { Combobox, type ComboboxValue } from '@salmonui/dropdowns/combobox';
import { Listbox, type ListboxKey } from '@salmonui/dropdowns/listbox';
import { Select, type SelectValue } from '@salmonui/dropdowns/select';

const COLORS = [
  { value: 'red', label: 'Red' },
  { value: 'orange', label: 'Orange' },
  { value: 'yellow', label: 'Yellow', disabled: true },
  { value: 'green', label: 'Green' },
  { value: 'blue', label: 'Blue' },
  { value: 'violet', label: 'Violet' },
];

// One of each dropdown with selected, active and disabled options, for keyboard,
// screen reader, forced-colors and touch checks.
export default function DropdownAccessibilityDemo() {
  const [color, setColor] = useState<SelectValue | null>('green');
  const [colors, setColors] = useState<readonly ComboboxValue[]>(['red', 'blue']);
  const [listed, setListed] = useState<readonly ListboxKey[]>(['orange']);
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', gap: 24, alignItems: 'start' }}>
      <div style={{ display: 'grid', gap: 4, minInlineSize: 200 }}>
        <label htmlFor="dd-a11y-select">Favourite color</label>
        <Select id="dd-a11y-select" data={COLORS} value={color} onValueChange={setColor} clearable />
      </div>
      <div style={{ display: 'grid', gap: 4, minInlineSize: 240 }}>
        <span id="dd-a11y-combobox">Palette</span>
        <Combobox aria-labelledby="dd-a11y-combobox" multiple data={COLORS} value={colors} onValueChange={(next) => setColors(next)} />
      </div>
      <div style={{ display: 'grid', gap: 4, minInlineSize: 200 }}>
        <span id="dd-a11y-listbox">Accent colors</span>
        <Listbox aria-labelledby="dd-a11y-listbox" multiple indicator="checkbox" data={COLORS} value={listed} onValueChange={(next) => setListed(next)} />
      </div>
    </div>
  );
}
```

## Performance

The dropdowns are measured on the production build in Chromium; the
budgets gate the release (`npm run release:verify`).

| Scenario | Budget |
| --- | --- |
| Open a `Select` or `Combobox` over 100,000 local items, click to painted | ≤ 50 ms, options in DOM ≤ visible + 2 × overscan |
| One filter step over 100,000 items with the index built; index build | ≤ 8 ms p95; ≤ 40 ms, after the first paint |
| Scroll the popup or a `Listbox` at 2,000 px/s | handler ≤ 1 ms p95, frame ≤ 16.7 ms p95, 0 blank frames |
| Move the active option | ≤ 2 options re-rendered per key |
| Select all over 100,000 items | ≤ 20 ms; the event's `items` built on first read |

- Remote search: every new search or window aborts the requests
  it supersedes (`AbortSignal`), and a response for an older search never
  replaces a newer one.
- Server rendering: the server renders the trigger, the value
  and the hidden form element (and a `Listbox` list), never a popup, and
  its work does not grow with `data` beyond the value label lookup. The
  Vite SSR and Next App Router examples hydrate every dropdown without a
  warning.
- Bundle size: each component is its own subpath with its own
  gzip budget (`@salmonui/dropdowns/select`, `/combobox`, `/listbox`,
  `/mention`, `/tree-select`); popups, search, remote reads, drag and drop
  and the grid keyboard are lazy chunks.
- Closed dropdowns: a closed dropdown adds no document or
  window listeners, observers or intervals; they are attached when a popup
  opens and removed when it closes.

### Live demo: Dropdowns over 100,000 items

Live demo: https://salmonui.dev/demos/dropdowns/dropdown-large-lists

Select, Combobox, Select multiple with select all and the Combobox columns popup over 100,000 local items, plus twenty closed Selects sharing the same data.

`Demo.tsx`:

```tsx
'use client';

import { useState } from 'react';
import { Combobox, type ComboboxColumn, type ComboboxValue } from '@salmonui/dropdowns/combobox';
import { Select, type SelectValue } from '@salmonui/dropdowns/select';

interface Part {
  readonly value: number;
  readonly label: string;
  readonly bin: string;
  readonly qty: number;
}

const PREFIXES = ['Axle', 'Bolt', 'Cable', 'Diode', 'Fuse', 'Gear', 'Hinge', 'Lens', 'Motor', 'Nut', 'Pulley', 'Relay', 'Spring', 'Valve', 'Washer'];
// 100,000 parts, built once at module scope and shared by every dropdown below.
const PARTS: Part[] = Array.from({ length: 100_000 }, (_, i) => ({
  value: i + 1,
  label: `${PREFIXES[i % PREFIXES.length]} ${String(i + 1).padStart(6, '0')}`,
  bin: `Bin ${String.fromCharCode(65 + (i % 26))}-${(i % 97) + 1}`,
  qty: (i * 7) % 500,
}));

const COLUMNS: ComboboxColumn<Part>[] = [
  { field: 'value', header: 'No.', width: 80, align: 'end' },
  { field: 'label', header: 'Part' },
  { field: 'bin', header: 'Bin', width: 90 },
  { field: 'qty', header: 'Qty', width: 70, align: 'end' },
  { field: 'value', header: 'Ref', width: 70, align: 'end', sortable: false, format: (value) => `R${String(value)}` },
];

const CLOSED = Array.from({ length: 20 }, (_, i) => i);

export default function DropdownLargeListsDemo() {
  const [part, setPart] = useState<SelectValue | null>(null);
  const [many, setMany] = useState<readonly SelectValue[]>([]);
  const [row, setRow] = useState<ComboboxValue | null>(null);
  return (
    <div style={{ display: 'grid', gap: 16, maxWidth: 600 }}>
      <div style={{ display: 'grid', gap: 4, maxWidth: 280 }}>
        <span id="dd-large-select">Part (Select, 100,000 options)</span>
        <Select aria-labelledby="dd-large-select" data={PARTS} value={part} onValueChange={setPart} searchable searchOperator="contains" placeholder="Open, scroll or search" />
      </div>
      <div style={{ display: 'grid', gap: 4, maxWidth: 280 }}>
        <span id="dd-large-combobox">Part (Combobox, type to filter 100,000)</span>
        <Combobox aria-labelledby="dd-large-combobox" data={PARTS} searchOperator="contains" placeholder="Type a part number, such as 4242" />
      </div>
      <div style={{ display: 'grid', gap: 4, maxWidth: 280 }}>
        <span id="dd-large-multiple">Parts to reorder (select all 100,000)</span>
        <Select aria-labelledby="dd-large-multiple" multiple indicator="checkbox" showSelectAll data={PARTS} value={many} onValueChange={(next) => setMany(next)} valueDisplay="count" />
        <output>{many.length.toLocaleString('en-US')} selected</output>
      </div>
      <div style={{ display: 'grid', gap: 4 }}>
        <span id="dd-large-columns">Part (Combobox columns, 100,000 rows, 5 columns)</span>
        <Combobox<Part> aria-labelledby="dd-large-columns" data={PARTS} columns={COLUMNS} searchFields={['label', 'bin']} searchOperator="contains" value={row} onValueChange={(next) => setRow(next)} />
      </div>
      <details>
        <summary>Twenty closed Selects over the same 100,000 items</summary>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(160px, 1fr))', gap: 8, marginBlockStart: 8 }}>
          {CLOSED.map((i) => (
            <Select key={i} aria-label={`Spare part ${i + 1}`} data={PARTS} defaultValue={(i + 1) * 4_999} />
          ))}
        </div>
      </details>
    </div>
  );
}
```
