Collapsible
An interactive component which expands/collapses a panel.
Installation#
pnpm dlx shadcn@latest add @davinciui/collapsibleUsage#
Composition: Collapsible wraps CollapsibleTrigger + CollapsibleContent.
Controlled: Use open and onOpenChange to control state. Use defaultOpen for uncontrolled.
Composition#
Use the following composition to build a Collapsible:
Collapsible
├── CollapsibleTrigger
└── CollapsibleContentAPI Reference#
| Prop | Type | Default |
|---|---|---|
CollapsibleRoot container. Wraps Trigger and Content. Accepts open, defaultOpen, onOpenChange, disabled. | Component | — |
CollapsibleTriggerButton that toggles the panel. Supports asChild to render custom button. | Component | — |
CollapsibleContentPanel with grid-rows open/close animation (300ms out, 200ms in). Put borders, padding and spacing on content inside — the panel collapses to 0fr. Supports keepMounted, hiddenUntilFound. | Component | — |
openControlled open state (Collapsible). | boolean | — |
defaultOpenInitial open state for uncontrolled usage. | boolean | false |
onOpenChangeCalled when open state changes. | (open: boolean, details: ChangeEventDetails) => void | — |
disabledDisables trigger interaction. | boolean | false |
keepMountedKeep the panel in the DOM when closed (find-in-page support). | boolean | false |
classNameAdditional CSS classes. | string | — |
Accessibility#
CollapsibleTrigger renders a native button with aria-expanded and aria-controls tied to the panel id; Enter and Space toggle it. The closed panel unmounts by default, so its content leaves the accessibility tree. Focus stays on the trigger.
Motion#
Panel height animates via grid-template-rows: 300ms ease-out cubic-bezier(0.22,1,0.36,1) on open, 200ms cubic-bezier(0.4,0,0.2,1) on close. motion-reduce:transition-none disables both; no timing props are exposed.
View source
Keep in mind
Need a custom component?
I build bespoke UI components & websites tailored to your brand.

