Data display
Accordion
A stack of collapsible sections. Each item has a header button that shows or hides its panel; with exclusive, opening one closes the others.
An item with a label renders its own heading and content, so the two inner tags are only written for a custom header.
Nothing to show
Billing starts open and Shipping closed. Each header toggles its own panel, and both can be open at once.
One open at a time, bound to Livewire #
Opening Shipping closes Billing and sets $section to 'shipping'; closing it sets null. Setting the property on the server opens that item. Without exclusive the property is an array of the open names, e.g. ['billing', 'shipping'].
Nothing to show
Rendering from data #
Nothing to show
Custom header #
Without label, the item renders its slot as is: the heading takes any markup, here a badge next to the title, and the whole header stays clickable.
Nothing to show
Border and sizes #
border draws a frame around the accordion (solid, dashed or dotted) and size sets padding, font size and radius.
Nothing to show
Reversed and disabled #
reversed puts the chevron before the label; disabled on an item (or on the accordion) blocks its header.
Nothing to show
Several open, bound #
Without exclusive, the bound property is an array of the open names.
Nothing to show
Events #
Items fire opened and closed; the accordion fires changed with the item elements in $event.detail.items. Listen on the tag itself.
Nothing to show
Nested #
An accordion inside an item; it inherits the props set on the item that holds it.
Nothing to show
Customization #
trigger: attributes go to the header button and content: to the panel; collapse takes x-collapse modifiers.
Nothing to show
Reference
tk:accordion
└── tk:accordion.item
├── tk:accordion.heading
└── tk:accordion.content
tk:accordion
| Prop | Type | Default | Description |
|---|---|---|---|
exclusive |
bool | false |
Only one item stays open; opening another closes it. |
collapse |
bool | string | true |
Animates opening and closing. false turns the animation off; a string is passed as x-collapse modifiers (e.g. duration.500ms). |
reversed |
bool | false |
Puts the chevron before the label instead of after it. |
size |
string | md |
xs, sm, md, lg, xl, 2xl or 3xl. Sets padding, font size and corner radius. |
border |
bool | string | null |
Draws a border around the accordion and pads the items. true, solid, dashed or dotted. |
disabled |
bool | false |
Disables every header. |
level |
int | false | 2 |
Heading level announced for each header (aria-level). false drops the heading wrapper. |
region |
bool | true |
false drops role="region" from the panels. |
wire:model and x-model bind the open item names: one name with exclusive, an array of names otherwise.
Slots
| Slot | Description |
|---|---|
| default | The items. |
Events
| Event | Detail | When |
|---|---|---|
changed |
{ items }, the item elements |
An item of this accordion opened or closed. |
tk:accordion.item
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | null |
Header text. When given, the item renders its own heading and content, and the default slot is the panel body. Without it, the default slot is rendered as is. |
name |
string | null |
Identifies the item in the accordion's wire:model / x-model value. |
expanded |
bool | false |
Opens the item on the first render. |
disabled |
bool | false |
Disables this item's header. |
size, collapse, reversed, border, level and region are inherited from the accordion and can be set per item.
Slots
| Slot | Description |
|---|---|
| default | The panel body, or the heading and content when label is not given. |
Events
| Event | Detail | When |
|---|---|---|
opened |
The item was opened. | |
closed |
The item was closed. |
Prefixes
| Prefix | Goes to |
|---|---|
trigger: |
The header button. |
content: |
The panel. |
tk:accordion.heading and tk:accordion.content
Used inside an item without label. The heading takes label (or its slot), size, collapse, reversed, border, disabled and level; the content takes size, collapse, border and region. All are inherited from the item and the accordion.
Slots
| Slot | Description |
|---|---|
| default | The header content, in place of label. |
| default | The panel body. |
Events
Events are dispatched on the component's own element and do not bubble: listen on the tag itself.
With Alpine:
Nothing to show
Calling a Livewire action:
Nothing to show
Customization
Classes and attributes on a tag go to its root element. To reach an inner element of an item, prefix the attribute (listed in the Reference above).
Nothing to show
Accessibility
Follows the WAI-ARIA accordion pattern. Each header is a <button> inside an element with role="heading" and aria-level, carrying aria-expanded and aria-controls pointing to its panel. Each panel has role="region" labelled by its header; set :region="false" above six items, where that many landmarks become noise for screen readers.
| Key | Action |
|---|---|
| Enter, Space | Opens or closes the focused header's panel. |
| Arrow Down / Arrow Up | Moves focus to the next / previous header, wrapping around. |
| Home / End | Moves focus to the first / last header. |
| Tab | Moves through the headers and the focusable content of open panels. |
Disabled headers are skipped by the arrow keys, Home and End.
Behavior notes
expandedonly sets the initial state: after the first render the browser owns it, so a Livewire update never closes an item the user opened. To drive it from the server, give each item anameand bind the accordion withwire:model/x-model.- When the accordion is bound with
wire:model/x-model, the bound value decides which items are open andexpandedis ignored. - A value coming from
wire:model/x-modelon page load is applied without animation and without firingopened/changed. - With
exclusive, if several items are markedexpanded, only the first stays open. - A nested accordion inherits the props set on the item that holds it (
disabled,reversed,border,level,collapse,region,size). To reset one, pass it on the nested accordion (e.g.:disabled="false").