# 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.

**Dependencies:** npm: 0 direct, 1 total; registry: 3 direct, 3 total.

## 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.

```tsx
<Collapsible className="max-w-md">
  <CollapsibleTrigger>
    Show advanced options
    <IconChevronDown size={16} className="in-data-[state=open]:rotate-180 motion-safe:transition-transform duration-medium ease-standard" aria-hidden="true" />
  </CollapsibleTrigger>
  <CollapsibleContent>Webhook retries run three times with exponential backoff.</CollapsibleContent>
</Collapsible>
```

### Reasoning trace

Starts open with defaultOpen for an assistant step summary.

```tsx
<Collapsible defaultOpen className="max-w-md">
  <CollapsibleTrigger>
    Thought for 4s
    <IconChevronDown size={16} className="in-data-[state=open]:rotate-180 motion-safe:transition-transform duration-medium ease-standard" aria-hidden="true" />
  </CollapsibleTrigger>
  <CollapsibleContent>Checked token contrast pairs across both light and dark themes.</CollapsibleContent>
</Collapsible>
```

## 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

```bash
npx werewolf-ui add https://www.werewolf-ui.dev/r/collapsible.json
```

Run `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](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.
