Skip to main content
The Collapsible component provides an interactive way to show and hide content. It’s useful for creating expandable sections, FAQs, or any interface where content needs to be progressively disclosed.

Import

Basic Usage

Key Features

  • Controlled or Uncontrolled: Use open and onOpenChange for controlled state, or defaultOpen for uncontrolled.
  • Smooth Animations: Built-in support for CSS transitions and animations.
  • Transition Status: Track animation states with transitionStatus (idle, opening, open, closing).
  • Accessibility: Proper ARIA attributes for screen readers.
  • Keep Mounted: Control whether the panel stays in the DOM when closed.
  • Hidden Until Found: Enable browser’s page search to find and expand content.

Components

Collapsible.Root

The root container that manages collapsible state. Props:
  • open - Controlled open state (boolean)
  • defaultOpen - Initial open state for uncontrolled mode (default: false)
  • onOpenChange - Callback when open state changes
  • disabled - Disable all user interaction (default: false)

Collapsible.Trigger

A button that toggles the panel open and closed. Renders a <button> element. Props:
  • disabled - Disable the trigger button
  • nativeButton - Use native button behavior (default: true)

Collapsible.Panel

The collapsible panel containing the content. Renders a <div> element. Props:
  • keepMounted - Keep panel in DOM when closed (default: false)
  • hiddenUntilFound - Allow browser search to expand panel (default: false)

Styling Example

Controlled Example

CSS Variables

The component provides CSS variables for dynamic styling:
  • --collapsible-panel-height - Current height of the panel in pixels
  • --collapsible-panel-width - Current width of the panel in pixels
These are useful for smooth height/width transitions during open/close animations.