Accordion
An accordion is a vertical list of headers that reveal or hide content sections when clicked.
Demo
Yes. It adheres to the WAI-ARIA design pattern.
Yes. It's unstyled by default, giving you freedom over the look and feel.
Yes! You can animate the Accordion with CSS and x-transition.
Features
- Full keyboard navigation
- Supports vertical or horizontal orientation
- Can expand one or multiple items
- Can set default state per item
- Can animate the expansion of items
Anatomy
Directives
x-accordion
RequiredThe root element for the accordion.
Modifier | Description |
---|---|
.single | .multiple | Opens one or multiple items at a time. Defaults to .multiple . |
.loop | Loops keyboard navigation (e.g. arrow keys) |
.vertical | .horizontal | Orientation of the accordion for keyboard navigation. Defaults to .vertical . |
x-accordion:item
RequiredEach drawer item in the accordion.
Modifier | Description |
---|---|
.open | Open the item by default |
Event | Description | detail |
---|---|---|
accordion:change | Whether the item is open or closed. | { open: boolean } |
Data Attribute | Values |
---|---|
[data-state] | open | closed |
x-accordion:trigger
RequiredEvent | Description | detail |
---|---|---|
accordion:change | Whether the item is open or closed. | { open: boolean } |
Data Attribute | Values |
---|---|
[data-state] | open | closed |
x-accordion:content
RequiredThe content that will be shown or hidden in the drawer item.
Event | Description | detail |
---|---|---|
accordion:change | Whether the item is open or closed. | { open: boolean } |
Data Attribute | Values |
---|---|
[data-state] | open | closed |
Toolbelt uses Alpine’s x-show directive to show or hide the item. The item’s shown or hidden state can be animated using CSS and the x-transition directive. Here’s an example for how to animate an accordion item’s height with a CSS grid trick: