# Accordion A container with multiple collapsible sections where only one section can be expanded at a time. ## Usage Wrap one or more `Disclosure` children. ```svelte Content Content ``` If you do not need open/close animation or programmatic state tracking, native `
` elements already give exclusive single-open behavior on their own; reach for Accordion only when you need those extras. ## Anatomy The `class` attribute values represent `part` names. Other attributes represent their corresponding props. ```svelte
{#if children} {children} {:else} {#each items as item} {item.panel} {/each} {/if}
``` ### Dependency - [Disclosure](/docs/disclosure) ## Props | Name | Type | Default | Description | |---|---|---|---| | `items` | `AccordionItem[]` | - | Data-mode array of `AccordionItem`; each item has a unique `value` addressed by `current`, a `label` as string / `Snippet<[open, variant]>` / component, a `panel` as `Snippet<[variant]>` / component, and optional `inactive` | | `children` | `Snippet` | - | Declarative mode: place `` children directly; when both `children` and `items` are supplied, `children` wins | | `current` | `string` | - | Bindable `value` of the open item; `undefined` means all closed. Accordion is exclusive (at most one item open at a time) | | `styling` | `SVSClass` | - | Styling override | | `variant` | `SVSVariant` | `NEUTRAL` | Variant | | `disclosure` | `DisclosureProps` | - | Default props applied to the data-mode inner `Disclosure` | ## Styling To learn more, see [Styling](/docs/styling). ### Variant Management No automatic switching. ### Default Class Name `svs-accordion` Internal dependent components combine the parent class with their own default class names, resulting in multiple classes (e.g., `svs-accordion svs-disclosure`). ## Behavior Declarative `` children automatically coordinate exclusive open state through `current` and inherit the base `variant`/`styling`. ## Accessibility ### ARIA Roles and Attributes The component applies these automatically: - Accordion (`whole` `
`): `role="group"`. Each item is a `Disclosure` child. See [Disclosure](/docs/disclosure) for each item's ARIA attributes and keyboard behavior. ### Standards Basis Accordion items are built on native `
` / `` through Disclosure, so keyboard and assistive-technology support follows the browser standard for disclosure controls. See the [Concepts standards-first guidance](/docs/concepts) for the library's approach. ## Exports ### Types ```ts type AccordionComponent = { component: Component; props?: Record }; type AccordionItem = { value: string; // REQUIRED, unique within `items`. Addresses `current`. label: string | Snippet<[boolean, string]> | AccordionComponent; panel: Snippet<[string]> | AccordionComponent; inactive?: string | boolean; // (false) reason string OR true; forwarded to Disclosure }; interface AccordionProps { items?: AccordionItem[]; children?: Snippet; current?: string; // bindable, undefined = all closed styling?: SVSClass; variant?: SVSVariant; // (VARIANT.NEUTRAL) disclosure?: Omit; } type AccordionReqdProps = never; type AccordionBindProps = "current"; ``` ### Others No additional exports are available. ## Examples The example code uses Tailwind CSS along with `SVSClass`. ### Basic **Code** ```svelte src=AccordionBasic.svelte {#snippet panel1(_variant: string)} Diam facilisi consequat sadipscing in. Illum eleifend sit sit lorem takimata diam ut vel amet elitr duo. {/snippet} {#snippet panel2(_variant: string)} Justo sea et. Sea est accusam sanctus feugait sed dolore lorem consectetuer est. {/snippet} {#snippet panel3(_variant: string)} No dolore aliquip et aliquip sed lorem et qui nihil dolor sit lorem no sit. Esse sed ipsum et diam takimata. {/snippet} ``` ### With Interactive Variant **Code** ```svelte src=AccordionPract.svelte {#snippet label1(open: boolean, _variant: string)} First Item {@render icon(open)} {/snippet} {#snippet label2(open: boolean, _variant: string)} Second Item {@render icon(open)} {/snippet} {#snippet label3(open: boolean, _variant: string)} Third Item {@render icon(open)} {/snippet} {#snippet panel1(_variant: string)} Diam facilisi consequat sadipscing in. Illum eleifend sit sit lorem takimata diam ut vel amet elitr duo. {/snippet} {#snippet panel2(_variant: string)} Justo sea et. Sea est accusam sanctus feugait sed dolore lorem consectetuer est. {/snippet} {#snippet panel3(_variant: string)} No dolore aliquip et aliquip sed lorem et qui nihil dolor sit lorem no sit. Esse sed ipsum et diam takimata. {/snippet} {#snippet icon(open: boolean)}
{/snippet} ```