Accordion
A vertically stacked set of interactive headings that each reveal a section of content.
Examples
Basic
| Prop | Default | Type | Description |
|---|---|---|---|
items | [] | array | Set the accordion items. |
item.value | - | string | The unique value of the item used for rendering and state tracking |
item.label | - | string | The label of the accordion item |
item.content | - | string | The content of the accordion item |
To avoid conflicts, please do not the use reserved values header, trigger, content, item, and default for the value of an accordion item. Doing so may cause slot conflicts.
Mounted
| Prop | Default | Type | Description |
|---|---|---|---|
unmountOnHide | true | boolean | Set to false to keep the content of the accordion mounted, even if the accordion is closed. |
item.unmountOnHide | true | boolean | Like unmountOnHide, but applies to a specific item. Has no effect if unmountOnHide is false |
⚡ By default, the accordion's content is not rendered until it is opened for performance reasons. To render the content when the page loads, even if the accordion is closed for SEO purposes, set the
unmountOnHideprop tofalse.
If you have a lot of accordion items, it is not recommended to use the mounted prop because it affects the performance of the page, instead use the item.mount prop to mount the content of a specific item if needed.
Multiple
| Prop | Default | Type | Description |
|---|---|---|---|
type | single | 'single' | 'multiple' | Expand a single item or multiple items at a time |
Default open
| Prop | Default | Type | Description |
|---|---|---|---|
defaultValue | - | string | string[] | Open the specified items whose value matches the input. |
Use type="multiple" prop when using default-value to open multiple items by default.
Color
Since we use the Button component for the accordion label, you can use _accordionTrigger prop to pass button props, like btn to change the color of the label. See Button for more information.
:_accordion-trigger="{ btn: 'text-{color}' }" prop is basically from Button component. You can use it to change the color of the label.
Icon
| Prop | Default | Type | Description |
|---|---|---|---|
_accordionTrigger.leading | - | string | Set a custom leading icon for the accordion. |
_accordionTrigger.trailing | - | string | Set a custom trailing icon for the accordion. |
item._accordionTrigger.leading | - | string | Set a custom leading icon for a specific item. |
item._accordionTrigger.trailing | - | string | Set a custom trailing icon for a specific item. |
If no trailing icon is given, it will be used for both open and close states and will animate upside down automatically.
Use the unocss variants group-data-[state=open]/accordion-trigger and group-data-[state=closed]/accordion-trigger to select the icon based on the open/close state of the accordion item.
Reverse
| Prop | Default | Type | Description |
|---|---|---|---|
_accordionTrigger.reverse | - | boolean | Switch the position of the trailing and leading icons. |
item._accordionTrigger.reverse | - | boolean | Switch the position of the trailing and leading icons of a specific item. |
reverse prop is basically from Button component. You can use it to switch the position of the trailing and leading icons.
Variant
| Prop | Default | Type | Description |
|---|---|---|---|
accordion | border divider | {variant} | The variant of the accordion. |
| Variant | Description |
|---|---|
border | A bordered accordion. |
divider | An accordion with dividers between items. |
~ | An unstyled accordion. |
Customization
You can customize the accordion using the
unaprop and utility classes.
Slots
| Name | Props | Description |
|---|---|---|
default | { modelValue } | Fill with AccordionItem components |
item | { open, item, index } | The item of the accordion. |
header | { open, item, index } | The header of the accordion containing the trigger |
trigger | { open, item, index } | The trigger button. |
content | { open, item, index } | The content of the accordion. |
| Slot prop | Description |
|---|---|
modelValue | the value of the item(s) currently open |
open | allows you to access the open state of the item. |
item | allows you to access the item object. |
index | allows you to access the index of the item. To identify items, prefer using item.value. |
All slots can be prefixed with the value of an item to target a specific item. For example, to customize the content of the item with the value 1, use the 1-content slot.
| Slot name | Description |
|---|---|
${value} | The render slot of a specific item. Default value renders the other item's slots. |
${value}-header | The header of a specific item |
${value}-trigger | The trigger of a specific item |
${value}-content | The content of a specific item |