Accordion
Data displaySections that open and close under their headings: <Accordion.Root> (type="single" or "multiple", bind:value) holds Accordion.Items (value), each with an Accordion.Trigger (its heading, level 3 by default) and an Accordion.Content. Enter or Space toggles a section; arrow keys move between headings.
import { Accordion } from '@limerdev/zest'; Use for
Long content people scan by heading and open as needed: FAQs, a settings page with many groups, details under a summary.
Don't
Content everyone needs, or that is short enough to show: don't hide it. Switching between views of the same thing: use
Tabs. A single open/close section: use Collapsible.Examples
Faq
type="single" keeps one section open; collapsible lets it close again.
Per started half hour, from approved weeks only.
The project lead, or the account's owner when there is none.
Ask the approver to reopen it; the invoice updates when it is approved again.
<script lang="ts">
import { Accordion } from '@limerdev/zest';
type Question = { value: string; question: string; answer: string };
const questions: Question[] = [
{
value: 'billing',
question: 'How is time billed?',
answer: 'Per started half hour, from approved weeks only.'
},
{
value: 'approval',
question: 'Who approves a week?',
answer: "The project lead, or the account's owner when there is none."
},
{
value: 'late',
question: 'Can I change an approved week?',
answer: 'Ask the approver to reopen it; the invoice updates when it is approved again.'
}
];
</script>
<Accordion.Root type="single" class="w-full max-w-md">
{#each questions as item (item.value)}
<Accordion.Item value={item.value}>
<Accordion.Trigger>{item.question}</Accordion.Trigger>
<Accordion.Content class="text-muted">{item.answer}</Accordion.Content>
</Accordion.Item>
{/each}
</Accordion.Root> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
Accordion.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Whether the accordion is disabled or not. |
| loop | boolean | true | Whether to loop through the accordion items when navigating with the arrow keys. |
| onValueChange | OnChangeFn<string> | OnChangeFn<string[]> | โ | A callback function called when the value changes. |
| orientation | "horizontal" | "vertical" | "vertical" | The orientation of the accordion. |
| type required | "multiple" | "single" | โ | The type of accordion. If set to 'multiple', the accordion will allow multiple items to be open at the same time. If set to 'single', the accordion will only allow a single item to be open. |
| value bindable | string | string[] | "" | The value of the currently open accordion item. |
Accordion.Item
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Whether the accordion item is disabled, which prevents users from interacting with it. |
| value | string | โ | The value of the accordion item. This is used to identify if the item is open or closed. If not provided, a unique ID will be generated for this value. |
Accordion.Trigger
| Prop | Type | Default | Description |
|---|---|---|---|
| level | 1 | 2 | 3 | 4 | 5 | 6 | 3 | The heading level the trigger sits in, to fit the page's outline. |
Accordion.Content
| Prop | Type | Default | Description |
|---|---|---|---|
| forceMount | boolean | true | Whether to forcefully mount the content, regardless of the open state. This is useful if you want to use Svelte transitions for the content. |
| hiddenUntilFound | boolean | false | Whether to allow the browser to expand the content when searching for content within the panel via the browser's built-in search functionality. When true, this prop will override the forceMount prop. |