Accordion
Coordinate one or several expandable sections with shared disclosure rules.
Anatomy#
Usage#
Use Accordion for several related disclosures that share one open-item policy. For a single independent disclosure, use Collapsible.
Content#
content accepts text, JSX, or a component that receives { value, expanded, disabled }. Use the
component form when the panel depends on the item state. Content mounts while its item is open (see
Content lifetime).
headingLevel (default 3) sets the heading level that wraps each trigger. icon adds a leading
icon to an item, and expandIcon replaces the indicator icon for every item.
Open items#
value, defaultValue, and onValueChange always use an array of item values. By default, opening
an item closes the others; collapsible (default true) controls whether the open item can close.
Set multiple to allow several open items, where every item can always close.
Pair value with onValueChange when the page owns the open set. onValueChange receives the
complete next array and fires only for user toggles, not for programmatic changes to value.
Content lifetime#
The content shell stays mounted so each trigger’s aria-controls points to a real element.
forceMount controls only the content inside that shell.
By default, content mounts each time its item opens and unmounts after it closes. Set forceMount
to mount content before the first open and keep it mounted so hidden fields preserve local state.
Keyboard interaction#
| Key | Description |
|---|---|
| ↵ / Space | Toggles the focused trigger when enabled. |
| ↓ | Moves focus to the next enabled trigger. |
| ↑ | Moves focus to the previous enabled trigger. |
| ↖ | Moves focus to the first enabled trigger. |
| ↘ | Moves focus to the last enabled trigger. |
Arrow-key focus wraps from the last trigger to the first by default. Set loop={false} to stop at
either end. Disabled items are skipped.
Examples#
Single#
Keep one section open at a time. defaultValue opens the first answer without owning state.
Multiple#
Set multiple to allow several sections to stay open at once.
Disabled and custom content#
Set disabled on individual items to prevent toggling. Pass JSX in content for rich layouts such as lists or callouts.
Keep mounted#
Set forceMount to keep panel content mounted and preserve local state while closed.
Controlled#
Pair value with onValueChange to control the open items externally. The value is always an array of item values, even in single mode.
API Reference#
Attributes#
data-disableddata-closeddata-expandedProps#
Props for the Accordion component. Renders a <div> element by default.