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.
Controlled state#
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.
transition (default true) animates the content height: the content stays mounted until the
closing animation finishes, and the measured height is exposed as --mo-collapsible-content-height
on the root. Set transition={false} to toggle instantly. 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#
Uncontrolled#
Leave the disclosure uncontrolled when the page does not need to read open state.
Controlled#
Control open with onOpenChange when external state or a disabled condition governs the panel.
Partial content#
Keep always-visible content outside Collapsible.Content so only the expandable region toggles.
External trigger#
Pass open and onOpenChange so a second control can show or hide the same region.
Keep mounted#
Set forceMount to keep Collapsible.Content mounted and preserve inner state while closed.
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.