A single disclosure panel with a generous trigger, visible open state, and reduced-motion-aware content transition.
import { BadgeCheck, GitCommitHorizontal } from "lucide-react";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ballmac/collapsible";
export default function CollapsibleDemo() {
return (
<Collapsible
defaultOpen
className="w-full max-w-sm rounded-xl border bg-card p-2 shadow-sm"
>
<CollapsibleTrigger>
<span className="flex items-center gap-2">
<BadgeCheck aria-hidden="true" className="size-4 text-primary" />
Release 2.4 is ready
</span>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="mx-3 mb-2 border-t pt-3 text-sm">
<p className="mb-3 text-muted-foreground">
Three updates are included in this release.
</p>
<ul className="grid gap-2">
<li className="flex items-center gap-2">
<GitCommitHorizontal
aria-hidden="true"
className="size-4 text-muted-foreground"
/>{" "}
Faster project search
</li>
<li className="flex items-center gap-2">
<GitCommitHorizontal
aria-hidden="true"
className="size-4 text-muted-foreground"
/>{" "}
Share links for guests
</li>
<li className="flex items-center gap-2">
<GitCommitHorizontal
aria-hidden="true"
className="size-4 text-muted-foreground"
/>{" "}
Improved export flow
</li>
</ul>
</div>
</CollapsibleContent>
</Collapsible>
);
}Installation
The default, and what a Radix-style project installs.
$ pnpm dlx shadcn@latest add @ballmac/collapsibleInstall the dependencies.
$ pnpm add radix-ui lucide-reactCopy the source into your project.
components/ballmac/collapsible.tsx// Ballmac UI: Collapsible. https://ui.ballmac.com/components/collapsible "use client"; import * as React from "react"; import { ChevronDown } from "lucide-react"; import { Collapsible as Primitive } from "radix-ui"; import { cn } from "@/lib/utils"; type CollapsibleProps = React.ComponentProps<typeof Primitive.Root>; function Collapsible({ className, ...props }: CollapsibleProps) { return ( <Primitive.Root data-slot="collapsible" className={cn("w-full", className)} {...props} /> ); } type CollapsibleTriggerProps = React.ComponentProps< typeof Primitive.Trigger > & { /** Show the rotating disclosure chevron after the label. */ showChevron?: boolean; }; function CollapsibleTrigger({ className, children, showChevron = true, ...props }: CollapsibleTriggerProps) { return ( <Primitive.Trigger data-slot="collapsible-trigger" className={cn( "group flex min-h-11 w-full items-center justify-between gap-3 rounded-lg px-3 text-start text-sm font-medium outline-none transition-colors duration-150 hover:bg-accent/70 focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50 motion-reduce:transition-none", className, )} {...props} > {children} {showChevron && ( <ChevronDown aria-hidden="true" className="size-4 shrink-0 text-muted-foreground transition-transform duration-200 group-data-[state=open]:rotate-180 motion-reduce:transition-none" /> )} </Primitive.Trigger> ); } type CollapsibleContentProps = React.ComponentProps<typeof Primitive.Content>; function CollapsibleContent({ className, ...props }: CollapsibleContentProps) { return ( <Primitive.Content data-slot="collapsible-content" className={cn( "overflow-hidden text-sm data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-top-1 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 motion-reduce:animate-none", className, )} {...props} /> ); } export { Collapsible, CollapsibleTrigger, CollapsibleContent, type CollapsibleProps, type CollapsibleTriggerProps, type CollapsibleContentProps, };Update the import paths to match your project setup.
$ pnpm dlx shadcn@latest add https://ui.ballmac.com/r/base/collapsible.jsonInstall the dependencies.
$ pnpm add lucide-react @base-ui/react@^1.9.0Copy the source into your project.
components/ballmac/collapsible.tsx// Ballmac UI: Collapsible. https://ui.ballmac.com/components/collapsible "use client"; import * as React from "react"; import { ChevronDown } from "lucide-react"; import { Collapsible as Primitive } from "@base-ui/react/collapsible"; import { cn } from "@/lib/utils"; type CollapsibleProps = Omit<React.ComponentProps<typeof Primitive.Root>, "className"> & { className?: string }; function Collapsible({ className, ...props }: CollapsibleProps) { return ( <Primitive.Root data-slot="collapsible" className={cn("w-full", className)} {...props} /> ); } type CollapsibleTriggerProps = Omit<React.ComponentProps<typeof Primitive.Trigger>, "className"> & { className?: string; /** Show the rotating disclosure chevron after the label. */ showChevron?: boolean; }; function CollapsibleTrigger({ className, children, showChevron = true, ...props }: CollapsibleTriggerProps) { return ( <Primitive.Trigger data-slot="collapsible-trigger" className={cn( "group flex min-h-11 w-full items-center justify-between gap-3 rounded-lg px-3 text-start text-sm font-medium outline-none transition-colors duration-150 hover:bg-accent/70 focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50 motion-reduce:transition-none", className, )} {...props} > {children} {showChevron && ( <ChevronDown aria-hidden="true" className="size-4 shrink-0 text-muted-foreground transition-transform duration-200 group-data-panel-open:rotate-180 motion-reduce:transition-none" /> )} </Primitive.Trigger> ); } type CollapsibleContentProps = Omit<React.ComponentProps<typeof Primitive.Panel>, "className"> & { className?: string }; /** The part that opens and closes. Base UI calls it a panel and sets `--collapsible-panel-height` for the animation. */ function CollapsibleContent({ className, ...props }: CollapsibleContentProps) { return ( <Primitive.Panel data-slot="collapsible-content" className={cn( "h-(--collapsible-panel-height) overflow-hidden text-sm transition-[height] duration-200 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none", className, )} {...props} /> ); } export { Collapsible, CollapsibleTrigger, CollapsibleContent, type CollapsibleProps, type CollapsibleTriggerProps, type CollapsibleContentProps, };Update the import paths to match your project setup.
Usage
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from "@/components/ballmac/collapsible"The full example is in the Code tab above.
Examples
Controlled disclosure
Controlled state: open
"use client";
import * as React from "react";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ballmac/collapsible";
export default function CollapsibleStates() {
const [open, setOpen] = React.useState(true);
return (
<div className="w-full max-w-xs">
<p className="mb-2 text-xs text-muted-foreground">
Controlled state: {open ? "open" : "closed"}
</p>
<Collapsible
open={open}
onOpenChange={setOpen}
className="rounded-xl border p-2"
>
<CollapsibleTrigger>Advanced settings</CollapsibleTrigger>
<CollapsibleContent>
<p className="px-3 pb-3 text-sm text-muted-foreground">
Only admins can change project defaults.
</p>
</CollapsibleContent>
</Collapsible>
</div>
);
}API reference
| Prop | Type | Default |
|---|---|---|
showChevronShow the rotating disclosure chevron after the label. | boolean | true |
Also accepts the standard attributes of its root element.
Accessibility
| Key | Action |
|---|---|
| Enter / Space | Opens or closes the disclosure |
| Tab | Moves into visible content |
Quality scorecard
Every applicable check passes
Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.0.0, across 2 examples.
Passed: Accessibility scan
No serious or critical issues in light and dark, on a phone and a desktop (axe-core 4.13.0, WCAG 2.1 AA and best-practice rules).
Passed: Small screens
No sideways scrolling at 360, 390 or 1280 px wide.
Passed: Reduced motion
No endless animation to begin with.
Passed: Right to left
Mirrors correctly in Arabic, Hebrew, Persian and Urdu layouts (0% of elements off the mirror, limit 15%).
Passed: Clean console
No console errors or React hydration errors while loading.
Passed: Keyboard
2 tab stops, each showing a visible change when it takes focus. 2 documented keys.
Not applicable: Loading, empty and error
Does not show data or take submissions.
Passed: Automated tests
Covered by collapsible.test.tsx.
For information: Footprint
0.8 KB of source (gzip) in 1 file. Installs radix-ui, lucide-react.
Automated checks find a subset of problems and do not replace testing with a screen reader and a keyboard in your own app. What they miss.
Use with AI
Reveals one optional section of information with a keyboard-accessible disclosure trigger. With the shadcn MCP server set up (guide), ask your agent:
Add the Ballmac UI Collapsible (@ballmac/collapsible) to this project with the shadcn MCP, then use it where it fits.
Use it for
- Advanced settings
- Supporting detail in a dense card
Not for
- Several related disclosures; use accordion
- Primary content that should always be visible
Registry JSON: https://ui.ballmac.com/r/collapsible.json
Credits
Free to use in personal and commercial projects.
- Registry
- shadcn/utils
Pairs well with
Card
A composable content surface with compact spacing, an action slot, and optional interactive feedback.
Accordion
Vertically stacked disclosure sections on Radix Accordion, single or multiple open, with hairline dividers, a rotating plus and height animation.
Avatar
A Radix avatar with image and initials fallback, three sizes, an optional presence dot, and AvatarGroup for overlapping stacks with a +N overflow counter.
Badge
A small pill label in four variants with an optional status dot and success, warning and error tones. Style links with badgeVariants().
Ballmac UI Pro
Need the whole screen, not one piece?
311 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.
Not ready? Try three Pro blocks free
Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.