Collapsible

One section shown and hidden by a person or an agent.

Source
$npx @dinachi/cli@latest add collapsible
CollapsibleTrigger
disabled

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>
  );
}

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
agent
(open, details) => void
Runs for people and agents. details.cancel() refuses the change.
disabled
agent
boolean = false
Blocks the trigger, for people and agents.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as disclosure.

Reads

label

The trigger's text, or its aria-label.

open

Whether the panel is showing.

disabled

True 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.