Accordion
A set of collapsible panels with headings.
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Accordion } from '@vase-ui/vue/accordion';
import styles from '../../_index.module.css';
const PlusIcon: FunctionalComponent = () =>
h(
'svg',
{
width: '16',
height: '16',
viewBox: '0 0 16 16',
fill: 'none',
stroke: 'currentColor',
'stroke-linecap': 'square',
'stroke-linejoin': 'round',
style: { display: 'block' },
},
[h('path', { d: 'M1.5 8h13M8 14.5v-13' })],
);
// The panel animates its height from 0 to the height of its content, and back.
const enterFromClass = styles.PanelClosed;
const enterToClass = styles.PanelOpen;
const leaveFromClass = styles.PanelOpen;
const leaveToClass = styles.PanelClosed;
const panelTransition = { enterFromClass, enterToClass, leaveFromClass, leaveToClass };
</script>
<template>
<Accordion.Root :class="styles.Accordion">
<Accordion.Item :class="styles.Item">
<Accordion.Header as="h2" :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
What is Vase UI?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel :class="styles.Panel">
<div :class="styles.Content">
Vase UI is a library of unstyled, accessible Vue components for design systems and web
apps.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item :class="styles.Item">
<Accordion.Header as="h2" :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
How do I get started?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel :class="styles.Panel">
<div :class="styles.Content">
Head to the “Quick start” guide in the docs. If you’ve used unstyled libraries before,
you’ll feel at home.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item :class="styles.Item">
<Accordion.Header as="h2" :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
Can I use it for my project?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel :class="styles.Panel">
<div :class="styles.Content">Yes. Vase UI is free and open source.</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
</Accordion.Root>
</template>.Accordion {
box-sizing: border-box;
display: flex;
max-width: 20rem;
width: 100%;
flex-direction: column;
border: 1px solid oklch(14.5% 0 0deg);
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
color: white;
}
}
.Item {
& + & {
border-top: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
}
}
}
.Header {
margin: 0;
}
.Trigger {
box-sizing: border-box;
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 0.5rem 0.75rem;
margin: 0;
border: none;
border-radius: 0;
background-color: transparent;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.25rem;
text-align: left;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
position: relative;
outline: 2px solid oklch(14.5% 0 0deg);
z-index: 1;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Icon {
transition: transform 100ms ease-out;
[aria-expanded='true'] > & {
transform: rotate(45deg);
}
}
.Panel {
box-sizing: border-box;
overflow: hidden;
font-size: 0.875rem;
line-height: 1.25rem;
transition: height 150ms ease-out;
}
.PanelOpen {
height: var(--accordion-panel-height);
}
.PanelClosed {
height: 0;
}
/* No size and no transition: at a reveal by find-in-page, the browser then scrolls to the text. */
.FoundPanel {
box-sizing: border-box;
font-size: 0.875rem;
line-height: 1.25rem;
}
.Content {
padding: 0.5rem 0.75rem;
}<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Accordion } from '@vase-ui/vue/accordion';
const PlusIcon: FunctionalComponent = () =>
h(
'svg',
{
width: '16',
height: '16',
viewBox: '0 0 16 16',
fill: 'none',
stroke: 'currentColor',
'stroke-linecap': 'square',
'stroke-linejoin': 'round',
style: { display: 'block' },
},
[h('path', { d: 'M1.5 8h13M8 14.5v-13' })],
);
// The panel animates its height from 0 to the height of its content, and back.
const enterFromClass = 'h-0';
const enterToClass = 'h-[var(--accordion-panel-height)]';
const leaveFromClass = 'h-[var(--accordion-panel-height)]';
const leaveToClass = 'h-0';
const panelTransition = { enterFromClass, enterToClass, leaveFromClass, leaveToClass };
</script>
<template>
<Accordion.Root
class="flex w-full max-w-80 flex-col border border-neutral-950 text-neutral-950 dark:border-white dark:text-white"
>
<Accordion.Item>
<Accordion.Header as="h2">
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
What is Vase UI?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel
class="overflow-hidden text-sm transition-[height] duration-150 ease-[ease-out]"
>
<div class="px-3 py-2">
Vase UI is a library of unstyled, accessible Vue components for design systems and web
apps.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item class="border-t border-neutral-950 dark:border-white">
<Accordion.Header as="h2">
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
How do I get started?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel
class="overflow-hidden text-sm transition-[height] duration-150 ease-[ease-out]"
>
<div class="px-3 py-2">
Head to the “Quick start” guide in the docs. If you’ve used unstyled libraries before,
you’ll feel at home.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item class="border-t border-neutral-950 dark:border-white">
<Accordion.Header as="h2">
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
Can I use it for my project?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel
class="overflow-hidden text-sm transition-[height] duration-150 ease-[ease-out]"
>
<div class="px-3 py-2">Yes. Vase UI is free and open source.</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
</Accordion.Root>
</template>Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { Accordion } from '@vase-ui/vue/accordion';
</script>
<template>
<Accordion.Root>
<Accordion.Item>
<Accordion.Header>
<Accordion.Trigger />
</Accordion.Header>
<Accordion.Panel />
</Accordion.Item>
</Accordion.Root>
</template>Examples
Open multiple panels
Set the multiple prop to let the user open more than one panel at a time.
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Accordion } from '@vase-ui/vue/accordion';
import styles from '../../_index.module.css';
const PlusIcon: FunctionalComponent = () =>
h(
'svg',
{
width: '16',
height: '16',
viewBox: '0 0 16 16',
fill: 'none',
stroke: 'currentColor',
'stroke-linecap': 'square',
'stroke-linejoin': 'round',
style: { display: 'block' },
},
[h('path', { d: 'M1.5 8h13M8 14.5v-13' })],
);
// The panel animates its height from 0 to the height of its content, and back.
const enterFromClass = styles.PanelClosed;
const enterToClass = styles.PanelOpen;
const leaveFromClass = styles.PanelOpen;
const leaveToClass = styles.PanelClosed;
const panelTransition = { enterFromClass, enterToClass, leaveFromClass, leaveToClass };
</script>
<template>
<Accordion.Root :class="styles.Accordion" multiple>
<Accordion.Item :class="styles.Item">
<Accordion.Header :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
What is Vase UI?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel :class="styles.Panel">
<div :class="styles.Content">
Vase UI is a library of unstyled, accessible Vue components for design systems and web
apps.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item :class="styles.Item">
<Accordion.Header :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
How do I get started?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel :class="styles.Panel">
<div :class="styles.Content">
Head to the “Quick start” guide in the docs. If you’ve used unstyled libraries before,
you’ll feel at home.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item :class="styles.Item">
<Accordion.Header :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
Can I use it for my project?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel :class="styles.Panel">
<div :class="styles.Content">Yes. Vase UI is free and open source.</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
</Accordion.Root>
</template>.Accordion {
box-sizing: border-box;
display: flex;
max-width: 20rem;
width: 100%;
flex-direction: column;
border: 1px solid oklch(14.5% 0 0deg);
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
color: white;
}
}
.Item {
& + & {
border-top: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
}
}
}
.Header {
margin: 0;
}
.Trigger {
box-sizing: border-box;
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 0.5rem 0.75rem;
margin: 0;
border: none;
border-radius: 0;
background-color: transparent;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.25rem;
text-align: left;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
position: relative;
outline: 2px solid oklch(14.5% 0 0deg);
z-index: 1;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Icon {
transition: transform 100ms ease-out;
[aria-expanded='true'] > & {
transform: rotate(45deg);
}
}
.Panel {
box-sizing: border-box;
overflow: hidden;
font-size: 0.875rem;
line-height: 1.25rem;
transition: height 150ms ease-out;
}
.PanelOpen {
height: var(--accordion-panel-height);
}
.PanelClosed {
height: 0;
}
/* No size and no transition: at a reveal by find-in-page, the browser then scrolls to the text. */
.FoundPanel {
box-sizing: border-box;
font-size: 0.875rem;
line-height: 1.25rem;
}
.Content {
padding: 0.5rem 0.75rem;
}<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Accordion } from '@vase-ui/vue/accordion';
const PlusIcon: FunctionalComponent = () =>
h(
'svg',
{
width: '16',
height: '16',
viewBox: '0 0 16 16',
fill: 'none',
stroke: 'currentColor',
'stroke-linecap': 'square',
'stroke-linejoin': 'round',
style: { display: 'block' },
},
[h('path', { d: 'M1.5 8h13M8 14.5v-13' })],
);
// The panel animates its height from 0 to the height of its content, and back.
const enterFromClass = 'h-0';
const enterToClass = 'h-[var(--accordion-panel-height)]';
const leaveFromClass = 'h-[var(--accordion-panel-height)]';
const leaveToClass = 'h-0';
const panelTransition = { enterFromClass, enterToClass, leaveFromClass, leaveToClass };
</script>
<template>
<Accordion.Root
class="flex w-full max-w-80 flex-col border border-neutral-950 text-neutral-950 dark:border-white dark:text-white"
multiple
>
<Accordion.Item>
<Accordion.Header>
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
What is Vase UI?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel
class="overflow-hidden text-sm transition-[height] duration-150 ease-[ease-out]"
>
<div class="px-3 py-2">
Vase UI is a library of unstyled, accessible Vue components for design systems and web
apps.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item class="border-t border-neutral-950 dark:border-white">
<Accordion.Header>
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
How do I get started?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel
class="overflow-hidden text-sm transition-[height] duration-150 ease-[ease-out]"
>
<div class="px-3 py-2">
Head to the “Quick start” guide in the docs. If you’ve used unstyled libraries before,
you’ll feel at home.
</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
<Accordion.Item class="border-t border-neutral-950 dark:border-white">
<Accordion.Header>
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
Can I use it for my project?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Transition v-bind="panelTransition">
<Accordion.Panel
class="overflow-hidden text-sm transition-[height] duration-150 ease-[ease-out]"
>
<div class="px-3 py-2">Yes. Vase UI is free and open source.</div>
</Accordion.Panel>
</Transition>
</Accordion.Item>
</Accordion.Root>
</template>Hidden until found
The hiddenUntilFound prop hides the closed panels with hidden="until-found". The find-in-page search of the browser can then search their contents and open the panel that has a match. Set the prop on each <Accordion.Panel>, or one time on <Accordion.Root> for all panels.
To try it, press Ctrl+F (Cmd+F on macOS) and search for "restocking". The browser opens the closed panel that has the match. With the prop, a closed panel always stays in the DOM, so search engines can also index its contents.
A browser that does not support hidden="until-found" keeps the panels hidden until their trigger opens them, and find-in-page skips the contents. The panels of this demo have no <Transition> and no size transition. The Collapsible page gives the reasons.
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Accordion } from '@vase-ui/vue/accordion';
import styles from '../../_index.module.css';
const PlusIcon: FunctionalComponent = () =>
h(
'svg',
{
width: '16',
height: '16',
viewBox: '0 0 16 16',
fill: 'none',
stroke: 'currentColor',
'stroke-linecap': 'square',
'stroke-linejoin': 'round',
style: { display: 'block' },
},
[h('path', { d: 'M1.5 8h13M8 14.5v-13' })],
);
</script>
<template>
<Accordion.Root :class="styles.Accordion" hidden-until-found>
<Accordion.Item :class="styles.Item">
<Accordion.Header :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
How long does shipping take?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel :class="styles.FoundPanel">
<div :class="styles.Content">
Standard shipping takes 3–5 business days. Express delivery arrives in 1–2 business days.
</div>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item :class="styles.Item">
<Accordion.Header :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
What is your return policy?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel :class="styles.FoundPanel">
<div :class="styles.Content">
You can return any item within 30 days of delivery. Opened items may be subject to a 10%
restocking fee.
</div>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item :class="styles.Item">
<Accordion.Header :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
Do you ship internationally?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel :class="styles.FoundPanel">
<div :class="styles.Content">
Yes, we ship to over 40 countries. International orders typically arrive within 7–14
business days.
</div>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item :class="styles.Item">
<Accordion.Header :class="styles.Header">
<Accordion.Trigger :class="styles.Trigger">
How can I track my order?
<PlusIcon :class="styles.Icon" />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel :class="styles.FoundPanel">
<div :class="styles.Content">
Once your order ships, you’ll receive a tracking link by email. Tracking updates can take
up to 24 hours to appear.
</div>
</Accordion.Panel>
</Accordion.Item>
</Accordion.Root>
</template>.Accordion {
box-sizing: border-box;
display: flex;
max-width: 20rem;
width: 100%;
flex-direction: column;
border: 1px solid oklch(14.5% 0 0deg);
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
color: white;
}
}
.Item {
& + & {
border-top: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
}
}
}
.Header {
margin: 0;
}
.Trigger {
box-sizing: border-box;
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 0.5rem 0.75rem;
margin: 0;
border: none;
border-radius: 0;
background-color: transparent;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.25rem;
text-align: left;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
position: relative;
outline: 2px solid oklch(14.5% 0 0deg);
z-index: 1;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Icon {
transition: transform 100ms ease-out;
[aria-expanded='true'] > & {
transform: rotate(45deg);
}
}
.Panel {
box-sizing: border-box;
overflow: hidden;
font-size: 0.875rem;
line-height: 1.25rem;
transition: height 150ms ease-out;
}
.PanelOpen {
height: var(--accordion-panel-height);
}
.PanelClosed {
height: 0;
}
/* No size and no transition: at a reveal by find-in-page, the browser then scrolls to the text. */
.FoundPanel {
box-sizing: border-box;
font-size: 0.875rem;
line-height: 1.25rem;
}
.Content {
padding: 0.5rem 0.75rem;
}<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Accordion } from '@vase-ui/vue/accordion';
const PlusIcon: FunctionalComponent = () =>
h(
'svg',
{
width: '16',
height: '16',
viewBox: '0 0 16 16',
fill: 'none',
stroke: 'currentColor',
'stroke-linecap': 'square',
'stroke-linejoin': 'round',
style: { display: 'block' },
},
[h('path', { d: 'M1.5 8h13M8 14.5v-13' })],
);
</script>
<template>
<Accordion.Root
class="flex w-full max-w-80 flex-col border border-neutral-950 text-neutral-950 dark:border-white dark:text-white"
hidden-until-found
>
<Accordion.Item>
<Accordion.Header>
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
How long does shipping take?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel class="text-sm">
<div class="px-3 py-2">
Standard shipping takes 3–5 business days. Express delivery arrives in 1–2 business days.
</div>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item class="border-t border-neutral-950 dark:border-white">
<Accordion.Header>
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
What is your return policy?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel class="text-sm">
<div class="px-3 py-2">
You can return any item within 30 days of delivery. Opened items may be subject to a 10%
restocking fee.
</div>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item class="border-t border-neutral-950 dark:border-white">
<Accordion.Header>
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
Do you ship internationally?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel class="text-sm">
<div class="px-3 py-2">
Yes, we ship to over 40 countries. International orders typically arrive within 7–14
business days.
</div>
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item class="border-t border-neutral-950 dark:border-white">
<Accordion.Header>
<Accordion.Trigger
class="group flex w-full items-center justify-between gap-4 bg-transparent px-3 py-2 text-left text-sm font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 focus-visible:relative focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white dark:text-white dark:hover:not-disabled:bg-neutral-800"
>
How can I track my order?
<PlusIcon
class="shrink-0 transition-transform duration-100 ease-[ease-out] group-aria-expanded:rotate-45"
/>
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel class="text-sm">
<div class="px-3 py-2">
Once your order ships, you’ll receive a tracking link by email. Tracking updates can take
up to 24 hours to appear.
</div>
</Accordion.Panel>
</Accordion.Item>
</Accordion.Root>
</template>Animate the panels
Put each panel in a <Transition>, as the demo at the top of this page does. Before each open and each close, a panel writes the size of its content in the CSS variables --accordion-panel-height and --accordion-panel-width. The Collapsible page shows the classes. When one item opens and another closes, one panel leaves while the other enters.
API reference
Accordion.Root
Groups all parts of the accordion.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | AccordionValue<Value> | null | undefined | The values of the open items at the mount of an uncontrolled root. null is no value. | |
disabled | boolean | undefined | false | The user cannot open or close an item with its trigger. |
hiddenUntilFound | boolean | undefined | false | A closed panel stays in the DOM with hidden="until-found", so that find-in-page of the
browser can find its text and open it. The hiddenUntilFound of a panel wins. |
keepMounted | boolean | undefined | false | A closed panel stays in the DOM, with hidden and inert, so its content keeps its state, and
the server HTML has it. <Transition> does not animate such a panel: animate it with CSS on
[hidden]. The keepMounted of a panel wins. |
modelValue | AccordionValue<Value> | null | undefined | The values of the open items. v-model binds it. With null, no item is open, and the root
stays controlled. | |
multiple | boolean | undefined | false | More than one item can be open at one time. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: AccordionRootState<Value> | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: AccordionRootState<Value> | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Events
| Event | Arguments | Description |
|---|---|---|
valueChange | [value: AccordionValue<Value>, details: AccordionRootChangeEventDetails] | The user opens or closes an item: trigger-press for a press of a trigger, none for a reveal
by find-in-page. The openChange of the item comes first. details.cancel() keeps the value as
it is. |
update:modelValue | [value: AccordionValue<Value>] | Comes after valueChange, unless a listener cancels the change. v-model uses it. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-disabled] | The accordion is disabled. |
Accordion.Item
Groups an accordion header with the corresponding panel.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot open or close the item with its trigger. A disabled root also disables it. |
value | any | The value of the item in the value of the root. With none, the item has a generated value. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: AccordionItemState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: AccordionItemState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Events
| Event | Arguments | Description |
|---|---|---|
openChange | [open: boolean, details: AccordionItemChangeEventDetails] | The user opens or closes the item. It comes before the valueChange of the root.
details.cancel() keeps the item as it is. An item that another item closes emits nothing. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-open] | The panel of the item is open. |
[data-disabled] | The item or the accordion is disabled. |
Accordion.Header
A heading that labels the corresponding panel. Give it another heading level with as.
Renders an <h3> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: AccordionItemState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: AccordionItemState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-open] | The panel of the item is open. |
[data-disabled] | The item or the accordion is disabled. |
Accordion.Trigger
A button that opens and closes the corresponding panel.
Renders a <button> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot press the trigger. A disabled item or root also disables it. |
id | string | undefined | The panel names the trigger by this id in aria-labelledby. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: AccordionTriggerState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: AccordionTriggerState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-expanded="true"] | The panel is open. |
:disabled | The trigger is a native button, and the trigger, the item, the accordion or a fieldset around it is disabled. |
[aria-disabled="true"] | The trigger is another element, and the trigger, the item or the accordion is disabled. |
Accordion.Panel
A collapsible panel with the accordion item contents. With more than about six panels that can
be open at one time, give each panel another role, such as group.
Renders a <div> element with the role region.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
hiddenUntilFound | boolean | undefined | A closed panel stays in the DOM with hidden="until-found", so that find-in-page of the
browser can find its text and open it. With none, the root decides. | |
id | string | undefined | The trigger names the panel by this id in aria-controls. | |
keepMounted | boolean | undefined | A closed panel stays in the DOM, with hidden and inert, so its content keeps its state, and
the server HTML has it. <Transition> does not animate such a panel: animate it with CSS on
[hidden]. With none, the root decides. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: AccordionItemState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: AccordionItemState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[hidden] | The panel is closed, and keepMounted or hiddenUntilFound keeps it in the DOM. |
[data-disabled] | The item or the accordion is disabled. |
CSS variables
| Variable | Description |
|---|---|
--accordion-panel-height | The height of the content of the panel, in pixels. The panel writes it before each open and each close. |
--accordion-panel-width | The width of the content of the panel, in pixels. The panel writes it before each open and each close. |
Differences from Base UI
Vase UI ports Accordion from Base UI 1.9.0.
API
| Base UI | Vase UI |
|---|---|
Accordion.Root prop loopFocus | Base UI deprecated the prop, and it has no effect. |
Accordion.Root prop orientation | Base UI deprecated the prop, and it does not change the keyboard. The parts have no state orientation and no data-orientation, which is always vertical. |
Accordion.Root | The root has no data-orientation, which is always vertical. |
Accordion.Item | The index of your v-for gives the index, and CSS has :nth-child(), so the state has no index. !state.open gives hidden, and after-leave of <Transition> gives the end of a close, so the state has no hidden. The state has no orientation, which is always vertical. The item has no data-index. |
Accordion.Header | The index of your v-for gives the index, and CSS has :nth-child(), so the state has no index. !state.open gives hidden, and after-leave of <Transition> gives the end of a close, so the state has no hidden. The state has no orientation, which is always vertical. The header has no data-index. |
Accordion.Trigger | The trigger reads the element that it renders, so it has no nativeButton. The index of your v-for gives the index, and CSS has :nth-child(), so the state has no index. !state.open gives hidden, and after-leave of <Transition> gives the end of a close, so the state has no hidden. The state has no orientation, which is always vertical. CSS selects [aria-expanded="true"], and :disabled on a native button or [aria-disabled="true"] on another element, so the trigger has no data-panel-open and no data-disabled. The trigger has no data-index. |
Accordion.Panel prop hiddenUntilFound | An absent hiddenUntilFound takes the value of Accordion.Root, and false overrides it. Vue gives an absent Boolean prop the value false, so the declared default is undefined. With no value on the root, the part uses false, the default of Base UI. |
Accordion.Panel prop keepMounted | An absent keepMounted takes the value of Accordion.Root, and false overrides it. Vue gives an absent Boolean prop the value false, so the declared default is undefined. With no value on the root, the part uses false, the default of Base UI. |
Accordion.Panel | <Transition> around the panel animates it, so the state has no transitionStatus, and the panel has no data-starting-style and no data-ending-style. The index of your v-for gives the index, and CSS has :nth-child(), so the state has no index. !state.open gives hidden, and after-leave of <Transition> gives the end of a close, so the state has no hidden. The state has no orientation, which is always vertical. CSS selects an open panel with :not([hidden]), so the panel has no data-open. The panel has no data-index and no data-orientation. |
Behavior
| Vase UI | Evidence |
|---|---|
A panel with an empty id has a generated id. The open trigger names that id in aria-controls. Base UI gives the panel id="" then, so aria-controls names no element. | |
Accordion.Root, ToggleGroup and CheckboxGroup read null in modelValue as an empty array, and the part stays controlled. A press emits an array that holds the value of the item, and the part keeps the value of the parent. A change of modelValue to null empties the part, and the part does not show defaultValue. A form reset does not change a CheckboxGroup whose modelValue is null, and it emits nothing. defaultValue reads null as an empty array too. Vue accepts null for an optional prop with no warning, so a v-model whose ref becomes null gives null to the part. Base UI throws a TypeError for a null value: Accordion.Root and CheckboxGroup at the render, and ToggleGroup with multiple at a press. Without multiple, ToggleGroup of Base UI reads null as an empty array, as Vase UI does. |
|
hiddenUntilFound keeps a closed panel in the DOM with hidden="until-found", because find-in-page needs the content. keepMounted of false changes nothing then, and the part gives no warning. Base UI gives a warning in a development build. |
|
A button part knows the element of a component in as or of the element slot only at the mount, and it needs no prop that says what the element is. Until the mount, the element has the attributes that suit a <button> and each other element: type="button", role="button", a tab stop, and the disabled state of both. So in the server HTML, Tab reaches a <div> before a lazy hydration, and a <button> does not submit its form. At the mount, the part keeps the attributes of its element. Base UI needs nativeButton set to false for an element that is not a <button>. |
|
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.