Collapsible
An animated show/hide section built on Radix UI Collapsible with smooth Framer Motion height transitions.
Overview
The Collapsible component provides an animated show/hide section. Built on Radix UI's Collapsible primitive for accessibility and Framer Motion for smooth height animations. It's a foundational building block used by Sidebar, TreeView, and other expandable components.
Installation
Install the component via the CLI in one command.
npx @work-rjkashyap/unified-ui add collapsiblepnpm dlx @work-rjkashyap/unified-ui add collapsiblenpx @work-rjkashyap/unified-ui add collapsiblebunx @work-rjkashyap/unified-ui add collapsibleIf you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.
Or install the full package
Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.
npm install @work-rjkashyap/unified-uipnpm add @work-rjkashyap/unified-uiyarn add @work-rjkashyap/unified-uibun add @work-rjkashyap/unified-uiAnatomy
import {
Collapsible,
CollapsibleTrigger,
CollapsibleContent,
} from "@work-rjkashyap/unified-ui";Examples
Basic Usage
Default Open
Multiple Sections
Disabled
Custom Animation Duration
Composition
Collapsible
The root component that manages open/closed state.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | — | Controlled open state. |
defaultOpen | boolean | false | Default open state for uncontrolled mode. |
onOpenChange | (open: boolean) => void | — | Callback fired when the open state changes. |
disabled | boolean | false | Prevents trigger interaction. |
className | string | — | Additional CSS classes for the root element. |
CollapsibleTrigger
The button that toggles the collapsible. Use asChild to render your own trigger element.
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean | false | Merge props onto child instead of rendering. |
className | string | — | Additional CSS classes. |
CollapsibleContent
The content section that expands and collapses with a smooth height animation.
| Prop | Type | Default | Description |
|---|---|---|---|
duration | number | 0.2 | Animation duration in seconds. |
forceMount | boolean | false | Keep content in the DOM even when collapsed (useful for SEO). |
className | string | — | Additional CSS classes for the content wrapper. |
Accessibility
The Collapsible component is built on Radix UI, which handles all ARIA attributes and keyboard interactions automatically.
- aria-expanded — Radix sets
aria-expandedon the trigger to reflect the open state. - aria-controls — Radix links the trigger to the content via
aria-controls. - Keyboard — Space and Enter keys toggle the collapsible when the trigger is focused.
- Disabled — When disabled, the trigger is non-interactive and removed from the tab order.
- Reduced motion — Framer Motion automatically respects
prefers-reduced-motionand falls back to instant transitions.
Design Tokens
| Token | Usage |
|---|---|
--duration-fast | Default animation timing reference |
--easing-standard | Easing curve for expand/collapse |
--border | Content section border color |
--muted-foreground | Content text color |