# Aria Patterns Applies to files matching `**/*.{html,jsx,tsx,vue,svelte,astro}`. Part of the `kb-path-instructions` skill. ## Dependencies - `web-accessibility-baseline.md` (same folder) - WCAG AA baseline rules this file extends - `semantic-html.md` (same folder) - native HTML alternatives to prefer before reaching for ARIA roles When generating custom interactive widgets, apply these role-specific ARIA patterns. Each pattern defines the required markup structure, required attributes, and mandatory keyboard behavior. These patterns follow the WAI-ARIA Authoring Practices Guide (APG). > **Impact:** Using an ARIA role without its required keyboard pattern creates a widget that is completely unusable by keyboard-only users and confusing to screen reader users who expect specific key behaviors based on the announced role. **Golden rule:** Only use `role="menu"` / `role="tab"` / `role="tree"` / etc. when you also implement the full keyboard interaction pattern for that role. Partial ARIA is worse than no ARIA. ## Required Keyboard Behavior by Role Every role below requires the listed keys to be fully implemented before using that role. Missing any required key makes the pattern non-conformant. | Role | Required Keys | Navigation Pattern | |------|--------------|--------------------| | `tab` / `tablist` | Arrow Left/Right, Home, End; Tab exits into panel | Roving tabindex | | `dialog` | Tab/Shift+Tab (trapped inside), Escape | No - use `tabindex="-1"` on container, manage focus explicitly | | `combobox` | Down/Up Arrow, Enter (select), Escape (close), Tab (accept + move) | `aria-activedescendant` | | `menu` / `menuitem` | Down/Up Arrow, Home, End, Escape, Tab (closes menu) | Roving tabindex | | `tree` / `treeitem` | Down/Up Arrow, Right (expand), Left (collapse), Home, End | Roving tabindex | | `listbox` / `option` | Down/Up Arrow, Home, End, Enter/Space (select) | Roving tabindex | | `grid` / `gridcell` | All four Arrow keys, Home/End (Page Up/Down optional) | Roving tabindex or `aria-activedescendant` | > **Roving tabindex:** Only one item in a composite widget has `tabindex="0"` at any time; all others have `tabindex="-1"`. When focus moves via arrow keys, set the new item to `tabindex="0"` and the previous to `tabindex="-1"`. Tab enters and exits the whole widget as one focus stop; arrow keys navigate internally. See [APG Roving tabindex](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex). --- ## Tabs ```html
...
``` **Required attributes:** `aria-selected` on every tab (true/false), `aria-controls` -> panel `id`, `aria-labelledby` on panels. **Keyboard - roving tabindex pattern:** - Only the selected tab has `tabindex="0"`. All others have `tabindex="-1"`. - `Arrow Left` / `Arrow Right` - move focus between tabs; update `aria-selected`. - `Home` - move focus to first tab. - `End` - move focus to last tab. - Tab key - moves focus into the active panel (not to the next tab). --- ## Dialog (Modal) ```html

Confirm deletion

This action permanently removes the item and cannot be undone.

``` Use `dialog.showModal()` when using the native element - the browser makes the rest of the page inert, handles Escape and the backdrop, and exposes the dialog as modal, so `aria-modal` is not needed. `aria-describedby` belongs on the dialog itself, not on a wrapper `div`. > **Note:** The native `` element already has an implicit `dialog` role. Do **not** add `role="dialog"` to a `` element - it is redundant and may confuse some assistive technology. Only add `role="dialog"` when using a non-native element (e.g., `
`). For the ARIA pattern (non-native `
`-based dialog): ```html

Confirm deletion

This action cannot be undone.

``` **Required attributes:** `aria-modal="true"`, `aria-labelledby` pointing to the heading `id`. **Required behavior:** - On open: move focus to the first focusable element (or the dialog container if `tabindex="-1"`). - While open: Tab and Shift+Tab cycle focus only within the dialog. Focus must not leave. - `Escape`: closes the dialog. - On close: return focus to the element that triggered the dialog. --- ## Combobox / Autocomplete ```html
  • San Francisco
  • San Diego
``` **Required attributes:** `aria-expanded` (true when list is open), `aria-controls` -> listbox `id`, `aria-activedescendant` -> focused option `id` (remove the attribute when no option is focused). **Keyboard:** - `Down Arrow` - opens list, moves focus to first option (set `aria-activedescendant`). - `Up/Down Arrow` - moves between options. - `Enter` - selects the highlighted option, closes list. - `Escape` - closes list, clears `aria-activedescendant`, returns focus to input. - `Tab` - accepts current value, closes list, moves focus to next element. --- ## Accordion ```html

...

``` **Required attributes:** `aria-expanded` (true/false) on each trigger button, `aria-controls` -> panel `id`, `role="region"` on panel, heading wrapping each trigger. **Note:** `role="region"` creates a landmark. For accordions with many panels (>6), omit `role="region"` to avoid polluting the landmark list. **Keyboard:** `Enter`/`Space` toggles the focused panel. Standard Tab navigation between triggers. No required arrow key behavior (unlike tabs). --- ## Menu Button Use `role="menu"` only for application-style action menus (Edit / Delete / Rename), not for site navigation. ```html ``` **Required attributes:** `aria-haspopup="menu"` on trigger, `aria-expanded` (true/false), `role="menu"` on container, `role="menuitem"` on items, `role="none"` on list items (removes list semantics that would conflict with menu role). **Keyboard:** - `Enter`/`Space`/`Down Arrow` - opens menu, moves focus to first item. - `Up/Down Arrow` - moves between items (roving tabindex). - `Home`/`End` - jump to first/last item. - `Escape` - closes menu, returns focus to trigger button. - Tab - closes menu (focus leaves the menu). --- ## Carousel / Live Region Slider ```html

Product name

...

``` **Required:** `aria-roledescription="carousel"` on container, `role="group" aria-roledescription="slide"` on each slide, `aria-label="Slide N of M"` on each slide, live region announcing current slide (`aria-live="off"` during automatic rotation so it does not interrupt, `polite` otherwise), pause control for auto-advancing carousels. **Auto-advancing carousels must:** - Provide a visible pause/stop control. - Pause automatically when keyboard focus enters the carousel. - Respect `prefers-reduced-motion` (stop all auto-advancement, keep manual controls). --- ## Tree View ```html
  • src
    • App.tsx
``` **Required attributes:** `aria-expanded` on items with children (true = open, false = closed), `role="group"` wrapping child lists, `aria-selected` on all items (for single-select trees). **Keyboard:** - `Down/Up Arrow` - moves focus between visible items. - `Right Arrow` - on collapsed item: expands it. On expanded item: moves to first child. - `Left Arrow` - on expanded item: collapses it. On collapsed item or leaf: moves to parent. - `Home`/`End` - first/last visible item. - Enter or `Space` - activates/selects the focused item. --- ## Switch / Toggle ```html ``` Or as a styled checkbox (semantically equivalent): ```html ``` **Required attributes:** on the `button` version, `aria-checked` (true/false), updated on click. The `input type="checkbox" role="switch"` version takes its state from `checked`; do not add `aria-checked`. **Keyboard:** `Space` toggles the switch state. --- ## Tooltip ```html ``` **Tooltip vs. description:** A tooltip supplements an already-named element with additional context. The button above has an accessible name ("Copy" from the visually hidden span) and the tooltip adds clarification. Do not use a tooltip as the sole accessible name. **Required behavior:** - Appears on focus and on hover. - Remains visible while focused (does not auto-dismiss). - Dismissible with `Escape`. - `role="tooltip"` on the tooltip container, `aria-describedby` on the trigger pointing to it. --- ## Spinbutton / Number Input with Custom Controls ```html
Quantity
``` **Note:** The native `` handles `role="spinbutton"`, `aria-valuemin`, `aria-valuemax`, and `aria-valuenow` automatically. The increment/decrement buttons are supplements - keep Tab focus on the input itself. ## Redundant ARIA Attributes ### `aria-required` vs native `required` In modern assistive technology (JAWS 18+, NVDA 2020.1+, VoiceOver iOS 14+), `aria-required="true"` on a native ``, `