Components

Collapsible

Accessible show/hide section that toggles between expanded and collapsed states.

Category: Utility — Pattern: Base UI Overlay

Dependency: @base-ui-components/react/collapsible

Preview

Loading preview...
import {
  Collapsible,
  CollapsibleTrigger,
  CollapsibleContent,
} from "@hareru/ui"

<Collapsible>
  <CollapsibleTrigger>Show Details</CollapsibleTrigger>
  <CollapsibleContent><p>Collapsible content</p></CollapsibleContent>
</Collapsible>

Import

import {
  Collapsible,
  CollapsibleTrigger,
  CollapsibleContent,
} from "@hareru/ui"

Exports

NameTypeDescription
CollapsibleComponentRoot collapsible context; accepts open, defaultOpen, and onOpenChange
CollapsibleTriggerComponentElement that toggles the expanded state
CollapsibleContentComponentSection that is shown or hidden based on open state

Key Props

PropTypeDefaultDescription
defaultOpenbooleanfalseInitial expanded state (uncontrolled)
openbooleanControlled expanded state
onOpenChange(open: boolean) => voidCallback when expanded state changes
disabledbooleanfalsePrevents toggling

Structure

  • CollapsibleTrigger [trigger] (expected)
  • CollapsibleContent [content] (expected)

(expected) = recommended in canonical composition, not runtime-required.

States

StateTypeValuesDefaultCSS Reflection
disabledboolean
openboolean

Accessibility

  • Keyboard:
    • Enter or Space to toggle
  • Notes: Disclosure widget with animated expand/collapse.

Usage

import {
  Collapsible,
  CollapsibleTrigger,
  CollapsibleContent,
} from "@hareru/ui"

<Collapsible>
  <CollapsibleTrigger>Show Details</CollapsibleTrigger>
  <CollapsibleContent><p>Collapsible content</p></CollapsibleContent>
</Collapsible>

Notes

  • CollapsibleContent animates open/close when CSS transitions are applied to [data-state="open"] and [data-state="closed"].
  • The data-state attribute on both CollapsibleTrigger and CollapsibleContent reflects "open" or "closed" for CSS targeting.
  • Use the controlled open + onOpenChange props when you need to synchronise state with other UI elements.

On this page