$npx @dinachi/cli@latest add collapsible
CollapsibleTriggerdisabledmore-details.tsx
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@/components/ui/collapsible"
import { ChevronDown } from "lucide-react"
export function MoreDetails() {
return (
<Collapsible className="w-full max-w-sm">
<CollapsibleTrigger>
<span>View more details</span>
<ChevronDown className="h-4 w-4 transition-transform" />
</CollapsibleTrigger>
<CollapsiblePanel>
<div className="px-4 pb-4 text-sm text-muted-foreground">
This is the collapsible content. It can contain any elements you need,
including text, images, or other components.
</div>
</CollapsiblePanel>
</Collapsible>
)
}Usage
import { ChevronDown } from "lucide-react"
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@/components/ui/collapsible"
export function ShippingDetails() {
return (
<Collapsible className="max-w-sm">
<CollapsibleTrigger>
<span>Shipping details</span>
<ChevronDown className="h-4 w-4 transition-transform" />
</CollapsibleTrigger>
<CollapsiblePanel>
<p className="px-4 pb-4 text-muted-foreground">Ships in 2 to 3 working days.</p>
</CollapsiblePanel>
</Collapsible>
)
}Examples
A section that opens from its trigger.
import { Collapsible, CollapsibleTrigger, CollapsiblePanel } from '@/components/ui/collapsible';
import { ChevronDown } from 'lucide-react';
export function Example() {
return (
<Collapsible className="w-full max-w-sm">
<CollapsibleTrigger>
<span>View more details</span>
<ChevronDown className="h-4 w-4 transition-transform" />
</CollapsibleTrigger>
<CollapsiblePanel>
<div className="px-4 pb-4 text-sm text-muted-foreground">
This is the collapsible content. It can contain any elements you need,
including text, images, or other components.
</div>
</CollapsiblePanel>
</Collapsible>
);
}State: Closed
The open state lives in your state.
import React from 'react';
import { Collapsible, CollapsibleTrigger, CollapsiblePanel } from '@/components/ui/collapsible';
import { ChevronDown } from 'lucide-react';
export function Example() {
const [open, setOpen] = React.useState(false);
return (
<div className="w-full max-w-sm space-y-2">
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger>
<span>{open ? 'Hide' : 'Show'} settings</span>
<ChevronDown className="h-4 w-4 transition-transform" />
</CollapsibleTrigger>
<CollapsiblePanel>
<div className="space-y-2 px-4 pb-4">
<div className="rounded-md border px-4 py-3 text-sm">Setting 1</div>
<div className="rounded-md border px-4 py-3 text-sm">Setting 2</div>
<div className="rounded-md border px-4 py-3 text-sm">Setting 3</div>
</div>
</CollapsiblePanel>
</Collapsible>
<p className="text-xs text-muted-foreground px-4">
State: {open ? 'Open' : 'Closed'}
</p>
</div>
);
}Notes
Chevron
The trigger rotates a direct child svg 180 degrees while open. Put the icon directly inside CollapsibleTrigger, unwrapped, with transition-transform to animate it.
Several sections
For related sections sharing one open state, use Accordion.
API
openboolean
Controlled open state.defaultOpenboolean = false
Starting state when uncontrolled.onOpenChange
Runs for people and agents. agent
(open, details) => voiddetails.cancel() refuses the change.disabled
Blocks the trigger, for people and agents.agent
boolean = falsechildren
Also the name the agent reads.agent
ReactNoderenderReactElement
Swap the element, keep the behaviour.keepMountedboolean = false
Keeps the content in the DOM while closed.hiddenUntilFoundboolean = false
Lets find in page reach the content and open the panel.Agent
Inside an AgentProvider, it appears in agent.snapshot() as disclosure.
Reads
labelThe trigger's text, or its aria-label.
openWhether the panel is showing.
disabledTrue when the collapsible is disabled.
Actions
open() / close()Whichever fits the current state. Panel content is listed once open.
An agent's change runs through onOpenChange like a click on the trigger. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused. A disabled collapsible refuses on its own.
await agent.act({
steps: [{ ref: "View more details", action: "open" }],
})Accessibility
- The trigger is a button with aria-expanded, and aria-controls on the panel while open.
- The trigger's text is its name, for screen readers and the agent.
- Reduced motion turns off the height animation.
Keyboard
EnterSpaceOpens or closes the panel
EnterSpaceOpens or closes the panel