A vertically stacked set of interactive headings that each reveal a section of content.
Loading...
Installation
Install the following dependencies:
Copy and paste the following code into your project.
Loading...
Update the import paths to match your project setup.
Composition
Accordion └── AccordionItem ├── AccordionTrigger │ └── AccordionItemIndicator (optional) └── AccordionContent
Examples
Card
Loading...
Controlled
Loading...
Default
Loading...
Separated Items
Loading...
With Form Fields
Loading...
With Icons
Loading...
API Reference
Accordion
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | generated | Unique identifier used to create the accordion part IDs. |
ids | ElementIds | — | Overrides the generated IDs for individual parts. |
value | string[] | — | Expanded item values when the accordion is controlled. |
defaultValue | string[] | [] | Initially expanded item values. |
multiple | boolean | false | Allows more than one item to be expanded. |
collapsible | boolean | false | Allows every item to be collapsed. |
disabled | boolean | false | Disables interaction with every item. |
orientation | "horizontal" | "vertical" | "vertical" | Sets the accordion's orientation and keyboard navigation. |
onValueChange | (details: { value: string[] }) => void | — | Runs when the expanded values change. |
onFocusChange | (details: { value: string | null }) => void | — | Runs when the focused item changes. |
lazyMount | boolean | false | Mounts item content only after it is first expanded. |
unmountOnExit | boolean | false | Unmounts item content when it is collapsed. |
AccordionItem
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Required unique value that identifies the item. |
disabled | boolean | false | Prevents the item from being expanded. |
Context and Hooks
| Export | API |
|---|---|
useAccordion(props) | Creates an accordion API from the state and behavior options above. |
AccordionRootProvider | Accepts that API through value and renders the root. |
useAccordionContext() | Returns the nearest accordion API. |
useAccordionItemContext() | Returns { expanded, focused, disabled } for the item. |
AccordionContext | Render-prop component that exposes the accordion API. |
AccordionItemContext | Render-prop component that exposes the current item state. |
AccordionValueChangeDetails | Type for the object passed to onValueChange. |
Angular
React
Solid
Svelte
Vue