<!-- generated by scripts/gen-docs.mjs from docs/system/collapsible.md. Edit the source and rerun. -->
# Collapsible

## Description
A row that opens under itself to the details it holds, so a list, a card or a page can keep what you read only sometimes one press away.

`import { Collapsible, CollapsibleChevron, CollapsiblePanel, CollapsibleTrigger } from "@/components/cobalt/ui/collapsible"`, source `registry/cobalt/ui/collapsible.tsx`, status `ready-with-gaps`.
Foundation: `Base UI Collapsible`. Traps checked: `trap/motion-layout-property` (n/a: the panel animates its height, because what sits below must move with it), `trap/motion-exit-slower` (it opens in 450ms and closes in 300ms), `trap/motion-overshoot` (both springs have no bounce), `trap/reduced-motion-ignored`, `trap/decor-pointer`, `trap/link-as-button` (n/a: the trigger is a real button and goes nowhere).

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Collapsible`: a root that holds the open state, a trigger button with `aria-expanded` and `aria-controls`, a panel that is removed while closed, `data-panel-open` on the trigger, `data-starting-style` and `data-ending-style` on the panel, and `--collapsible-panel-height` measured on the panel while it moves | `data-slot` on every part; the panel's height on the system's own springs: it opens on the layout spring (`springs.layout`, 450ms, `--t-layout`) and closes on the settle spring (`springs.settle`, 300ms, `--t-settle`), each sampled into a CSS `linear()` curve from `registry/cobalt/lib/motion.ts`, so the first frame moves the panel 4 percent of its height and the last frames settle instead of stopping (`registry/cobalt/ui/collapsible.tsx:9-12`); the content fades on the same curve as the height, so the opacity always equals the share revealed (`registry/cobalt/ui/collapsible.tsx:108`); no padding or margin on the panel, which would keep it from reaching a height of 0, and a clip on the vertical axis only while the height moves, with `data-settled` once it rests, so a focus ring at the panel's edge is whole at rest (`registry/cobalt/ui/collapsible.tsx:79-83`); `CollapsibleChevron`, a hidden down chevron that turns over on the panel's two curves; `group/collapsible` on the trigger so the chevron reads its state; `select-none` and `text-start` on the trigger, so a double press selects no text and right-to-left text aligns to its start; no outline on the trigger, which takes the system focus ring |

## Examples
Runs that open to their details, a card's line that opens to the services behind its total, and questions that open to their answers.

Real uses, 1 call site (`rg -n "<Collapsible\b" app registry --glob '!registry/cobalt/ui/*'`): the showcase's Source fold under each example (`app/pages/component.tsx:93`). Inside the registry Trace builds on it (`registry/cobalt/ui/trace.tsx:110`), and the docs use it for their folds, their rules and their code panels (`site/fold.tsx:80`, `site/rules.tsx:25`, `site/example.tsx:213`).

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/collapsible/default.tsx` | default | Each run opens to its details, and the runs below it make room |
| Not applicable: closed is the rest state of every example | state:closed | The rows with their panels out of the page |
| Not applicable: open is reached by pressing a row on any example | state:open | The panel at its height, the chevron turned over, the rows below moved down by that height |
| `docs/system/examples/collapsible/in-card.tsx` | composition:Card | A line of a card opens to the services behind its total, and the card grows with it |
| `docs/system/examples/collapsible/in-section.tsx` | composition:Section | Questions under a section heading, each opening to its answer |

Example: Each run opens to its details, and the runs below it make room (`docs/system/examples/collapsible/default.tsx`)

```tsx
import {
  Collapsible,
  CollapsibleChevron,
  CollapsiblePanel,
  CollapsibleTrigger,
} from "@/components/cobalt/ui/collapsible";
import { DataList, DataListItem, DataListLabel, DataListValue } from "@/components/cobalt/ui/data-list";
import { TextLink } from "@/components/cobalt/ui/text-link";

const runs = [
  { name: "orders_daily", took: "4m 12s", started: "09:41", rows: "2,418,203", source: "Warehouse" },
  { name: "sessions_hourly", took: "38s", started: "10:00", rows: "184,920", source: "Event stream" },
  { name: "customers_sync", took: "1m 05s", started: "10:12", rows: "48,117", source: "CRM export" },
];

export default function Example() {
  return (
    <ul className="flex w-full max-w-sm flex-col">
      {runs.map((run) => (
        <li key={run.name}>
          <Collapsible>
            <CollapsibleTrigger>
              <span className="flex min-w-0 flex-1 items-baseline justify-between gap-4">
                <span className="min-w-0 truncate">{run.name}</span>
                <span className="shrink-0 font-normal text-muted-foreground tabular-nums">{run.took}</span>
              </span>
              <CollapsibleChevron />
            </CollapsibleTrigger>
            <CollapsiblePanel>
              <div className="flex flex-col gap-3 pt-1 pb-4">
                <DataList>
                  <DataListItem>
                    <DataListLabel>Started</DataListLabel>
                    <DataListValue>{run.started}</DataListValue>
                  </DataListItem>
                  <DataListItem>
                    <DataListLabel>Rows written</DataListLabel>
                    <DataListValue>{run.rows}</DataListValue>
                  </DataListItem>
                  <DataListItem>
                    <DataListLabel>Source</DataListLabel>
                    <DataListValue>{run.source}</DataListValue>
                  </DataListItem>
                </DataList>
                <TextLink href={`#logs-${run.name}`} className="self-start text-sm">
                  View logs
                </TextLink>
              </div>
            </CollapsiblePanel>
          </Collapsible>
        </li>
      ))}
    </ul>
  );
}
```

Example: A line of a card opens to the services behind its total, and the card grows with it (`docs/system/examples/collapsible/in-card.tsx`)

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import {
  Collapsible,
  CollapsibleChevron,
  CollapsiblePanel,
  CollapsibleTrigger,
} from "@/components/cobalt/ui/collapsible";
import { DataList, DataListItem, DataListLabel, DataListValue } from "@/components/cobalt/ui/data-list";

const over = [
  ["Vector search", "+$2,140"],
  ["GPU inference", "+$1,385"],
  ["Object storage", "+$410"],
];

export default function Example() {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle>Cloud spend, October</CardTitle>
        <CardDescription>$56,145 of a $52,210 budget</CardDescription>
      </CardHeader>
      <CardContent>
        <Collapsible>
          <CollapsibleTrigger>
            <span className="flex min-w-0 flex-1 items-baseline justify-between gap-4">
              <span className="min-w-0">3 services over budget</span>
              <span className="shrink-0 font-normal text-muted-foreground tabular-nums">+$3,935</span>
            </span>
            <CollapsibleChevron />
          </CollapsibleTrigger>
          <CollapsiblePanel>
            <div className="pt-1 pb-2">
              <DataList>
                {over.map(([service, amount]) => (
                  <DataListItem key={service}>
                    <DataListLabel>{service}</DataListLabel>
                    <DataListValue>{amount}</DataListValue>
                  </DataListItem>
                ))}
              </DataList>
            </div>
          </CollapsiblePanel>
        </Collapsible>
      </CardContent>
    </Card>
  );
}
```

Example: Questions under a section heading, each opening to its answer (`docs/system/examples/collapsible/in-section.tsx`)

```tsx
import {
  Collapsible,
  CollapsibleChevron,
  CollapsiblePanel,
  CollapsibleTrigger,
} from "@/components/cobalt/ui/collapsible";
import { Section } from "@/components/cobalt/ui/section";

const questions = [
  {
    question: "How is usage counted?",
    answer:
      "Each query you run counts once, whether it returns rows or not. A query that fails before it starts, such as one with a syntax error, does not count.",
  },
  {
    question: "When am I billed?",
    answer:
      "On the first of each month, for the month before. The invoice lists every workspace with the queries it ran.",
  },
  {
    question: "Can I set a spending limit?",
    answer:
      "Yes. An owner can set a monthly limit in Billing. Queries stop at the limit until an owner raises it or the month ends.",
  },
];

export default function Example() {
  return (
    <Section id="billing-questions" heading="Questions" className="w-full max-w-md">
      <div className="flex flex-col">
        {questions.map((item) => (
          <Collapsible key={item.question}>
            <CollapsibleTrigger className="items-start">
              {item.question}
              <CollapsibleChevron className="mt-0.5" />
            </CollapsibleTrigger>
            <CollapsiblePanel>
              <p className="pb-3 text-sm text-muted-foreground">{item.answer}</p>
            </CollapsiblePanel>
          </Collapsible>
        ))}
      </div>
    </Section>
  );
}
```

## Variants
Not applicable: Collapsible has no variant axis. Its size comes from `className` on the trigger and the panel.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| closed | render, or a press on the open trigger | press the trigger to open | `aria-expanded="false"`, the chevron pointing down, no panel in the page | test |
| opening | a press, Enter or Space on the trigger | press again, which turns the panel back from the height it has | the panel growing from 0, its content fading in with it, the chevron turning, the rows below moving down by the growth | by hand |
| open | the opening ends, or `defaultOpen` | read the panel, press the trigger to close | `aria-expanded="true"`, the chevron turned over, the panel at its own height | test |
| closing | a press, Enter or Space on the open trigger | press again, which opens it from the height it has | the panel shrinking to 0 in 300ms, its content fading out with it, the chevron turning back | by hand |
| disabled | `disabled` on the root | read the row | `disabled` on the trigger, so it takes no press and no focus | by hand |

### State precedence
- Open and disabled: disabled wins. The trigger ignores presses, and the panel stays as it was.
- Closed and disabled: disabled wins. The panel stays out of the page and the trigger ignores presses.
- Opening and a press: the press wins. Base UI measures the height the panel has at that moment, and the panel closes from there.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| closed to open | input | `springs.layout` as a CSS curve over `--t-layout` (450ms); measured the largest step between two 16ms frames at 12 percent of the growth, the panel at rest at 352 to 464ms, and nothing outside the panel moving more than 0.5px in 196 recordings of the examples, rules, folds and code panels on the docs and the showcase at 1440 and 390, light and dark (Playwright, fake clock, 2026-10-17) | the panel's height from 0 to its own height and its opacity from 0 to 1, on the one curve; the chevron's rotation on the same curve | `motion-reduce:transition-none`: the panel appears at once |
| open to closed | input | `springs.settle` as a CSS curve over `--t-settle` (300ms); measured at rest at 240 to 320ms | the panel's height to 0 and its opacity to 0; the chevron turns back on the same curve | the panel leaves at once |

## Props

<!-- Props generated from registry/cobalt/ui/collapsible.tsx with TypeScript by scripts/props-table.mjs -->
### Collapsible

No props of its own.

Also accepts every native `<div>` attribute; from Base UI: `defaultOpen`, `disabled`, `onOpenChange`, `open`, `render`.

### CollapsibleChevron

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `className?` | `string` |  |  |

### CollapsiblePanel

No props of its own.

Also accepts every native `<div>` attribute; from Base UI: `hiddenUntilFound`, `keepMounted`, `render`.

### CollapsibleTrigger

No props of its own.

Also accepts every native `<button>` attribute; from Base UI: `nativeButton`, `render`.

`defaultOpen` starts the root open. `open` and `onOpenChange` control it from outside, such as opening the row a link points at. `disabled` stops the trigger. Every native attribute passes to its part, and `className` is merged last. The trigger takes `render` to become another element, such as a Button, and keeps that element's look. The panel takes `ref` and `style`; it moves on the `ease-layout` and `ease-settle` curves, the layout and settle springs sampled into `--curve-layout` and `--curve-settle` in tokens.css.

## Usage

### When to use
- A row of a list holds details you read sometimes, such as a run's figures: each row opens on its own, and the rows below make room.
- A line of a card or a section stands for a longer list, such as a total for the items behind it.
- A question holds an answer of a paragraph or two.

### When not to use
- Several views of one subject sit side by side. Use Tabs instead.
- The answer is a menu of actions. Use DropdownMenu instead.
- A button opens one small field, such as a name to save. Use Grow instead, which turns the button into the form.
- The answer needs your decision before you go on. Use Dialog instead.

### Rules
- `rule/collapsible-trigger-names-the-panel`: When a trigger opens a panel, label it with what the panel holds, such as a run's name or `How is usage counted?`, instead of `Show more`, because the label is the accessible name and `Show more` says nothing to a screen reader reading the page by its buttons. Evidence: principle wcag: 2.4.6 Headings and labels, the label says what the control is for; app 3/3 example triggers name their panel (`docs/system/examples/collapsible/default.tsx:23`, `docs/system/examples/collapsible/in-card.tsx:26`, `docs/system/examples/collapsible/in-section.tsx:34`). Check: review of every `CollapsibleTrigger`; test `collapsible.test.tsx` reads the trigger's text.
  - Don't: `<CollapsibleTrigger>Show more</CollapsibleTrigger>`
  - Do: `<CollapsibleTrigger>orders_daily<CollapsibleChevron /></CollapsibleTrigger>`
- `rule/collapsible-chevron-is-decoration`: When a trigger shows a chevron, use `CollapsibleChevron` and leave it without a label, instead of an icon of your own with a title, because the chevron repeats what `aria-expanded` already says and a label would be read twice. Evidence: principle wcag: 1.1.1 Non-text content, a decorative image is hidden from assistive technology; app 3/3 example triggers use `CollapsibleChevron` (`docs/system/examples/collapsible/default.tsx:28`, `docs/system/examples/collapsible/in-card.tsx:31`, `docs/system/examples/collapsible/in-section.tsx:36`). Check: test `collapsible.test.tsx` expects `aria-hidden="true"` on the chevron.
  - Don't: `<ChevronDownIcon aria-label="Expand" />`
  - Do: `<CollapsibleChevron />`
- `rule/collapsible-panel-keeps-its-own-height`: When a panel needs room around its content, put the padding on an element inside `CollapsiblePanel`, instead of on the panel, because the panel animates its height from 0 and padding on it keeps it from getting there: the old panel's 4px padding held it at 8px, so the last 8px of every close were cut and its first line showed over the row below. Evidence: measured the old panel stopping at 8px for 5 frames of each close, `.design-system/evidence/collapsible/before-analysis.txt`; app 3/3 example panels put the room on the element inside (`docs/system/examples/collapsible/default.tsx:31`, `docs/system/examples/collapsible/in-card.tsx:34`, `docs/system/examples/collapsible/in-section.tsx:39`). Check: test `collapsible.test.tsx` finds no padding or margin on the panel; review of every `CollapsiblePanel`.
  - Don't: `<CollapsiblePanel className="pb-2">…</CollapsiblePanel>`
  - Do: `<CollapsiblePanel><ul className="pb-2">…</ul></CollapsiblePanel>`
- `rule/collapsible-rows-open-on-their-own`: When the rows of a list each open, give each row its own `Collapsible` and let several be open at once, instead of closing one row when another opens, because a row above that closes pulls the row you pressed up the page while it opens: one rule above another moved the pressed row 182px. Evidence: measured the docs' rule rows when they opened one at a time, the second rule's trigger moving 182.4px while it opened, `.design-system/evidence/collapsible/before-analysis.txt` (docs-collapsible-1440-light-05-rule-switch-mid); app 2/2 lists of rows open each row on its own (`docs/system/examples/collapsible/default.tsx:22`, `site/rules.tsx:25`). Check: review of every list of Collapsibles for shared open state.
  - Don't: `<Collapsible open={openRow === i} onOpenChange={(next) => setOpenRow(next ? i : null)}>`
  - Do: `<Collapsible>`

### Content
- `rule/collapsible-trigger-is-short`: When you write a trigger label, use a noun phrase such as `Billing history`, the row's own name such as `orders_daily`, or a question the panel answers such as `How is usage counted?`, instead of a sentence about opening, because the chevron already says it opens and the label says what opens. Evidence: app 3/3 example labels are a name, a count or a question (`docs/system/examples/collapsible/default.tsx:25`, `docs/system/examples/collapsible/in-card.tsx:28`, `docs/system/examples/collapsible/in-section.tsx:35`). Check: review of every trigger label.
  - Don't: `<CollapsibleTrigger>Click here to see the billing history</CollapsibleTrigger>`
  - Do: `<CollapsibleTrigger>Billing history</CollapsibleTrigger>`

### Anti-slop
- `rule/collapsible-no-scale-on-open`: When a panel opens, keep the height and the fade the component gives it and add no `scale-*` or `translate-*` on the panel, because the system moves nothing by scale and a panel that slides as well as grows reads as two motions. Evidence: person D36, D37; measured the panel's transition is `height, opacity` only, `registry/cobalt/ui/collapsible.tsx:108`. Check: lint rule/component-override on CollapsiblePanel for `scale-` (scripts/check-system.mjs); review.
  - Don't: `<CollapsiblePanel className="data-[starting-style]:scale-95">…</CollapsiblePanel>`
  - Do: `<CollapsiblePanel>…</CollapsiblePanel>`

### Limits
- `rule/collapsible-panel-fits-one-screen`: When a panel's content runs past 480px, split it or link to its own page instead of opening it in place, because the height animation moves everything below by that distance in 450ms and a long move reads as the page jumping. Evidence: measured 136px for a run's details, 96px for a card's services and 52 to 72px for an answer, `docs/system/examples/collapsible/default.tsx:31`, `docs/system/examples/collapsible/in-section.tsx:39`. Check: review of every `CollapsiblePanel` against 480px.
  - Don't: `<CollapsiblePanel>{allTwoHundredInvoices}</CollapsiblePanel>`
  - Do: `<CollapsiblePanel>{latestThreeInvoices}</CollapsiblePanel>`

## Accessibility
Rests on a `button` with `aria-expanded` from Base UI `Collapsible`.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the trigger | moves focus to the trigger | the trigger | by hand |
| Enter or Space | trigger | opens or closes the panel | the trigger | by hand |
| Tab | trigger, open | moves into the panel's first control, or past it | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| trigger | button | its text | `aria-expanded`, `aria-controls` while open | "orders_daily, 4m 12s, button, collapsed" or "expanded" | test |
| panel | none | not named | `hidden` is absent: a closed panel is not in the page | its text, read after the trigger once open | test |
| chevron | none, `aria-hidden="true"` | nothing | none | nothing | test |

## Tokens
| Part | State | Token |
|---|---|---|
| panel | opening | `--t-layout`, `springs.layout` |
| panel | closing | `--t-settle`, `springs.settle` |
| chevron | all | `--muted-foreground` |
| chevron | opening | `--t-layout`, `springs.layout` |
| chevron | closing | `--t-settle`, `springs.settle` |

## Related
- Grow: a button that turns into the one small form it opens.
- Tabs: several views of one subject, one shown at a time.
- Section: a titled block of a page that stays open.
- DropdownMenu: a list of actions under a trigger.
