5 Collapsible
L4stIdi0t edited this page 2026-11-17 17:40:23 +01:00

Collapsible

Fully self-contained accessible disclosure — no UI dependency.

Styling inspired by melt-next's collapsible: a rounded trigger that lifts (shadow) when open, with the content panel tucked slightly inset beneath it, and a smooth slide open/close. A11y is correct ARIA on a native <button>:

  • aria-expanded reflects state, aria-controls/labelledby wire the pair
  • Enter/Space handled natively by the button

Layout · keyboard contract

<script lang="ts">
	import { Collapsible } from '@l4st/driftwood';
</script>
Light Dark
collapsible collapsible in dark mode

Props

Prop Type Default What it does
title required string — The trigger's label.
open boolean false Whether the panel is showing.
hiddenUntilFound boolean false Keep the closed panel in the page as hidden="until-found" rather than leaving it out: it is server-rendered, so search engines index it, and find-in-page opens it on a match. It then opens without the reveal.
class string — Merged with the component's own classes, last — so yours win.
classes Classes<CollapsiblePart> — Classes for the parts inside: trigger, icon (the chevron), content (the panel). Merged last, so they win; the open trigger carries aria-expanded="true".
children required Snippet — The content.

Types

export type CollapsiblePart = 'trigger' | 'icon' | 'content';

Keyboard

Key Does
Enter / Space toggle the panel

Example

The markup behind the screenshot above, lifted from src/routes/shots/ — so it compiles, and it is exactly what produced the image.

<Collapsible title="What accessibility is built in?" open>
	<ul class="list-disc space-y-1 pl-5 text-sm">
		<li>Correct roles and state on every control.</li>
		<li>Keyboard operation before it ships.</li>
	</ul>
</Collapsible>

Layout · Card · StatCard · Accordion · AccordionItem · Separator · Table · Scroller


← All components · Getting started · Theming · source