Collapsible
A single disclosure section that expands and collapses its content in place without a mandatory heading wrapper, suited for advanced form options or reasoning traces.
Preview
Usage
When to use
- Hide and show one optional section, such as advanced form fields or an assistant reasoning summary.
- Disclose content in place without adding a heading element.
When not to use
- A stack of sections with dividers or arrow-key navigation between titles. Use Accordion.
- Switching between views of the same content. Use Tabs.
Examples
Advanced options
A compact disclosure inside a form without adding a heading.
Reasoning trace
Starts open with defaultOpen for an assistant step summary.
Do and don't
Do
- Use Collapsible for one optional section, such as advanced form fields or a reasoning block.
- Keep the trigger label clear about what opens or closes.
Don't
- Don't use Collapsible for a stack of sections that share dividers or headings; use Accordion.
- Don't hide required fields inside a collapsed section.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| open | boolean | - | - | Controlled open state. Pair with onOpenChange. |
| defaultOpen | boolean | - | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | - | Called with the next open state when the trigger is activated. |
| disabled | boolean | - | false | Prevents toggling the section and dims the trigger. |
Slots
| Name | Required | Description |
|---|---|---|
| trigger | yes | CollapsibleTrigger holding the toggle label and optional icon. |
| content | yes | CollapsibleContent holding the disclosed body. |
Anatomy
| Part | Description |
|---|---|
| root | Collapsible: a column as wide as its parent. |
| trigger | CollapsibleTrigger: the button that toggles the section, at least sm height with 14px medium text, neutral hover and pressed overlays, and a focus ring. |
| icon | Optional Tabler icon inside the trigger, secondary by default. |
| hitArea | Transparent ::before centered on the trigger, never smaller than size-target-min (24px on mouse, 44px on touch). |
| content | CollapsibleContent: the disclosed container, 14px secondary text, growing in on open and collapsing on close. |
| body | The padded inner block inside the content, py-sm, so nothing shows while the container height is zero. |
Accessibility
Role: generic
| Keys | Action |
|---|---|
| Tab | Moves focus to the trigger button and, when open, into the disclosed content. |
| Space, Enter | Toggles the disclosed content open or closed. |
- CollapsibleTrigger is a button with aria-expanded and aria-controls pointing to CollapsibleContent.
- Unlike Accordion, CollapsibleTrigger does not wrap itself in an h2-h4 heading, so it fits inside forms and inline status blocks.
- Closed content unmounts after the collapse animation finishes, or at once under prefers-reduced-motion.
Install
npx werewolf-ui add https://www.werewolf-ui.dev/r/collapsible.jsonRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.