Accordion
A set of collapsible panels with headings and content.
<script lang="ts">
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "coss-svelte";
const items = [
{
content:
"Base UI is a library of high-quality unstyled React components for design systems and web apps.",
id: "1",
title: "What is Base UI?",
},
{
content:
"Head to the \u201CQuick start\u201D guide in the docs. If you\u2019ve used unstyled libraries before, you\u2019ll feel at home.",
id: "2",
title: "How do I get started?",
},
{
content: "Of course! Base UI is free and open source.",
id: "3",
title: "Can I use it for my project?",
},
];
</script>
<Accordion class="w-full" value="3">
{#each items as item}
<AccordionItem value={item.id}>
<AccordionTrigger>{item.title}</AccordionTrigger>
<AccordionContent>{item.content}</AccordionContent>
</AccordionItem>
{/each}
</Accordion>
Installation
Install the component package, shared coss-svelte theme, and Bits UI peer.
npm install coss-svelte @coss-svelte/theme bits-uiUsage
Import the Svelte component exports directly from the package.
import { Accordion, AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger } from "coss-svelte";Anatomy
- Accordion
- AccordionContent
- AccordionHeader
- AccordionItem
- AccordionTrigger
API Reference
Accordion
A set of collapsible panels with headings and content.
Signatures
{ type?: "single"; value?: string; onValueChange?: OnChangeFn<string> }{ type: "multiple"; value?: string[]; onValueChange?: OnChangeFn<string[]> }| Prop | Type | Default | Description |
|---|---|---|---|
type | "single" | "multiple" | "single" | Behavior, selection, or HTML type passed to the underlying control. |
bind:value | string | string[] | "" | Current value for the component. Bind with `bind:value` when supported. |
items | AccordionItem[] | [] | Items rendered by the component's built-in fallback composition. |
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Accordion.Root.
AccordionContent
Wraps the primary content for the parent component.
| Prop | Type | Default | Description |
|---|---|---|---|
forceMount | boolean | true | Keeps content mounted while closed so transitions can complete. |
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Accordion.Content.
AccordionHeader
Groups heading content for the parent component.
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Accordion.Header.
AccordionItem
Renders one selectable or repeated item.
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Accordion.Item.
AccordionTrigger
Renders the control that opens, closes, or selects related content.
children : Snippet<[]>child : Snippet<[{ props: Record<string, unknown> }]>bind:ref : HTMLElement | nullInherits from Bits UI Accordion.Trigger.
Implementation Details
- Status
- Stable
- Foundation
- bits
- Category
- Layout & Navigation
- Particles
- 4