Collapsible

An interactive component which expands and collapses a panel.

Order #4189

StatusShipped

Installation

pnpm dlx cubix@latest add collapsible --base radix

Usage

Import
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/cubix/collapsible"
Example
<Collapsible>
  <CollapsibleTrigger>Can I use this in my project?</CollapsibleTrigger>
  <CollapsibleContent>
    Yes. Free to use for personal and commercial projects. No attribution
    required.
  </CollapsibleContent>
</Collapsible>

Composition

Use the following composition to build a Collapsible:

 
Collapsible
├── CollapsibleTrigger
└── CollapsibleContent

Controlled State

Use the open and onOpenChange props to control the state.

 
import * as React from "react"

export function Example() {
  const [open, setOpen] = React.useState(false)

  return (
    <Collapsible open={open} onOpenChange={setOpen}>
      <CollapsibleTrigger>Toggle</CollapsibleTrigger>
      <CollapsibleContent>Content</CollapsibleContent>
    </Collapsible>
  )
}

Examples

Basic

Settings Panel

Use a trigger button to reveal additional settings.

Radius
Set the corner radius of the element.

File Tree

Use nested collapsibles to build a file tree.

API Reference

Note: See the Base UI or Radix UI Collapsible docs for the full primitive API.

Collapsible

The root that manages open state and provides context to trigger and content.

PropTypeDefaultDescription
openboolean-Controlled open state of the panel.
defaultOpenboolean-Initial open state when uncontrolled.
onOpenChange(open: boolean) => void-Called when the open state changes.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

CollapsibleTrigger

The control that toggles the panel. Compose it onto a Button when you need a styled trigger.

PropTypeDefaultDescription
renderReact.ReactElement-Compose the trigger onto a child element such as Button (Base UI).
asChildboolean-Compose the trigger onto a child element such as Button (Radix UI).
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

CollapsibleContent

The panel that expands and collapses.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Content revealed when the panel is open.