Skip to content
All components
Data display

Collapsible

Show or hide one optional region in place with a single trigger, keeping secondary detail out of the way until someone asks for it.

A single animated disclosure.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add collapsible

Then import it from @/components/ui/collapsible. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Show more

Reveal the rest of a list with a show more trigger. The trigger label states how many items are hidden and changes when the list is expanded. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"

const contributors = [
  "Amara Okafor",
  "Bruno Costa",
  "Chen Wei",
  "Dana Levi",
  "Elif Yilmaz",
  "Farah Haddad",
  "Goran Petrov",
  "Hana Sato",
]

function ShowMoreList() {
  const [open, setOpen] = React.useState(false)
  const visible = contributors.slice(0, 3)
  const hidden = contributors.slice(3)

  return (
    <Collapsible open={open} onOpenChange={setOpen} className="flex w-full max-w-md flex-col gap-2">
      <p id="collapsible-contributors" className="text-label-sm text-strong-950">
        Contributors ({contributors.length})
      </p>
      <ul aria-labelledby="collapsible-contributors" className="flex flex-col gap-1 text-paragraph-sm text-sub-600">
        {visible.map((name) => (
          <li key={name}>{name}</li>
        ))}
      </ul>
      <CollapsibleContent>
        <ul aria-label="More contributors" className="flex flex-col gap-1 text-paragraph-sm text-sub-600">
          {hidden.map((name) => (
            <li key={name}>{name}</li>
          ))}
        </ul>
      </CollapsibleContent>
      <CollapsibleTrigger asChild>
        <Button type="button" size="xs" intent="neutral" emphasis="ghost" className="self-start">
          {open ? "Show fewer contributors" : `Show ${hidden.length} more contributors`}
        </Button>
      </CollapsibleTrigger>
    </Collapsible>
  )
}

export function CollapsibleShowMore() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <ShowMoreList />
    </div>
  )
}

Open by default

Start a disclosure open with defaultOpen. The whole header row is the trigger and a decorative chevron reflects the state. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { ChevronDownIcon } from "lucide-react"

import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"

export function CollapsibleOpenByDefault() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <Collapsible defaultOpen className="group/release w-full max-w-md rounded-12 border border-soft-200 p-3">
        <CollapsibleTrigger className="flex w-full items-center justify-between gap-4 rounded-8 text-left text-label-sm text-strong-950 outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-base focus-visible:outline-solid">
          Release notes, version 2.4
          <ChevronDownIcon
            aria-hidden="true"
            className="size-4 shrink-0 text-soft-400 transition-transform group-data-[state=open]/release:rotate-180 motion-reduce:transition-none"
          />
        </CollapsibleTrigger>
        <CollapsibleContent>
          <ul className="mt-3 flex list-disc flex-col gap-1 ps-5 text-paragraph-sm text-sub-600">
            <li>Search now matches file contents, not only names.</li>
            <li>Exports keep the column order you chose.</li>
            <li>Fixed a crash when a comment was edited offline.</li>
          </ul>
        </CollapsibleContent>
      </Collapsible>
    </div>
  )
}

Disabled trigger

Disable a disclosure and explain why next to it. Disabled stops toggling; the reason stays visible as text. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Button } from "@/components/ui/button"
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"

export function CollapsibleDisabledTrigger() {
  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <Collapsible disabled className="w-full max-w-md">
        <div className="flex items-center justify-between gap-4">
          <div className="flex min-w-0 flex-col gap-0.5">
            <p className="text-label-sm text-strong-950">Audit log</p>
            <p id="collapsible-audit-reason" className="text-paragraph-sm text-sub-600">
              Available on plans with audit history.
            </p>
          </div>
          <CollapsibleTrigger asChild>
            <Button
              type="button"
              emphasis="ghost"
              intent="neutral"
              size="xs"
              aria-describedby="collapsible-audit-reason"
            >
              Show audit log
            </Button>
          </CollapsibleTrigger>
        </div>
        <CollapsibleContent>
          <p className="mt-3 text-paragraph-sm text-sub-600">No entries.</p>
        </CollapsibleContent>
      </Collapsible>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Collapsible

Reveal or hide one optional content region.

Collapsible props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (18)
Collapsible inherited props
PropTypeDefaultDescription
defaultOpenboolean | undefined—Initial uncontrolled visibility state. Later changes use the primitive's controls or controlled open API.
openboolean | undefined—Controlled visibility state. Pair with onOpenChange so requested state changes can be applied.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
onOpenChange((open: boolean) => void) | undefined—Receive the requested open state. Apply it to open when controlled.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CollapsibleContent

Content region within the root composition. Keep required providers, labels and related controls from the complete example.

CollapsibleContent props
PropTypeDefaultDescription
forceMounttrue | undefined—Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (14)
CollapsibleContent inherited props
PropTypeDefaultDescription
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

CollapsibleTrigger

Interactive control that opens or toggles the associated content. Preserve its accessible name and the required root context.

CollapsibleTrigger props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (19)
CollapsibleTrigger inherited props
PropTypeDefaultDescription
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
namestring | undefined—Name used by the control's form submission or primitive form integration.
type"button" | "submit" | "reset" | undefined—Native element or primitive mode defined by the source union. Choose a supported value; its meaning depends on the component.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Accessibility & usage

From registry/ui/collapsible.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Progressive disclosure of secondary detail: advanced options, build output, release notes, a long explanation.
  • A 'Show more' list that reveals the remaining items below the first few.
  • A sidebar group or panel section that people can fold away, with the open state controlled by the app when it must persist.

When not to use

  • Several headed sections that behave as a set; an accordion gives them shared keyboard navigation and heading structure.
  • Information people must see to complete a task, such as an error or a required field.
  • Content that should cover the page or demand a decision; use a dialog or sheet.
  • A preview that appears on hover; use a hover card for supplemental content.

Anatomy

Collapsible
Radix root that owns open state: open/defaultOpen/onOpenChange and disabled. Renders a div that can carry layout classes.
CollapsibleTrigger
The button that toggles the region and exposes aria-expanded and aria-controls. Use asChild to render a TDPXL Button.
CollapsibleContent
The controlled region; animates height, is hidden and removed from the tab order when closed, and keeps consumer classes alongside its defaults.

Keyboard & interaction

  • Enter or Space on the trigger toggles the region (WAI-ARIA disclosure pattern); aria-expanded reports the state.
  • When the region opens, focus stays on the trigger; Tab continues into the revealed content in DOM order, so place the content right after the trigger or announce where it appeared.
  • disabled stops the trigger from toggling and removes it from the tab order; it does not close a region that is already open.
  • Controlled usage (open plus onOpenChange) lets the app persist state or change the trigger label ('Show more' and 'Show fewer').
  • Height animations stop when the user prefers reduced motion.

Responsive behavior

  • Triggers keep a target of at least 24x24 CSS pixels; on touch screens prefer making the whole header row the trigger.
  • Revealed content must reflow at 320 CSS pixels; give wide content (code, tables) its own scroll region.
  • On large screens, consider showing secondary detail by default with defaultOpen when there is room.

Content guidelines

  • Write the trigger as the action and its object: 'Show release notes', 'Show 5 more contributors', and switch to the reverse when open.
  • Include a count when revealing a list, so people know how much is hidden.
  • Keep the visible part meaningful on its own; the hidden part adds detail, not the main point.
  • When the trigger is disabled, explain why in visible text next to it.

Alternatives

  • Accordion — A list of headed sections that expand and collapse with arrow-key navigation between triggers.
  • Dialog — Focused content or a decision that interrupts the page.
  • Tabs — Switching between peer views that are always one-of-many.

Resources