Skip to content

Collapsible

collapsible

A section that opens and closes: a trigger, a panel, and a chevron that turns. The height is a CSS transition over the height Base UI measures, so the content inside keeps its own layout instead of being reflowed by a wrapper.

Install

$npxshadcnadd@forme/collapsible

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import {
  Collapsible,
  CollapsibleIndicator,
  CollapsiblePanel,
  CollapsibleTrigger,
} from "@/components/forme/collapsible/collapsible";

<Collapsible>
  <CollapsibleTrigger>
    What happens when a component is updated?
    <CollapsibleIndicator />
  </CollapsibleTrigger>
  <CollapsiblePanel>You pull the new source when you want it.</CollapsiblePanel>
</Collapsible>

When to use

Reach for it

  • One section that hides detail until it is asked for: a FAQ answer, an advanced settings block, a long description.
  • Several independent sections, stacked. Each owns its state, so more than one can be open at once.

Use something else

  • A set where only one may be open — that is an Accordion, which coordinates them.
  • Content that should always be visible; hiding one line behind a click costs more than it saves.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

CollapsibleTrigger

PropTypeDefaultDescription
asChildboolean—Render as the single child element instead of a <button>, keeping the trigger behaviour.

Also takes every prop of Base UI Collapsible.Trigger.

CollapsiblePanel

The panel.

PropTypeDefaultDescription
innerClassNamestring—Padding and layout for the content, inside the clipping wrapper.

Also takes every prop of Base UI Collapsible.Panel.

The other parts

  • CollapsibleTakes Base UI Collapsible.Root
  • CollapsibleIndicatorTakes <span> attributes

Accessibility

  • The trigger is a real <button> with aria-expanded and aria-controls, so it is reachable and announced by the browser.
  • The panel unmounts when closed, keeping hidden content out of the tab order and out of find-in-page; keepMounted or hiddenUntilFound change that trade deliberately.

Motion

  • The panel's height is one CSS transition over --collapsible-panel-height, so the content inside is never measured or pinned.
  • The chevron turns on the same duration, reading the open state from the trigger's data-panel-open.
  • Reduced motion collapses the duration to nothing through the foundation's global rule — there is no branch to forget.