Collapsible
Disclose one content region from a caller-placed trigger.
Use Collapsible for one disclosure whose trigger and content belong to the surrounding layout. Use Accordion when several disclosures share selection rules.
Basic usage#
Playground#
Anatomy#
Usage#
Styling#
Configure root, trigger, and content through collapsible.base in your Theme. The Content element exposes data-expanded and data-closed for state styling. 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 direct class and style on the root, Trigger, or Content to style those elements. Content’s ref and as apply to the inner Content element. CollapsibleT.Slot, CollapsibleT.Classes, and CollapsibleT.Styles type the slot overrides. There are no visual variants. See Styling for override precedence.
State ownership#
Use open with onOpenChange for controlled state, or defaultOpen when the component owns its initial state. The trigger and content primitives may be composed into a custom layout.
Content lifetime#
The content shell stays mounted so the trigger’s aria-controls points to a real element even while closed. unmountOnHide controls the user content inside it. Keep user content mounted when it holds state that should survive closing.
Keyboard interaction#
The trigger uses button semantics by default. A polymorphic trigger follows the keyboard semantics of its supplied element or component.
Examples#
Uncontrolled state#
Controlled state#
Composable primitives#
Attributes#
data-closedSlot: collapsible, collapsible-trigger, collapsible-contentDescription: Present when disclosure or transition content is closed.data-expandedSlot: collapsible, collapsible-trigger, collapsible-contentDescription: Present when the panel, accordion, or menu is expanded.data-disabledSlot: collapsible-triggerDescription: Present when the component, slot, or item is disabled.Props#
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.