<!-- index: /slotted/llms.txt -->
# accordion

`data-ui="accordion"` · Stacked sections that expand and collapse.

## Import

```tsx
import { Accordion, AccordionDefaultsProvider, Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleTrigger } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Accordion } from '@slotted/react/accordion';
import {
  Collapsible,
  CollapsibleHeader,
  CollapsiblePanel,
  CollapsibleTrigger,
} from '@slotted/react/collapsible';

const SECTIONS = [
  {
    value: 'delivery',
    title: 'Delivery',
    body: 'Scheduled for September 12 with Harbor Freight, tracking HF-48213.',
  },
  { value: 'payment', title: 'Payment', body: 'Invoice INV-20877 for $2,146.50, due October 4.' },
  {
    value: 'returns',
    title: 'Returns',
    body: 'Accepted within 30 days of delivery, with the original packing slip.',
  },
];

export default function AccordionBasic() {
  return (
    <Accordion defaultValue={['delivery']}>
      {SECTIONS.map((section) => (
        <Collapsible key={section.value} value={section.value}>
          <CollapsibleHeader>
            <CollapsibleTrigger>{section.title}</CollapsibleTrigger>
          </CollapsibleHeader>
          <CollapsiblePanel>{section.body}</CollapsiblePanel>
        </Collapsible>
      ))}
    </Accordion>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, or the element render returns | yes |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `value` | `readonly string[]` | — | Accordion | Present means the consumer owns the set of open panels, for the life of the component. Each entry is a Collapsible’s value. |
| `defaultValue` | `readonly string[]` | — | Accordion | The set an uncontrolled accordion starts from, read once. A later change to it does not silently become new state. |
| `multiple` | `boolean` | false | Accordion, AccordionDefaultsProvider | Whether more than one panel may be open. With it off, opening one closes the one that was, and that panel is told the reason was select. |
| `requireOpen` | `boolean` | false | Accordion, AccordionDefaultsProvider | Whether the set refuses to empty. The one open header then carries aria-disabled="true", which is what the pattern asks of an accordion that does not permit its panel to be collapsed. |
| `loop` | `boolean` | true | Accordion, AccordionDefaultsProvider | Whether the arrow keys wrap past the ends of the set. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Accordion, AccordionDefaultsProvider | The step every item sits at, and the air between cards under separated. |
| `variant` | `'plain' \| 'ruled' \| 'framed' \| 'separated'` | ruled | Accordion, AccordionDefaultsProvider | How the set is drawn. Each value maps onto the item variant the set hands over: plain to plain, ruled and framed to ruled, separated to framed. The set never selects into an item to draw it. |
| `indicator` | `'chevron' \| 'plus-minus' \| 'none'` | chevron | Accordion, AccordionDefaultsProvider | The mark every header carries, handed to each item. |
| `togglePlacement` | `'end' \| 'start'` | end | Accordion, AccordionDefaultsProvider | Which side of the words that mark stands on, handed to each item. |
| `headingLevel` | `'none' \| '1' \| '2' \| '3' \| '4' \| '5' \| '6'` | 3 | Accordion, AccordionDefaultsProvider | The heading element every item’s header renders as. 3 is the level the pattern’s own example uses for a set inside a section. |
| `mount` | `'active' \| 'lazy' \| 'eager' \| 'until-found'` | eager | Accordion, AccordionDefaultsProvider | When each panel’s content exists, handed to every item. |
| `truncate` | `boolean` | false | Accordion, AccordionDefaultsProvider | Clips every title to one line instead of letting the row grow. |
| `disabled` | `boolean` | false | Accordion | Reaches every item, and every trigger as the native attribute. |
| `handle` | `Ref<AccordionHandle>` | — | Accordion | openAll() and closeAll(), the two moves an array cannot express while the family owns the array. They are on a handle of their own so ref keeps reaching the element, which is the rule for every other family here. |
| `render` | `(props) => ReactNode` | — | Accordion | Substitutes the set’s root and hands it every attribute — a set of sections can be a real section element. |
| `ref` | `Ref<HTMLElement>` | — | Accordion | Reaches the element itself, so the platform’s own methods are the platform’s. |
| `useAccordion()` | `() => AccordionContextValue \| undefined` | — | inside Accordion | What each item reads: the axes the set hands over, whether a value is open, whether it is held open, and toggle(value, reason). It is undefined outside a set rather than a throw, because a Collapsible standing alone is a complete component. |
| `AccordionDefaultsProvider` | `{ multiple, requireOpen, loop, size, variant, indicator, togglePlacement, headingLevel, mount, truncate }` | — | a subtree | The ten decisions an application takes once. A set that states any of them itself still wins. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onValueChange` | `(value: readonly string[], request: ChangeRequest<readonly string[]>)` | Before the set of open panels moves. The request carries the new set, the set it replaces, the reason (pointer, keyboard, select or programmatic), the originating event, and cancel(), which refuses the move before anything commits. Two sets holding the same values in any order are the same set, so no request is emitted for a move that changes nothing. |
| `onOpenChange, on each item` | `(open: boolean, request: ChangeRequest<boolean>)` | Before that one panel moves, and before the set is asked. It is what lets a consumer watch one section without unpacking the array, and cancelling it stops the set from being asked at all. |
| `onFocusIn, onKeyDown, on the set` | `the element’s own events` | Whenever the set fires them. Which header has focus is read from event.target.dataset.value, which is why the family ships no separate focus-change output. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `sm`, `md`, `lg` | `md` |
| `variant` | `plain`, `ruled`, `framed`, `separated` | `ruled` |
| `indicator` | `chevron`, `plus-minus`, `none` | `chevron` |
| `togglePlacement` | `end`, `start` | `end` |
| `headingLevel` | `none`, `1`, `2`, `3`, `4`, `5`, `6` | `3` |
| `mount` | `active`, `lazy`, `eager`, `until-found` | `eager` |

## Rules

- The pattern is the WAI-ARIA APG’s Accordion (w3.org/WAI/ARIA/apg/patterns/accordion/). Its keyboard table is four keys and all four are the platform’s: Enter and Space toggle the focused header because it is a button, and Tab and Shift + Tab move through the set because every focusable element in an accordion is in the page tab sequence. Nothing here writes tabindex.
- ArrowDown, ArrowUp, Home and End are a deliberate departure, and the cost is written down. The arrows were optional guidance until w3c/aria-practices#3434 removed them, and Base UI deprecated its own loopFocus and orientation in the same change; Radix and Ark still ship them and readers have learned them. Here they are additive — they move focus between headers, open nothing, and take no header out of the tab sequence — so a reader who does not know them loses nothing.
- Each header is a real heading at the level headingLevel names, and the trigger is its only element, which is what the pattern requires. The set itself carries no role: a group of headings is already an outline a reader can navigate, and a container announced around it is one more thing to move past.
- requireOpen writes aria-disabled="true" on the one header the set will not let close. The pattern asks for exactly that, and the APG’s own example is the only surveyed implementation that ships it; the header stays focusable and announced rather than leaving the reader’s path.
- A horizontal accordion is not shipped. Radix and Ark both offer one and Base UI has deprecated its own; a horizontally stacked set of sections of which one is open is a tab list, and tabs owns it — with the marker, the scrolling list and that pattern’s own keyboard model.
- Which header has focus is read from the platform: onFocusIn on the set and event.target.dataset.value. Ark ships an output for it, and an output that repeats what the DOM already says is one more thing to keep in step.

## Tokens

`--slotted-accordion-border-color`, `--slotted-accordion-gap`, `--slotted-accordion-radius`, `--slotted-accordion-rule-color`, `--slotted-accordion-shadow`, `--slotted-accordion-surface`, `--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-disabled-foreground`, `--slotted-radius-md`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-surface-raised`

## Examples

See [accordion.examples.md](./accordion.examples.md).
