The Collapsible component lets you expand or collapse content when needed.
Anatomy
A Collapsible consists of the following parts:
- CollapsibleTrigger: The button that toggles the collapsible.
- CollapsibleContent: The component that contains the collapsible content.
Adding a Collapsible
To add a Collapsible to your page, follow these steps:
- Insert the Collapsible component from the Library.
- Update the default text in the Collapsible to clearly indicate its function.
- Modify the content within the CollapsibleContent as needed.
Guides
Using a Collapsible for Additional Details
Sometimes, you might want to keep an interface clean by hiding extra details until needed. To set up an expandable content section:
- Add and select the Collapsible component.
- Edit the CollapsibleTrigger text to fit your content.
- Add, edit, or remove any text inside the CollapsibleContent as needed.
Creating an Expandable List
If you’re working with a list of items, a Collapsible can help make it more interactive. A common example is a navigation menu with a collapsible section where additional nav items only appear when needed.
To create a collapsible list:
- Select the CollapsibleContent inside the Collapsible component.
- Place your list items (e.g.,
DropdownMenuItem
) inside the CollapsibleContent so they are only visible when expanded.
Animating the Trigger Icon
You can animate the icon inside a CollapsibleTrigger to visually indicate when the section is expanded or collapsed.
To animate the trigger icon:
- Select the trigger icon and go to the Properties Panel.
- In the Classes input, add the
"animated-icon"
class and the"rotate"
subclass.
- Click on the
open
state to view its applied styles.
- Scroll to the Effects section and find the Transform panel.
- Click on Rotate and adjust the Z value (default is
180deg
).
Properties
Collapsible
Property | Type | Default | Description |
defaultOpen | boolean | false | Determines if the content is open when the page loads. |
disabled | boolean | false | If true , prevents the user from interacting with the collapsible and all its items. |
onOpenChange | Action | - | Runs an action whenever the collapsible opens or closes. |
CollapsibleTrigger
Property | Type | Default | Description |
asChild | boolean | - | Changes the default trigger element with its child, while keeping the same properties and behavior. |
CollapsibleContent
Property | Type | Default | Description |
forceMount | boolean | false | Used to force the content to be mounted regardless of its open state. It can be useful when controlling animation with React animation libraries. |