Skip to content

React Collapsible Component

A React collapsible section that animates its height and keeps closed content out of the page and the tab order. Use it as an expandable section for an Advanced options link at the bottom of a form, so retry limits, timeouts and proxy settings stay out of the way until someone needs them.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/collapsible.json

Basic

Use Accordion when opening one section should close another.

Files to copy

4 folders · 1 file · 4 packages
From theme/src/
  • components/collapsible/
  • components/status-icons/
  • lib/cn.ts
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/collapsible.jsonRegistry item: collapsible. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/button/
  • components/spinner/
  • hooks/{use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, tokens.ts}
  • lib/{form.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Controlled

open and onOpenChange drive it from outside. keepMounted holds the content in the DOM (hidden) so form fields inside keep their values.

Collapsible props

PropTypeDefaultDescription
open / defaultOpenbooleanfalseControlled / uncontrolled open state.
onOpenChange(open: boolean) => voidNoneCalled when it opens or closes.
disabledbooleanfalseLocks the section so it cannot be toggled.
classNamestringNoneAdds extra classes to the root.

CollapsibleTrigger and CollapsiblePanel

PropTypeDefaultDescription
hideIconbooleanfalseHide the chevron (for a custom indicator; read data-panel-open on the trigger).
contentClassNamestringNoneExtra classes for the padded box inside the panel.
render (Trigger)ReactElementNoneReplaces the button with another element.
keepMounted (Panel)booleanfalseKeep closed content in the DOM, hidden.
hiddenUntilFound (Panel)booleanfalseUse hidden=until-found so find-in-page opens it.

Keyboard

KeysAction
TabFocuses the trigger.
Enter/SpaceOpens or closes the panel.

Accessibility

  • The trigger is a real <button> with aria-expanded and aria-controls (Base UI Collapsible).
  • Closed content is removed from the page, so its links and fields are neither tabbable nor read. keepMounted keeps it in the DOM but hidden; hiddenUntilFound lets find-in-page open it.
  • The chevron is decorative. Triggers are 44px tall on touch screens and show a focus ring.
  • Under reduced motion the panel jumps to its open or closed height with no travel.

When to use Collapsible

  • Use it for rarely needed settings at the end of a form, such as retry limits, timeouts and proxy fields behind an Advanced options toggle, so the common path stays short.
  • Use it for a Show more list in a file panel or a changelog, where twelve extra rows hide behind one trigger and the section can also be opened from a button elsewhere.
  • Use keepMounted when fields inside the section must keep their values while closed, or hiddenUntilFound when the hidden text should still be reachable with the browser's find-in-page.
  • Skip it when opening one section should close the others; Accordion manages that for a group, and Dialog or Popover is better when the content should not push the page down.
  • Pair it with Button to open it from outside using open and onOpenChange, with Switch and Field for the options inside the panel, and Badge to show a count in the trigger.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .