Skip to main content

Collapsible

View as Markdown

A collapsible panel controlled by a button.

Features

Installation

typo3 ui:add collapsible

Read more about installing Components and Primitives.

Examples

Default Open

Set the collapsible to be open by default.

alien-bean-pasta

wild-irish-burrito

horse-battery-staple

Disabled

Prevent the collapsible from being toggled.

API Reference

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.

collapsible.root

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
-
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
[]
controlledboolean
If true, the component is meant to be initialized manually inside another component
No
false
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopecollapsible
data-partroot
data-state"open" | "closed"

collapsible.trigger

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopecollapsible
data-parttrigger
data-state"open" | "closed"
data-disabledPresent when disabled

collapsible.indicator

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
-
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopecollapsible
data-partindicator
data-state"open" | "closed"
data-disabledPresent when disabled

collapsible.content

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopecollapsible
data-partcontent
data-collapsible
data-state"open" | "closed"
data-disabledPresent when disabled
data-has-collapsed-sizePresent when the content has collapsed width or height

Machine JavaScript API

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.

Accessibility

KeyDescription
SpaceOpens/closes the collapsible.
EnterOpens/closes the collapsible.

Anatomy

<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>