Unified UI

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 collapsible
pnpm dlx @work-rjkashyap/unified-ui add collapsible
npx @work-rjkashyap/unified-ui add collapsible
bunx @work-rjkashyap/unified-ui add collapsible

If 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-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import {
	Collapsible,
	CollapsibleTrigger,
	CollapsibleContent,
} from "@work-rjkashyap/unified-ui";

Examples

Basic Usage

What is Unified UI?

Default Open

Details (open by default)
This content is visible by default because the defaultOpen prop is set to true. Click the toggle button to collapse it.

Multiple Sections

Installation
Usage
Theming

Disabled

Disabled section

Custom Animation Duration

Slow animation (0.5s)

Composition

Collapsible

The root component that manages open/closed state.

PropTypeDefaultDescription
openbooleanControlled open state.
defaultOpenbooleanfalseDefault open state for uncontrolled mode.
onOpenChange(open: boolean) => voidCallback fired when the open state changes.
disabledbooleanfalsePrevents trigger interaction.
classNamestringAdditional CSS classes for the root element.

CollapsibleTrigger

The button that toggles the collapsible. Use asChild to render your own trigger element.

PropTypeDefaultDescription
asChildbooleanfalseMerge props onto child instead of rendering.
classNamestringAdditional CSS classes.

CollapsibleContent

The content section that expands and collapses with a smooth height animation.

PropTypeDefaultDescription
durationnumber0.2Animation duration in seconds.
forceMountbooleanfalseKeep content in the DOM even when collapsed (useful for SEO).
classNamestringAdditional 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-expanded on 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-motion and falls back to instant transitions.

Design Tokens

TokenUsage
--duration-fastDefault animation timing reference
--easing-standardEasing curve for expand/collapse
--borderContent section border color
--muted-foregroundContent text color

On this page