Collapsible

Layout
Interactive

An expandable/collapsible container component for hiding and revealing content. Perfect for FAQs, settings panels, and progressive disclosure.

Preview

Interactive collapsible example

Props

Collapsible component API reference

PropTypeDefaultDescription
trigger*ReactNodeContent to display in the trigger button (visible when collapsed/expanded)
children*ReactNodeContent to show/hide when expanded
defaultOpenbooleanfalseInitial open state (uncontrolled mode)
openbooleanControlled open state
onOpenChange(open: boolean) => voidCallback when open state changes
disabledbooleanfalseDisable the collapsible interaction
classNamestringAdditional CSS classes for the container
triggerClassNamestringAdditional CSS classes for the trigger button
contentClassNamestringAdditional CSS classes for the content area
aria-labelstringAccessible label for the trigger (use when trigger content is not descriptive)

Settings Panel

Multiple collapsible sections with icons

Controlled State

Collapsible with external state control

Status:
Closed

Usage

Import and implementation example

import { Collapsible } from '@/components/ui/collapsible'

export default function Example() {
  return (
    <Collapsible
      trigger={<span>Click to expand</span>}
      defaultOpen={false}
    >
      <div className="p-4">
        Content goes here
      </div>
    </Collapsible>
  )
}

Features

Built-in functionality

  • Controlled & uncontrolled: Works with both internal and external state management
  • Custom triggers: Any React content can be used as the trigger
  • Chevron indicator: Rotates 180° when expanded
  • Disabled state: Prevent interaction when disabled
  • Custom styling: Separate className props for container, trigger, and content
  • Smooth transitions: CSS transitions for chevron rotation
  • Dark mode: Full dark mode support
  • Keyboard accessible: Works with Enter and Space keys

Accessibility

ARIA support and keyboard navigation

ARIA Attributes

aria-expanded (on trigger button)aria-controls (links trigger to content)aria-disabled (when disabled)aria-label (optional, for non-descriptive triggers)role="region" (on content)aria-labelledby (links content to trigger)

Keyboard Navigation

KeyAction
EnterToggle the collapsible open/closed
SpaceToggle the collapsible open/closed
TabMove focus to the trigger button

Notes

  • The trigger is a native button element for full keyboard accessibility
  • Content region is linked to the trigger via aria-labelledby
  • Chevron icon is hidden from screen readers with aria-hidden
  • When disabled, the trigger has aria-disabled="true" and reduced opacity
  • Focus ring is visible when navigating with keyboard