Skip to content
SevenOne

Search documentation

Search pages and components

Collapsible

Shows and hides a panel. Use it for extra details, such as the rest of a list or an order summary.

Installation

npx shadcn@latest add @sevenone/collapsible

Usage

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

Examples

List

@peduarte starred 3 repositories

@radix-ui/primitives
<Collapsible className="flex flex-col gap-2">
  <div className="flex items-center justify-between gap-4 pl-4">
    <h4 className="text-sm font-semibold">@peduarte starred 3 repositories</h4>
    <CollapsibleTrigger asChild>
      <Button variant="ghost" size="icon" aria-label="Show all repositories">
        <ChevronsUpDown />
      </Button>
    </CollapsibleTrigger>
  </div>
  <div className="rounded-md border px-4 py-2.5 font-mono text-sm">@radix-ui/primitives</div>
  <CollapsibleContent className="flex flex-col gap-2">…</CollapsibleContent>
</Collapsible>

Order summary

The whole header row is the trigger, so the hit area is large and its name includes the total.

<Collapsible className="rounded-lg border bg-card">
  <CollapsibleTrigger className="group flex min-h-control w-full items-center gap-4 px-4 py-2.5 text-sm font-medium">
    <span>Order summary (2 items)</span>
    <span className="ml-auto">$37.26</span>
    <ChevronDown aria-hidden="true" className="size-icon group-data-[state=open]:rotate-180" />
  </CollapsibleTrigger>
  <CollapsibleContent>
    <dl className="grid grid-cols-[1fr_auto] border-t px-4 py-3 text-sm">…</dl>
  </CollapsibleContent>
</Collapsible>

Accessibility

  • The trigger is a button with aria-expanded, and Enter or Space opens and closes it.
  • Icon-only triggers need an aria-label; a whole-row trigger gets its name from its text.
  • The chevron turns to show the state, and the opening motion stops when people ask for reduced motion.