# Collapsible

> 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.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Navigation
- Tags: collapsible, disclosure, expand, collapse, compound, navigation
- Types: `CollapsibleProps`, `CollapsibleTriggerProps`, `CollapsibleContentProps`, `CollapsibleContext`
- Docs: https://fancy-ui.rama.app/docs/components/collapsible
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/collapsible

## Import

```tsx
import { Collapsible } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | `false` | Whether the content is expanded, bindable. |
| `onOpenChange` | `(open: boolean) => void` | — | Called with the new state each time the trigger toggles it. |
| `disabled` | `boolean` | `false` | Makes the trigger inert. A bound open can still be changed from outside. |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes, merged onto the root. |
| `ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the root element. |
| `CollapsibleTrigger.disabled` | `boolean` | `false` | Disables this trigger on top of the root's own disabled. |
| `CollapsibleTrigger.className` (Svelte `CollapsibleTrigger.class`) | `string` | — | Additional CSS classes, merged onto the trigger button. |
| `CollapsibleTrigger.ref` | `HTMLButtonElement \| null` | `null` | Bindable reference to the trigger's button element. |
| `CollapsibleContent.forceMount` | `boolean` | `true` | Keeps 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.className` (Svelte `CollapsibleContent.class`) | `string` | — | Additional CSS classes, merged onto the inner body so padding collapses with the panel. |
| `CollapsibleContent.ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the region element that animates. |

## Node props

| Prop | Description |
| --- | --- |
| `children` | A CollapsibleTrigger and a CollapsibleContent. |
| `CollapsibleTrigger.children` | The trigger's content. |
| `CollapsibleContent.children` | The content. |

## Example

```tsx
import { useState } from "react";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "fancy-ui-react";

export function CollapsibleExample() {
	const [open, setOpen] = useState(false);

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