Collapsible
A section of content that users show and hide with a trigger.
A collapsible keeps a section of content closed until users open it with the trigger, and a second press closes it again. The page stays short, and users read the details in place when they need them. The parts have no styles of their own, so the examples render the trigger as a Button.
Transfer #4821
Usage
Examples
Open by Default
Some details matter as soon as a page opens. The collapsible then starts open through defaultOpen, and users close it once the details have served their purpose.
Transfer #4821
Destination
Basel
Cases
12
Controlled
Sometimes the application decides whether the details are visible. Through open and onOpenChange it holds that state, so other parts of the interface can open or close the collapsible as well, for example a link that leads users straight to the details.
Transfer #4821
API Reference
Collapsible
| Prop | open |
|---|---|
| Type | boolean |
| Default | – |
| Description | Sets whether the collapsible is open and makes it controlled. Update it in onOpenChange. |
| Prop | defaultOpen |
|---|---|
| Type | boolean |
| Default | false |
| Description | Opens the collapsible at first render. The collapsible then tracks its open state itself. |
| Prop | onOpenChange |
|---|---|
| Type | (open: boolean, eventDetails: CollapsibleRootChangeEventDetails) => void |
| Default | – |
| Description | Runs when users open or close the collapsible. It receives the open state that follows. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from opening or closing the collapsible. The trigger stays focusable. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the collapsible with another component. |
CollapsibleTrigger
| 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 | – |
| Description | Prevents users from opening or closing the collapsible with this trigger. Without it, the trigger uses the value set on the collapsible. |
CollapsibleContent
| Prop | hiddenUntilFound |
|---|---|
| Type | boolean |
| Default | false |
| Description | Lets the browser's page search find text in the closed content and open the collapsible. The closed content then stays in the DOM, and keepMounted has no effect. |
| Prop | keepMounted |
|---|---|
| Type | boolean |
| Default | false |
| Description | Keeps the content in the DOM while the collapsible is closed. It has no effect when hiddenUntilFound is set. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the content with another component. |