Browse the docs
ComponentsNo. 15 of 109
Collapsible
A region that a trigger button shows and hides, with a height animation.
Installation
pnpm dlx shadcn@latest add @corsair-ui/collapsibleNo setup needed: the CLI finds @corsair-ui in the shadcn registry directory. The files land in your project as source: edit them like your own code. More in Installation.
- Also adds
- utils
- npm
@radix-ui/react-collapsibleclsxtailwind-merge
Examples
Show more
An icon button toggles the rest of the list.
3 ports saved
Tortuga
API
| Prop | Type | Default |
|---|---|---|
open / defaultOpen / onOpenChangeCollapsible: controlled or uncontrolled. | boolean / boolean / (open) => void | — |
CollapsibleTrigger asChildTurn your own button into the trigger. | boolean | false |
Built on Radix Collapsible; every prop it takes is passed through.
Accessibility
- The trigger is a button announced as expanded or collapsed, pointing at the region.
- Give an icon-only trigger an aria-label.
- The region opens without sliding with prefers-reduced-motion.
Compatibility
- Tailwind CSS
- 3.4 and 4, both checked in CI
- React
- 19
- Rendering
- Client component ("use client")
Source
1 file, installed as source you own
collapsible.tsxView on GitHub"use client";
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
import type { ComponentProps } from "react";
import { cn } from "@/registry/default/lib/utils";
/**
* One region that a button shows and hides: "show more" lists, advanced
* options, a sidebar group. The trigger is a button, so Tab reaches it and
* Enter or Space toggles it; screen readers hear "expanded" or "collapsed"
* and the button points at the region it controls. Controlled with `open` /
* `onOpenChange` or uncontrolled with `defaultOpen`. With reduced motion the
* region opens without sliding. For several sections under headings, use
* Accordion.
*
* @example
* <Collapsible>
* <CollapsibleTrigger asChild>
* <Button variant="ghost" size="sm">Advanced options</Button>
* </CollapsibleTrigger>
* <CollapsibleContent>…</CollapsibleContent>
* </Collapsible>
*/
function Collapsible(props: ComponentProps<typeof CollapsiblePrimitive.Root>) {
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
}
/** Toggles the region. Use `asChild` to turn your own button into the trigger. */
function CollapsibleTrigger(props: ComponentProps<typeof CollapsiblePrimitive.Trigger>) {
return <CollapsiblePrimitive.Trigger data-slot="collapsible-trigger" {...props} />;
}
/** The region that opens and closes. Its height animates, unless motion is reduced. */
function CollapsibleContent({
className,
...props
}: ComponentProps<typeof CollapsiblePrimitive.Content>) {
return (
<CollapsiblePrimitive.Content
data-slot="collapsible-content"
className={cn(
"overflow-hidden",
// Behind motion-safe: so reduced motion really turns the height animation off.
"motion-safe:data-[state=open]:animate-collapsible-open motion-safe:data-[state=closed]:animate-collapsible-close",
className
)}
{...props}
/>
);
}
export { Collapsible, CollapsibleContent, CollapsibleTrigger };