shadcn.io is not affiliated with official shadcn/ui
Order #4189
StatusShipped
Shipping address
100 Market St, San Francisco
Items
2x Studio Headphones
Installation
bunx --bun shadcn@latest add https://kit.dev/r/aria/collapsible.jsonnpx shadcn@latest add https://kit.dev/r/aria/collapsible.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/collapsible.jsonyarn shadcn@latest add https://kit.dev/r/aria/collapsible.jsonInstall the following dependencies:
bun add lucide-react react-aria-componentsnpm install lucide-react react-aria-componentspnpm add lucide-react react-aria-componentsyarn add lucide-react react-aria-componentsCopy and paste the following code into your project.
"use client";
import { ChevronDownIcon } from "lucide-react";
import type React from "react";
import {
Button,
type ButtonProps,
Disclosure,
DisclosurePanel,
type DisclosurePanelProps,
type DisclosureProps,
} from "react-aria-components";
import { cn } from "@/lib/utils";
export const Collapsible = (props: DisclosureProps) => {
const { className, ...rest } = props;
return (Update the import paths to match your project setup.
Anatomy
Collapsible
├── CollapsibleTrigger
├── CollapsibleContent
└── CollapsibleIndicatorUsage
import { ChevronsUpDownIcon } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";const CollapsibleDemo = () => {
const [isOpen, setIsOpen] = useState(false);
const handleOpenChange = (details: { open: boolean }) => {
setIsOpen(details.open);
};
return (
<Collapsible
className="flex w-[350px] flex-col gap-2"
onOpenChange={handleOpenChange}
open={isOpen}
>
<div className="flex items-center justify-between gap-4 px-4">
<h4 className="font-semibold text-sm">Order #4189</h4>
<CollapsibleTrigger asChild>
<Button className="size-8" size="icon-md" variant="ghost">
<ChevronsUpDownIcon aria-hidden="true" />
<span className="sr-only">Toggle details</span>
</Button>
</CollapsibleTrigger>
</div>
<div className="flex items-center justify-between rounded-md border px-4 py-2 text-sm">
<span className="text-muted-foreground">Status</span>
<span className="font-medium">Shipped</span>
</div>
<CollapsibleContent className="flex flex-col gap-2">
<div className="rounded-md border px-4 py-2 text-sm">
<p className="font-medium">Shipping address</p>
<p className="text-muted-foreground">100 Market St, San Francisco</p>
</div>
<div className="rounded-md border px-4 py-2 text-sm">
<p className="font-medium">Items</p>
<p className="text-muted-foreground">2x Studio Headphones</p>
</div>
</CollapsibleContent>
</Collapsible>
);
};Accessibility
| Key | Description |
|---|---|
Enter | Activate the focused control. |
Space | Activate the focused control. |
Demos
Basic
A basic collapsible panel.
Settings
Use a trigger button to reveal additional settings.
File Tree
Use nested collapsibles to build a file tree.
Rtl
Right-to-left collapsible. See the RTL configuration guide for document direction.
API Reference
Collapsible
PropType
AttributeType
CollapsibleTrigger
PropType
AttributeType
CollapsibleContent
PropType
AttributeType
CollapsibleIndicator
PropType
AttributeType