Overview
Collapsible is an interactive component that can be expanded and collapsed to show or hide content.Features
- Full keyboard navigation
- Can be controlled or uncontrolled
- Supports CSS animations and transitions
Installation
Anatomy
API Reference
Root
Contains all the parts of a collapsible.The open state of the collapsible when it is initially rendered. Use when you do not need to control its open state.
The controlled open state of the collapsible. Must be used in conjunction with
onOpenChange.Event handler called when the open state of the collapsible changes.
When
true, prevents the user from interacting with the collapsible.Trigger
The button that toggles the collapsible.Content
The component that contains the collapsible content.Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
Examples
Basic Usage
Uncontrolled
Data Attributes
Root
data-state-"open"or"closed"data-disabled- Present when disabled
Trigger
data-state-"open"or"closed"data-disabled- Present when disabled
Content
data-state-"open"or"closed"data-disabled- Present when disabled
CSS Variables
Content
--radix-collapsible-content-height- The height of the content when open--radix-collapsible-content-width- The width of the content when open
These CSS variables can be used to animate the height and width of the content.
Keyboard Interactions
Space- Opens/closes the collapsibleEnter- Opens/closes the collapsible