Collapsible
LayoutOne section that opens and closes: <Collapsible.Root> (bind:open) holds a Collapsible.Trigger (a button; render your own with the child snippet) and a Collapsible.Content, which slides open.
import { Collapsible } from '@limerdev/zest'; Use for
Optional detail under something visible: advanced options in a form, the lines behind a total, older entries.
Don't
Several sections under headings: use
Accordion. Content everyone needs: show it.Examples
Basic
Optional detail under a total. The trigger is your own Button through child.
Invoice 1042 · 12 400 kr
- Development · 24 h · 9 600 kr
- Design · 7 h · 2 800 kr
<script lang="ts">
import ChevronsUpDown from '@lucide/svelte/icons/chevrons-up-down';
import { Collapsible } from '@limerdev/zest';
</script>
<Collapsible.Root class="w-full max-w-sm">
<div class="flex items-center justify-between gap-4">
<p class="text-sm font-medium">Invoice 1042 · 12 400 kr</p>
<Collapsible.Trigger variant="ghost" size="icon-sm" aria-label="Show lines">
<ChevronsUpDown />
</Collapsible.Trigger>
</div>
<Collapsible.Content>
<ul class="mt-2 flex flex-col gap-1 text-sm text-muted">
<li>Development · 24 h · 9 600 kr</li>
<li>Design · 7 h · 2 800 kr</li>
</ul>
</Collapsible.Content>
</Collapsible.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).
Collapsible.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | Whether the collapsible is disabled. |
| onOpenChange | OnChangeFn<boolean> | – | A callback function called when the open state changes. |
| onOpenChangeComplete | OnChangeFn<boolean> | – | A callback function called when the open state changes complete. |
| open bindable | boolean | false | Whether the collapsible is open. |
Collapsible.Trigger
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg" | 'default' | The height and padding, from the theme's field size; the icon sizes are square. |
| variant | "link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost" | 'primary' | The look, by the theme's colour roles: primary for the main action, error for deleting, secondary, neutral and outline for the rest, ghost in toolbars, link for a navigation that looks like text. |
Collapsible.Content
| Prop | Type | Default | Description |
|---|---|---|---|
| forceMount | boolean | false | Whether to force mount the content to the DOM. |
| hiddenUntilFound | boolean | true | 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. |