videorc/ui

Collapsible

One section that opens and closes under its trigger, such as advanced settings. Unstyled, so the trigger is whatever control fits.

Installation

$ pnpm dlx shadcn@latest add @videorc/collapsible

Usage

import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible";
<Collapsible>
  <CollapsibleTrigger>Advanced settings</CollapsibleTrigger>
  <CollapsibleContent>{settings}</CollapsibleContent>
</Collapsible>

Anatomy

<Collapsible>
  <CollapsibleTrigger />
  <CollapsibleContent />
</Collapsible>

Theming

Token or attributeMeaning
data-panel-openOn the trigger while open: turn a chevron with group-data-panel-open:rotate-180
data-open, data-closedOn the root and the panel
--collapsible-panel-heightThe panel's measured height, to animate it

Keyboard

KeyAction
Enter SpaceOpens or closes the panel

Accessibility

The trigger is a button with aria-expanded and aria-controls. Render your own button with render={<Button variant="ghost" />} to keep the desktop sizes; wrap the trigger in a heading when the section is one.

API reference

Every Base UI Collapsible prop: open, defaultOpen and onOpenChange on Collapsible, render on CollapsibleTrigger, and keepMounted or hiddenUntilFound on CollapsibleContent (the Base UI Panel).