Skip to content
Navigation Core Stable

Collapsible

.md

A single disclosure: a trigger that expands and collapses a region, animated without measuring so an interrupted toggle simply reverses, with the closed content kept in the page.

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { Collapsible } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { Collapsible, CollapsibleTrigger, CollapsibleContent } from "fancy-ui-svelte";

	let open = $state(false);
</script>

<Collapsible bind:open class="w-full max-w-sm">
	<div class="flex items-center justify-between gap-4">
		<h4 class="text-sm font-semibold">3 repositories starred</h4>
		<CollapsibleTrigger class="rounded-md border px-3 py-1 text-sm">
			{open ? "Show less" : "Show more"}
		</CollapsibleTrigger>
	</div>
	<div class="mt-2 rounded-md border px-3 py-2 font-mono text-sm">fancy-ui/core</div>
	<CollapsibleContent>
		<div class="mt-2 flex flex-col gap-2">
			<div class="rounded-md border px-3 py-2 font-mono text-sm">fancy-ui/motion</div>
			<div class="rounded-md border px-3 py-2 font-mono text-sm">fancy-ui/registry</div>
		</div>
	</CollapsibleContent>
</Collapsible>

Examples

Basic Usage

A trigger that reveals extra rows beneath a short list.

Multiple

Several independent panels, each with its own open state.

Controlled

Open state shared with a button outside the component.

Props

PropTypeDefaultDescription
open booleanfalseWhether the content is expanded, bindable.
onOpenChange (open: boolean) => void-Called with the new state each time the trigger toggles it.
disabled booleanfalseMakes the trigger inert. A bound open can still be changed from outside.
class string-Additional CSS classes, merged onto the root.
ref HTMLDivElement | nullnullBindable reference to the root element.
CollapsibleTrigger.disabled booleanfalseDisables this trigger on top of the root's own disabled.
CollapsibleTrigger.class string-Additional CSS classes, merged onto the trigger button.
CollapsibleTrigger.ref HTMLButtonElement | nullnullBindable reference to the trigger's button element.
CollapsibleContent.forceMount booleantrueKeeps the children mounted while closed (inert and hidden). Pass false to unmount them once the collapse has finished and mount them again on open.
CollapsibleContent.class string-Additional CSS classes, merged onto the inner body so padding collapses with the panel.
CollapsibleContent.ref HTMLDivElement | nullnullBindable reference to the region element that animates.

Slots

SlotDescription
children A CollapsibleTrigger and a CollapsibleContent.
CollapsibleTrigger.children The trigger's content.
CollapsibleContent.children The content.