Accordion
A stack of sections that lets users show and hide content.
An accordion stacks sections of content and keeps each one closed until users open it. Each trigger names its section, so users can scan the stack and read only the content they need.
Usage
Examples
Open by Default
One section often holds what most users come for, such as the status of an open order. Listed in defaultValue, that section is already open when the accordion appears, and users remain free to close it or to open another.
Controlled
Other parts of an interface sometimes decide which section is open, for example a warning that points to the section explaining its cause. Through value and onValueChange, the application keeps track of the open sections and can open the right one, so users arrive directly at the explanation they need.
Multiple
When users compare two sections, such as the terms of two suppliers, they need both open at once. By default, opening a section closes the one that was open. Once multiple is set, several sections stay open together, so users keep both in view.
With Frame
Next to tables and charts, an accordion can blend into the content around it. Wrapped in AccordionFrame, its sections form one self-contained unit, so users see at once which content belongs to the group.
Disabled
While the figures inside an accordion are being recalculated, its sections should stay as they are. Through disabled, the accordion holds every section in its current state, so users can neither open nor close one before the figures are complete.
Disabled Item
Sometimes only one section is unavailable, for instance because users lack the permission for its content. That item alone then carries disabled, so users cannot open or close it, yet they still see that it exists while every other section works as before.
API Reference
Accordion
| Prop | value |
|---|---|
| Type | any[] |
| Default | – |
| Description | Sets the values of the open items and makes the accordion controlled. Update it in onValueChange. |
| Prop | defaultValue |
|---|---|
| Type | any[] |
| Default | – |
| Description | Sets the values of the items that are open at first render. The accordion then tracks the open items itself. |
| Prop | onValueChange |
|---|---|
| Type | (value: any[], eventDetails: AccordionRootChangeEventDetails) => void |
| Default | – |
| Description | Runs when users open or close an item. It receives the values of the items that are open afterwards. |
| Prop | multiple |
|---|---|
| Type | boolean |
| Default | false |
| Description | Lets users keep several items open at the same time. Without it, opening an item closes the open one. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from opening or closing any item. |
| Prop | hiddenUntilFound |
|---|---|
| Type | boolean |
| Default | false |
| Description | Lets the browser's page search find text in closed items and open them. The content of closed items then stays in the DOM, and keepMounted has no effect. |
| Prop | keepMounted |
|---|---|
| Type | boolean |
| Default | false |
| Description | Keeps the content of closed items in the DOM. It has no effect when hiddenUntilFound is set. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the accordion with another component. |
AccordionItem
| Prop | value |
|---|---|
| Type | any |
| Default | – |
| Description | Identifies the item in value and defaultValue of the accordion. Without it, the item gets a generated ID. |
| Prop | onOpenChange |
|---|---|
| Type | (open: boolean, eventDetails: AccordionItemChangeEventDetails) => void |
| Default | – |
| Description | Runs when users open or close the item. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from opening or closing the item. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the item with another component. |
AccordionTrigger
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the trigger with another component. |
| Prop | nativeButton |
|---|---|
| Type | boolean |
| Default | true |
| Description | Declares whether the rendered element is a native button. Set it to false when render returns a different element. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from opening or closing the item with this trigger. A disabled item or accordion disables the trigger as well. |
AccordionContent
| Prop | hiddenUntilFound |
|---|---|
| Type | boolean |
| Default | – |
| Description | Lets the browser's page search find text in this content while its item is closed, and open the item. Without it, the content uses the value set on the accordion. |
| Prop | keepMounted |
|---|---|
| Type | boolean |
| Default | – |
| Description | Keeps this content in the DOM while its item is closed. Without it, the content uses the value set on the accordion. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the content with another component. |