Skip to content

    Collapsible

    A single disclosure section that expands and collapses its content in place without a mandatory heading wrapper, suited for advanced form options or reasoning traces.

    Preview

    Props

    • open
    • defaultOpen
    • disabled
    • trigger
    • body
    import { IconChevronDown } from "@tabler/icons-react"
    import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"
    
    <Collapsible className="max-w-md">
      <CollapsibleTrigger>
        Show advanced options
        <IconChevronDown size={16} className="in-data-[state=open]:rotate-180 motion-safe:transition-transform duration-medium ease-standard" aria-hidden="true" />
      </CollapsibleTrigger>
      <CollapsibleContent>Webhook retries run three times with exponential backoff.</CollapsibleContent>
    </Collapsible>

    Usage

    When to use

    • Hide and show one optional section, such as advanced form fields or an assistant reasoning summary.
    • Disclose content in place without adding a heading element.

    When not to use

    • A stack of sections with dividers or arrow-key navigation between titles. Use Accordion.
    • Switching between views of the same content. Use Tabs.

    Examples

    Advanced options

    A compact disclosure inside a form without adding a heading.

    import { IconChevronDown } from "@tabler/icons-react"
    import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"
    
    <Collapsible className="max-w-md">
      <CollapsibleTrigger>
        Show advanced options
        <IconChevronDown size={16} className="in-data-[state=open]:rotate-180 motion-safe:transition-transform duration-medium ease-standard" aria-hidden="true" />
      </CollapsibleTrigger>
      <CollapsibleContent>Webhook retries run three times with exponential backoff.</CollapsibleContent>
    </Collapsible>

    Reasoning trace

    Starts open with defaultOpen for an assistant step summary.

    Checked token contrast pairs across both light and dark themes.
    import { IconChevronDown } from "@tabler/icons-react"
    import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"
    
    <Collapsible defaultOpen className="max-w-md">
      <CollapsibleTrigger>
        Thought for 4s
        <IconChevronDown size={16} className="in-data-[state=open]:rotate-180 motion-safe:transition-transform duration-medium ease-standard" aria-hidden="true" />
      </CollapsibleTrigger>
      <CollapsibleContent>Checked token contrast pairs across both light and dark themes.</CollapsibleContent>
    </Collapsible>

    Do and don't

    Do

    • Use Collapsible for one optional section, such as advanced form fields or a reasoning block.
    • Keep the trigger label clear about what opens or closes.

    Don't

    • Don't use Collapsible for a stack of sections that share dividers or headings; use Accordion.
    • Don't hide required fields inside a collapsed section.

    Props

    NameTypeValuesDefaultDescription
    openboolean--Controlled open state. Pair with onOpenChange.
    defaultOpenboolean-falseInitial open state when uncontrolled.
    onOpenChange(open: boolean) => void--Called with the next open state when the trigger is activated.
    disabledboolean-falsePrevents toggling the section and dims the trigger.

    Slots

    NameRequiredDescription
    triggeryesCollapsibleTrigger holding the toggle label and optional icon.
    contentyesCollapsibleContent holding the disclosed body.

    Anatomy

    PartDescription
    rootCollapsible: a column as wide as its parent.
    triggerCollapsibleTrigger: the button that toggles the section, at least sm height with 14px medium text, neutral hover and pressed overlays, and a focus ring.
    iconOptional Tabler icon inside the trigger, secondary by default.
    hitAreaTransparent ::before centered on the trigger, never smaller than size-target-min (24px on mouse, 44px on touch).
    contentCollapsibleContent: the disclosed container, 14px secondary text, growing in on open and collapsing on close.
    bodyThe padded inner block inside the content, py-sm, so nothing shows while the container height is zero.

    Accessibility

    Role: generic

    KeysAction
    TabMoves focus to the trigger button and, when open, into the disclosed content.
    Space, EnterToggles the disclosed content open or closed.
    • CollapsibleTrigger is a button with aria-expanded and aria-controls pointing to CollapsibleContent.
    • Unlike Accordion, CollapsibleTrigger does not wrap itself in an h2-h4 heading, so it fits inside forms and inline status blocks.
    • Closed content unmounts after the collapse animation finishes, or at once under prefers-reduced-motion.

    Install

    npx werewolf-ui add https://www.werewolf-ui.dev/r/collapsible.json

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.