Skip to main content

Collapsible

View as Markdown

A collapsible panel controlled by a button.

<primitives:collapsible.root>
    <primitives:collapsible.trigger>
        <primitives:collapsible.indicator state="closed" />
        <primitives:collapsible.indicator state="open" />
    </primitives:collapsible.trigger>
    <primitives:collapsible.content />
</primitives:collapsible.root>
typo3 ui:add collapsible

Read more about installing Components and Primitives.

Set the collapsible to be open by default.

alien-bean-pasta

wild-irish-burrito

horse-battery-staple

Prevent the collapsible from being toggled.

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

Provides the collapsible state and wraps the trigger and content. Renders a <div> element.

NameDescriptionRequiredDefault
defaultOpenboolean
The initial open state of the collapsible when rendered. Use when you don't need to control the open state of the collapsible.
No
false
disabledboolean
Whether the collapsible is disabled.
No
-
collapsedHeightstring
The height of the content when collapsed.
No
-
collapsedWidthstring
The width of the content when collapsed.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-collapsible-root<uid>
data-state"open" | "closed"

Toggles the collapsible open and closed. Renders a <button> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-collapsible-trigger<uid>
data-state"open" | "closed"
data-disabledPresent when disabled

Displays state-specific content inside the trigger. Use state="open" and state="closed". Renders a <span> element.

NameDescriptionRequiredDefault
stateEnum\CollapsibleIndicatorState
The indicator state to render.
Yes
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-collapsible-indicator<uid>
data-state"open" | "closed"
data-disabledPresent when disabled

Contains the collapsible content region. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-collapsible-content<uid>
data-collapsible
data-state"open" | "closed"
data-disabledPresent when disabled
data-has-collapsed-sizePresent when the content has collapsed width or height
NameTypeDescription
openbooleanWhether the collapsible is open.
visiblebooleanWhether the collapsible is visible (open or closing)
disabledbooleanWhether the collapsible is disabled
setOpen(open: boolean) => voidFunction to open or close the collapsible.
measureSizeVoidFunctionFunction to measure the size of the content.
getTriggerState() => TriggerStateReturns the state of the trigger
getContentState() => ContentStateReturns the state of the content
KeyDescription
SpaceOpens/closes the collapsible.
EnterOpens/closes the collapsible.