Collapsible
Content opens to its real height on a spring and its rows fall in one after another.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/collapsibleThis adds components/keyframery/collapsible.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@/components/keyframery/collapsible"
export default function Usage() {
return (
<Collapsible>
<CollapsibleTrigger>Show details</CollapsibleTrigger>
<CollapsiblePanel>The details.</CollapsiblePanel>
</Collapsible>
)
}Anatomy
How the parts fit together:
Collapsible
├── CollapsibleTrigger
└── CollapsiblePanelExamples
Basic
The panel opens to its real height. The trigger's text can follow the state.
Controlled
Pass open and onOpenChange to open it from elsewhere.
Motion
| Move | What you see |
|---|---|
| Height | Content opens to its real height. |
| Cascade | Its rows fall in one after another. |
| Spring | The chevron turns on a spring. |
Timing and springiness follow the motion style you set. To change how fast this collapsible moves, pass speed:
<Collapsible speed="fast">
…
</Collapsible>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--collapsible-height | Trigger height | 2.25rem |
--collapsible-gap | Label and chevron gap | 0.75rem |
--collapsible-radius | Trigger corners | 9px |
--collapsible-font | Trigger label size | 13px |
--collapsible-face | Trigger surface | transparent; hover --foreground 4.5%; pressed --foreground 7% |
--collapsible-muted | Resting trigger text | --muted-foreground |
--collapsible-ink | Open and hovered trigger text | --foreground |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK collapsible reference.
Collapsible
Renders a <div>, and takes its props too.
Prop
Type
CollapsiblePanel
Renders a <div>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
CollapsibleTrigger: a<button>
Keyboard
| Key | What it does |
|---|---|
| Enter | Opens or closes the panel. |
| Space | Opens or closes the panel. |
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's collapsible with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/collapsible"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/collapsible"Questions
How does the animated Collapsible for UI SDK move?
Height: Content opens to its real height. Cascade: Its rows fall in one after another. Spring: The chevron turns on a spring.
Do I need Motion or Framer Motion for the animated Collapsible?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/collapsible instead. It has the same parts and props as @ui-sdk/react/collapsible and adds motion only.
What happens to the Collapsible when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.