Collapsible
View as MarkdownA collapsible panel controlled by a button.
alien-bean-pasta
wild-irish-burrito
horse-battery-staple
Features
Permalink to heading "Features"- Full keyboard navigation support
- Supports animation via CSS transitions or animations
- Supports custom open and collapsed heights/widths
<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>
Installation
Permalink to heading "Installation"typo3 ui:add collapsible
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Default Open
Permalink to heading "Default Open"Set the collapsible to be open by default.
alien-bean-pasta
wild-irish-burrito
horse-battery-staple
Disabled
Permalink to heading "Disabled"Prevent the collapsible from being toggled.
alien-bean-pasta
wild-irish-burrito
horse-battery-staple
API Reference
Permalink to heading "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
Permalink to heading "collapsible.root"Provides the collapsible state and wraps the trigger and content. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
defaultOpen | booleanThe initial open state of the collapsible when rendered. Use when you don't need to control the open state of the collapsible. | No | false |
disabled | booleanWhether the collapsible is disabled. | No | - |
collapsedHeight | stringThe height of the content when collapsed. | No | - |
collapsedWidth | stringThe width of the content when collapsed. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-collapsible-root | <uid> |
data-state | "open" | "closed" |
collapsible.trigger
Permalink to heading "collapsible.trigger"Toggles the collapsible open and closed. Renders a <button> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-collapsible-trigger | <uid> |
data-state | "open" | "closed" |
data-disabled | Present when disabled |
collapsible.indicator
Permalink to heading "collapsible.indicator"Displays state-specific content inside the trigger. Use state="open" and state="closed". Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
state | Enum\CollapsibleIndicatorStateThe indicator state to render. | Yes | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-collapsible-indicator | <uid> |
data-state | "open" | "closed" |
data-disabled | Present when disabled |
collapsible.content
Permalink to heading "collapsible.content"Contains the collapsible content region. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-collapsible-content | <uid> |
data-collapsible | |
data-state | "open" | "closed" |
data-disabled | Present when disabled |
data-has-collapsed-size | Present when the content has collapsed width or height |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
open | boolean | Whether the collapsible is open. |
visible | boolean | Whether the collapsible is visible (open or closing) |
disabled | boolean | Whether the collapsible is disabled |
setOpen | (open: boolean) => void | Function to open or close the collapsible. |
measureSize | VoidFunction | Function to measure the size of the content. |
getTriggerState | () => TriggerState | Returns the state of the trigger |
getContentState | () => ContentState | Returns the state of the content |
Accessibility
Permalink to heading "Accessibility"| Key | Description |
|---|---|
Space | Opens/closes the collapsible. |
Enter | Opens/closes the collapsible. |