Collapsible

A single show/hide panel toggled by a button, from @clerk/headless. It is a headless primitive: it supplies behavior, state, ARIA wiring, and the expand/collapse animation lifecycle, but ships no styles — you bring your own CSS by targeting the data-* attributes each part emits.

Example

The demo below is intentionally unstyled — it renders the raw primitive so you can see its behavior and ARIA wiring. Click the trigger to expand and collapse.

Usage

import { Collapsible } from '@clerk/headless/collapsible';

<Collapsible.Root>
  <Collapsible.Trigger>Toggle</Collapsible.Trigger>
  <Collapsible.Panel>Hidden content</Collapsible.Panel>
</Collapsible.Root>

Controlled

const [open, setOpen] = useState(false);

<Collapsible.Root
  open={open}
  onOpenChange={setOpen}
>
  <Collapsible.Trigger>Toggle</Collapsible.Trigger>
  <Collapsible.Panel>Hidden content</Collapsible.Panel>
</Collapsible.Root>

Parts

PartDefault ElementDescription
Collapsible.Root<div>Root wrapper, provides context
Collapsible.Trigger<button>Clickable toggle that opens/closes
Collapsible.Panel<div>Collapsible content area

All parts accept a render prop for polymorphic rendering and standard HTML attributes for their default element.

Props

Collapsible.Root

PropTypeDefaultDescription
openbooleanControlled open state
defaultOpenbooleanfalseInitial open state (uncontrolled)
onOpenChange(open: boolean) => voidCalled when open state changes
disabledbooleanfalsePrevents the trigger from toggling

Collapsible.Trigger and Collapsible.Panel take no additional props beyond standard HTML attributes for their default element.

Styling

Each part emits data-* attributes you can target with any CSS solution:

AttributeApplies ToDescription
data-openRoot, Trigger, PanelPresent when the panel is open
data-closedRoot, Trigger, PanelPresent when the panel is closed
data-disabledRoot, TriggerPresent when disabled

Collapsible.Panel also exposes --collapsible-panel-height / --collapsible-panel-width (its measured dimensions) for height/width-based animations:

.cl-collapsible-panel {
  overflow: hidden;
  height: var(--collapsible-panel-height);
  transition: height 200ms ease;
}
.cl-collapsible-panel[data-closed] {
  height: 0;
}