Skip to content
Redpanda UI
Esc
↑↓navigate↵open⌘Jpreview
Made by imskyleen
Edit on GitHub

Collapsible

An interactive component which expands/collapses a panel.

Installation

bash
npx shadcn@latest add @redpanda/collapsible
bash
pnpm dlx shadcn@latest add @redpanda/collapsible
bash
yarn dlx shadcn@latest add @redpanda/collapsible
bash
bunx shadcn@latest add @redpanda/collapsible
bash
nubx shadcn@latest add @redpanda/collapsible
bash
aube dlx shadcn@latest add @redpanda/collapsible

Controlled

Multiple independent collapsibles

Disabled

Default open

Chevron on leading edge

Reveal sensitive content

Usage

tsx
<Collapsible>  <CollapsibleTrigger>Collapsible Trigger</CollapsibleTrigger>  <CollapsibleContent>Collapsible Content</CollapsibleContent></Collapsible>

When to use

Use this decision tree to determine when to use the Collapsible component:

Props

Keyboard interactions

Key Action
Enter / Space on CollapsibleTrigger Toggles the panel open / closed.
Tab Moves focus to the next focusable element (including into the panel when open).

Accessibility

  • The trigger exposes aria-expanded + aria-controls pointing at the panel; Base UI sets the native data-open (root/trigger) / data-panel-open (panel) attributes you can target with CSS selectors.
  • The trigger must be a real button (or another focusable element via the render prop); static <div> triggers lose keyboard activation.
  • Use keepMounted on CollapsibleContent when the hidden content must remain in the DOM for SEO, intersection observers, or mid-animation measurements.

Controlled vs uncontrolled

Uncontrolled — trigger toggles the panel locally:

tsx
<Collapsible>  <CollapsibleTrigger>Toggle</CollapsibleTrigger>  <CollapsibleContent>{/* ... */}</CollapsibleContent></Collapsible>

Controlled — drive open from parent state (e.g. expand all / collapse all from a toolbar):

tsx
const [open, setOpen] = useState(false);
<Collapsible open={open} onOpenChange={setOpen}>  <CollapsibleTrigger>Toggle</CollapsibleTrigger>  <CollapsibleContent>{/* ... */}</CollapsibleContent></Collapsible>;

Don’t delete from the DOM

The choice made (also Base UI’s default) is to remove the element from the DOM for accessibility and performance reasons. However, this may pose a problem for SEO. If you want your Collapsible content to be taken into account by Google, pass keepMounted to CollapsibleContent — the closed panel stays in the DOM (hidden via the hidden attribute):

tsx
<Collapsible>  <CollapsibleTrigger>Toggle</CollapsibleTrigger>  <CollapsibleContent keepMounted>{/* stays in the DOM while closed */}</CollapsibleContent></Collapsible>

To additionally let the browser’s find-in-page (Ctrl/Cmd + F) reveal the closed content, use hiddenUntilFound instead (implies keepMounted and hides the panel with hidden="until-found"):

tsx
<CollapsibleContent hiddenUntilFound>{/* discoverable by find-in-page */}</CollapsibleContent>

Credits

  • We use Base UI for the collapsible component.
  • We take our inspiration from Shadcn UI for the collapsible style.

Recent changes

  • patchv1.2.0Pin shipped dependency floors to the version we develop against. Registry items now declare ranges like `^5.1.9` (the actual installed version) instead of collapsing to `^5.0.0`, so consumers start on the known-tested baseline while caret semantics still allow any compatible release within the same major.#133
  • minorv1.1.0Theme docs refresh, readability pass on semantic foregrounds, and consumer-facing Base UI regression fixes.#121
  • minorv1.0.0Post-Base-UI polish. Public API unchanged.#116
  • majorv1.0.0Migrate every Radix-based primitive to `@base-ui/react@^1.4.0` (Base UI).#114
  • patchv0.3.1## 🚧 Updated#112
See full history →

Last updated on

Was this page helpful?