Collapsible
Disclose one content region from a caller-placed trigger.
Anatomy#
Usage#
Use Collapsible for one disclosure whose trigger and content belong to the surrounding layout. Use Accordion when several disclosures share selection rules.
State ownership#
Use open with onOpenChange for controlled state, or defaultOpen when the component owns its
initial state. onOpenChange receives the next state when the user toggles a trigger, and does not
fire when you change open yourself. With a controlled open, the state changes only when you
update it. The trigger and content parts can sit anywhere inside the root, so you can compose them
into a custom layout.
disabled on Collapsible blocks every trigger and keeps the current open state. disabled on
Collapsible.Trigger blocks only that trigger. Set transition to animate the content height. The
content then stays mounted until the closing animation finishes, and the measured height is exposed
as --mo-collapsible-content-height on the root. Animation is skipped for prefers-reduced-motion.
Content lifetime#
The content shell stays mounted so the trigger’s aria-controls points to a real element even while
closed. forceMount controls the content inside it. By default, content mounts on first open and
unmounts after it closes. Set forceMount when content holds state that should survive closing; it
mounts the content even before the first open. Mounted closed content stays hidden and inert, and
browser find-in-page can reveal it, which opens the Collapsible and calls onOpenChange.
Styling#
Configure root, trigger, and content through collapsible.base in your Theme. The root and
Content expose data-expanded and data-closed for state styling, and the Trigger also exposes
data-disabled. Collapsible also renders an internal wrapper with data-expanded, data-closed,
and data-transition for measurement, height animation, presence, and accessibility. You cannot
configure that wrapper through Theme, classes, styles, or Content props.
Root classes and styles set defaults for this Collapsible. Use class and style directly on
the root, Trigger, or Content to style those elements. Content’s ref and as apply to the inner
Content element. There are no visual variants.
Keyboard interaction#
The trigger renders a button by default, or an a when you pass href. Pass as to render a
different element or component, which then follows its own keyboard semantics.
Examples#
Answer a password FAQ#
Leave the disclosure uncontrolled when the page does not need to read open state.
Inspect a locked invoice#
Own open when an external control or a lock switch must drive the same panel.
Reveal extra starred repositories#
Place the trigger beside a heading when only some rows should expand. Rows that stay visible can sit
outside Collapsible.Content.
Toggle advanced settings from outside the panel#
Pass open and onOpenChange so a second control can show or hide the same region.
Keep filter text while the panel is closed#
Set forceMount so fields inside Content keep their values.
API Reference#
Attributes#
data-closeddata-expandeddata-disabledProps#
Collapsible#
Props for the Collapsible component. Renders a <div> element by default.
Trigger#
Renders a <button> element by default.
Content#
Renders a <div> element by default.