Display
Collapsible
Shows and hides one block of content behind a trigger. The parts are unstyled, so you decide what the trigger looks like.
import * as Collapsible from '@statix/ui/collapsible';Examples
Show more
Style the trigger with buttonVariants. Read data-state="open" on the trigger to turn the chevron.
Last backup today at 03:10
- 12 November, 03:10
- 11 November, 03:10
- 10 November, 03:10
<script lang="ts">
import * as Collapsible from '@statix/ui/collapsible';
import { buttonVariants } from '@statix/ui/button';
import ChevronDownIcon from '@lucide/svelte/icons/chevron-down';
const older = ['12 November, 03:10', '11 November, 03:10', '10 November, 03:10'];
</script>
<Collapsible.Root class="w-full max-w-md">
<div class="flex items-center justify-between gap-4">
<p class="text-body text-ink">Last backup today at 03:10</p>
<Collapsible.Trigger class={buttonVariants({ variant: 'ghost', size: 'sm', class: 'group' })}>
Older backups
<ChevronDownIcon
data-icon="inline-end"
class="transition-transform duration-200 group-data-[state=open]:rotate-180"
/>
</Collapsible.Trigger>
</div>
<Collapsible.Content>
<ul class="mt-3 divide-y divide-border rounded-lg bg-card px-4">
{#each older as backup (backup)}
<li class="py-3 text-body text-ink-2">{backup}</li>
{/each}
</ul>
</Collapsible.Content>
</Collapsible.Root>Technical details
Tuck rarely needed facts into a card and bind open to control it from outside.
yoga-berger.de
WordPress Hosting, online since 2021.
- PHP
- 8.3
- Server
- web-04.statix.de
- SSL
- Valid until 14 February 2027
<script lang="ts">
import * as Collapsible from '@statix/ui/collapsible';
import ChevronRightIcon from '@lucide/svelte/icons/chevron-right';
let open = $state(false);
</script>
<div class="w-full max-w-md rounded-card bg-card p-7 shadow-card">
<h3 class="text-title text-ink">yoga-berger.de</h3>
<p class="mt-1 text-body text-ink-2">WordPress Hosting, online since 2021.</p>
<Collapsible.Root bind:open class="mt-5 border-t border-border pt-4">
<Collapsible.Trigger
class="group flex w-full items-center gap-2 rounded-sm text-label text-ink outline-none focus-visible:ring-3 focus-visible:ring-ring/40"
>
<ChevronRightIcon
class="size-4 transition-transform duration-200 group-data-[state=open]:rotate-90"
/>
Technical details
</Collapsible.Trigger>
<Collapsible.Content>
<dl class="mt-3 grid grid-cols-[auto_1fr] gap-x-6 gap-y-2 text-small">
<dt class="text-muted-foreground">PHP</dt>
<dd class="text-ink">8.3</dd>
<dt class="text-muted-foreground">Server</dt>
<dd class="text-ink">web-04.statix.de</dd>
<dt class="text-muted-foreground">SSL</dt>
<dd class="text-ink">Valid until 14 February 2027</dd>
</dl>
</Collapsible.Content>
</Collapsible.Root>
</div>Guidelines
Do
- Use it for one optional block, such as older backups or technical details.
- Say in the trigger what opens: "Older backups", not "More".
Don't
- Do not use it for a list of questions. Use Accordion.
- Do not hide errors or required fields inside it.
Accessibility
- Collapsible.Trigger is a <button> with aria-expanded and aria-controls.
- Enter and Space toggle the content.
- Closed content is removed from the DOM unless you pass forceMount.
API reference
Collapsible.Root
renders<div> and accepts its attributes| Prop | Type | Default |
|---|---|---|
open bind | boolean Open or closed. | false |
onOpenChange | (open: boolean) => void Called when the state changes. | – |
disabled | boolean Stops the trigger from toggling. | false |
ref bind | HTMLDivElement | null The root element. | – |
class | ClassValue Classes for the root. | – |
| Data attribute | Meaning |
|---|---|
data-slot="collapsible" | Always present. |
data-state | "open" or "closed". |
Collapsible.Trigger
renders<button> and accepts its attributes| Prop | Type | Default |
|---|---|---|
child | Snippet<[{ props }]> Render your own element, such as a Button, and spread props on it. | – |
ref bind | HTMLButtonElement | null The button. | – |
class | ClassValue Classes for the button. | – |
| Data attribute | Meaning |
|---|---|
data-slot="collapsible-trigger" | Always present. |
data-state | "open" or "closed". |
Collapsible.Content
renders<div> and accepts its attributes| Prop | Type | Default |
|---|---|---|
forceMount | boolean Keeps the content in the DOM when closed, for your own animations. | false |
ref bind | HTMLDivElement | null The content element. | – |
class | ClassValue Classes for the content. | – |
| Data attribute | Meaning |
|---|---|
data-slot="collapsible-content" | Always present. |
data-state | "open" or "closed". |