Prototyper UI

Collapsible

a collapsible section for revealing or hiding content

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/collapsible.json
npx shadcn@latest add https://prototyper-ui.com/r/collapsible.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/collapsible.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/collapsible.json

This will add the following files to your project:

  • components/ui/collapsible.tsx

Usage

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

<Collapsible>
  <CollapsibleTrigger>Toggle</CollapsibleTrigger>
  <CollapsibleContent>
    Content that can be collapsed or expanded.
  </CollapsibleContent>
</Collapsible>

Anatomy

<Collapsible>
  <CollapsibleTrigger />
  <CollapsibleContent>
    {/* your content */}
  </CollapsibleContent>
</Collapsible>
Sub-componentdata-slotPurposeRequired
CollapsiblecollapsibleRoot provider, manages open/close stateYes
CollapsibleTriggercollapsible-triggerButton that toggles the collapsible panelYes
CollapsibleContentcollapsible-contentThe panel that is shown or hiddenYes

Examples

Disabled

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the collapsible:

Slot nameElement
collapsibleRoot provider (wrapping element)
collapsible-triggerThe trigger button
collapsible-contentThe collapsible panel

Customization Examples

/* Animate the collapsible panel height */
[data-slot="collapsible-content"] {
  overflow: hidden;
  transition: height 250ms var(--ease-out-fluid);
}

[data-slot="collapsible-content"][data-open] {
  height: var(--collapsible-panel-height);
}

[data-slot="collapsible-content"][data-closed] {
  height: 0;
}
{/* Override styling via className */}
<CollapsibleContent className="mt-4 space-y-2">
  {/* ... */}
</CollapsibleContent>

API Reference

Collapsible

Root component that manages the open/close state of the collapsible section.

Prop

Type

All Base UI Collapsible.Root props are forwarded via ...props.

CollapsibleTrigger

Button that toggles the collapsible panel open and closed.

Prop

Type

All Base UI Collapsible.Trigger props are forwarded via ...props.

CollapsibleContent

The panel that is shown or hidden when the collapsible is toggled.

Prop

Type

All Base UI Collapsible.Panel props are forwarded via ...props.

Accessibility

Keyboard Interactions

KeyAction
SpaceToggles the collapsible panel
EnterToggles the collapsible panel
TabMoves focus to / away from the trigger

ARIA Attributes

  • CollapsibleTrigger renders as a <button> element with aria-expanded reflecting the open state.
  • aria-controls on the trigger is automatically linked to the CollapsibleContent panel.
  • CollapsibleContent has role="region" for screen reader discoverability.
  • When disabled is set, the trigger receives the disabled attribute and interaction is prevented.

On this page