Collapsible
An interactive component which expands and collapses a panel.
Order #4189
StatusShipped
Installation
pnpm dlx cubix@latest add collapsible --base ariaUsage
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/cubix/collapsible"<Collapsible>
<CollapsibleTrigger>Can I use this in my project?</CollapsibleTrigger>
<CollapsibleContent>
Yes. Free to use for personal and commercial projects. No attribution
required.
</CollapsibleContent>
</Collapsible>Composition
Use the following composition to build a Collapsible:
Collapsible
├── CollapsibleTrigger
└── CollapsibleContentControlled State
Use the open and onOpenChange props to control the state.
import * as React from "react"
export function Example() {
const [open, setOpen] = React.useState(false)
return (
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger>Toggle</CollapsibleTrigger>
<CollapsibleContent>Content</CollapsibleContent>
</Collapsible>
)
}Examples
Basic
Settings Panel
Use a trigger button to reveal additional settings.
File Tree
Use nested collapsibles to build a file tree.
API Reference
Note: See the Base UI or Radix UI Collapsible docs for the full primitive API.
Collapsible
The root that manages open state and provides context to trigger and content.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state of the panel. |
| defaultOpen | boolean | - | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
CollapsibleTrigger
The control that toggles the panel. Compose it onto a Button when you need a styled trigger.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Compose the trigger onto a child element such as Button (Base UI). |
| asChild | boolean | - | Compose the trigger onto a child element such as Button (Radix UI). |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
CollapsibleContent
The panel that expands and collapses.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Content revealed when the panel is open. |