Accordion
Stacked sections that expand and collapse; one open at a time unless multiple. Panel height animates via CSS.
WAI-ARIA patternInstallation
npx nuecrea-ui add accordionUsage
import * as Accordion from '@/components/ui/accordion';
const items = [
{
value: 'shipping',
title: 'How long does shipping take?',
body: 'Orders ship within 2 business days.',
},
{ value: 'returns', title: 'Can I return an item?', body: 'Yes, within 30 days of delivery.' },
{ value: 'gift', title: 'Do you offer gift wrapping?', body: 'Not yet.', disabled: true },
{ value: 'support', title: 'How do I contact support?', body: 'Email help@example.com.' },
];
export default function AccordionStory() {
return (
<main className="grid max-w-md gap-8">
<Accordion.Root defaultValue={['shipping']}>
{items.map((item) => (
<Accordion.Item
key={item.value}
value={item.value}
disabled={item.disabled}
>
<Accordion.Header>
<Accordion.Trigger>{item.title}</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel>{item.body}</Accordion.Panel>
</Accordion.Item>
))}
</Accordion.Root>
<Accordion.Root multiple disabled defaultValue={['locked']}>
<Accordion.Item value="locked">
<Accordion.Header>
<Accordion.Trigger>Locked section</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel>Hidden content.</Accordion.Panel>
</Accordion.Item>
</Accordion.Root>
</main>
);
}API reference
Accordion.Root
Groups items; owns which are open. Renders <div>.
| Prop | Type | Default | Description |
|---|---|---|---|
value | unknown[] | — | Controlled open item values. |
defaultValue | unknown[] | — | Initially open item values. |
multiple | boolean | false | Allow several open items. |
disabled | boolean | false | Disable every item. |
keepMounted | boolean | false | Keep closed panels in the DOM (hidden). |
| Event | Payload | Description |
|---|---|---|
onValueChange | unknown[] | Fired when items open or close. Angular: the `value` model's change event. |
| Data attribute | Present when |
|---|---|
data-orientation | always: vertical |
data-disabled | the accordion is disabled |
Accordion.Item
One section. Renders <div>.
| Prop | Type | Default | Description |
|---|---|---|---|
value | unknown | — | Identifies the item. Generated when unset. |
disabled | boolean | false | Cannot be toggled. |
| Event | Payload | Description |
|---|---|---|
onOpenChange | boolean | Fired when this item opens or closes. |
| Data attribute | Present when |
|---|---|
data-orientation | always: vertical |
data-open | the item is open |
data-closed | the item is closed |
data-hidden | the item's panel is hidden |
data-disabled | the item (or whole accordion) is disabled |
data-index | always: the item's index |
Accordion.Header
Heading wrapping the trigger. Renders <h3>.
| Data attribute | Present when |
|---|---|
data-orientation | always: vertical |
data-open | the item is open |
data-closed | the item is closed |
data-hidden | the item's panel is hidden |
data-disabled | the item (or whole accordion) is disabled |
data-index | always: the item's index |
Accordion.Trigger
Toggles the panel. A plain button in the tab order; the styled version appends a chevron. Renders <button>.
| Data attribute | Present when |
|---|---|
data-orientation | always: vertical |
data-panel-open | the panel is open |
data-hidden | the item's panel is hidden |
data-disabled | the item (or whole accordion) is disabled |
data-index | always: the item's index |
Accordion.Panel
The section content (role=region). Hidden when closed (unmounted in React). Renders <div> with role region.
| Prop | Type | Default | Description |
|---|---|---|---|
keepMounted | boolean | false | Keep in the DOM while closed. |
| Data attribute | Present when |
|---|---|
data-orientation | always: vertical |
data-open | the item is open |
data-closed | animating closed |
data-disabled | the item (or whole accordion) is disabled |
data-index | always: the item's index |
data-starting-style | animating open |
data-ending-style | animating closed |
| CSS variable | Description |
|---|---|
--accordion-panel-height | Content height in px while animating, auto when open. |
--accordion-panel-width | Content width in px while animating, auto when open. |
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Toggle the focused item's panel. |
| Tab | Move between triggers (no arrow-key navigation, as in Base UI). |