Accordion
A vertically stacked set of interactive headings that each reveal an associated section of content.
Source code
Click here to see the source code for this component on GitHub. Feel free to copy it and adjust it for your own use.
Anatomy
Pass a list of items
to the component.
<template>
<UiAccordion :items />
</template>
<script lang="ts" setup>
const items = [];
</script>
Or use each part individually
<template>
<UiAccordion>
<UiAccordionItem>
<UiAccordionHeader>
<UiAccordionTrigger />
</UiAccordionHeader>
<UiAccordionContent />
</UiAccordionItem>
</UiAccordion>
</template>
Installation
npx ui-thing@latest add accordion
Usage
Basic
The most common way to use the accordion is by just passing an array of items to the items
prop. Each item should have a value
, title
, and content
.
Custom styling
If you want to change the way that the items look, you can do so by using the different components that the accordion is composed of.
Custom icon
You can change the icon
that is displayed based on the open state of an item. Just override the the trigger
slot and then override the icon
slot.
Origin UI Examples
These are some examples that I found today over here Origin UI. I think they are cool.
To use these examples you will have to copy the code and adjust it for your own use.