Accordion
View as MarkdownA set of collapsible panels with headings.
Features
Permalink to heading "Features"- Full keyboard navigation support
- Supports single or multiple expanded panels
- Supports horizontal and vertical orientations
<primitives:accordion.root>
<primitives:accordion.item>
<primitives:accordion.itemHeader>
<primitives:accordion.itemTrigger>
<primitives:accordion.itemIndicator />
</primitives:accordion.itemTrigger>
</primitives:accordion.itemHeader>
<primitives:accordion.itemContent />
</primitives:accordion.item>
</primitives:accordion.root>
Installation
Permalink to heading "Installation"typo3 ui:add accordion
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Allow several open panels
Permalink to heading "Allow several open panels"Set multiple to keep several panels open at once. Try opening two items below.
Disable single items
Permalink to heading "Disable single items"Set disabled on an accordion.item to keep its panel closed. The second item below is disabled.
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.
accordion.root
Permalink to heading "accordion.root"Groups all parts of the accordion. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
multiple | booleanWhether multiple accordion items can be expanded at the same time. | No | false |
collapsible | booleanWhether an accordion item can be closed after it has been expanded. | No | true |
defaultValue | string[]The initial value of the expanded accordion items. Use when you don't need to control the value of the accordion. | No | - |
disabled | booleanWhether the accordion items are disabled. | No | - |
orientation | Enum\OrientationThe orientation of the accordion items. | No | Vertical |
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-accordion-root | <uid> |
data-orientation | The orientation of the accordion |
accordion.item
Permalink to heading "accordion.item"Groups an accordion header with the corresponding content. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe value of the accordion item. | Yes | - |
disabled | booleanWhether the accordion item is disabled. | 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 | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-accordion-item | <uid> |
data-state | "open" | "closed" |
data-focus | Present when focused |
data-disabled | Present when disabled |
data-orientation | The orientation of the item |
accordion.itemHeader
Permalink to heading "accordion.itemHeader"A heading that labels the corresponding content. Renders an <h3> element.
| Name | Description | Required | Default |
|---|---|---|---|
level | integerThe heading level to render for the accordion item header. | No | 3 |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-accordion-item-header | <uid> |
data-state | "open" | "closed" |
data-focus | Present when focused |
data-disabled | Present when disabled |
data-orientation | The orientation of the item |
accordion.itemContent
Permalink to heading "accordion.itemContent"The content of the accordion item. 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-accordion-item-content | <uid> |
data-state | "open" | "closed" |
data-disabled | Present when disabled |
data-focus | Present when focused |
data-orientation | The orientation of the item |
accordion.itemTrigger
Permalink to heading "accordion.itemTrigger"A button that opens and closes the corresponding item. 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-accordion-item-trigger | <uid> |
data-controls | |
data-orientation | The orientation of the item |
data-state | "open" | "closed" |
data-focus | Present when focused |
accordion.itemIndicator
Permalink to heading "accordion.itemIndicator"An optional visual indicator that can be used to show the open/closed state of the item. 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-accordion-item-indicator | <uid> |
data-state | "open" | "closed" |
data-disabled | Present when disabled |
data-focus | Present when focused |
data-orientation | The orientation of the item |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
focusedValue | string | null | The value of the focused accordion item. |
value | string[] | The value of the accordion |
setValue | (value: string[]) => void | Sets the value of the accordion |
getItemState | (props: ItemProps) => ItemState | Returns the state of an accordion item. |
getItemHeaderProps | (props: ItemProps) => T["element"] | Returns props for the item heading wrapper around the trigger. Render this as a heading element (e.g. `h3`) per the WAI-ARIA accordion pattern. |
Accessibility
Permalink to heading "Accessibility"| Key | Description |
|---|---|
Space | When focus is on an trigger of a collapsed item, the item is expanded |
Enter | When focus is on an trigger of a collapsed section, expands the section. |
Tab | Moves focus to the next focusable element |
Shift + Tab | Moves focus to the previous focusable element |
ArrowDown | Moves focus to the next trigger |
ArrowUp | Moves focus to the previous trigger. |
Home | When focus is on an trigger, moves focus to the first trigger. |
End | When focus is on an trigger, moves focus to the last trigger. |