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.jsonCollapsibleCollapsiblePanelCollapsibleTrigger- +1 more
Basic
Use Accordion when opening one section should close another.
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@/components/sheenui/collapsible/collapsible";
// Package build (after the first npm release, or a packed tarball): import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@sheenui/theme";
export function Example() {
return (
<Collapsible className="glass-2 max-w-md rounded-sheen-xl p-2">
<CollapsibleTrigger>Advanced options</CollapsibleTrigger>
<CollapsiblePanel>
Retry limit, request timeout and proxy settings live here. The panel animates its height and keeps
closed content out of the page.
</CollapsiblePanel>
</Collapsible>
);
}Files to copy
4 folders · 1 file · 4 packages
- From
theme/src/ components/collapsible/components/status-icons/lib/cn.tsstyles/
- 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.
- report-q1.pdf
- report-q2.pdf
- report-q3.pdf
import { useState } from "react";
import { Button } from "@/components/sheenui/button/button";
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@/components/sheenui/collapsible/collapsible";
// Package build (after the first npm release, or a packed tarball): import { Button, Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
const [open, setOpen] = useState(false);
return (
<div className="flex w-full max-w-md flex-col gap-3">
<Button variant="glass" size="sm" className="self-start" onClick={() => setOpen((o) => !o)}>
{open ? "Collapse" : "Expand"} from outside
</Button>
<Collapsible open={open} onOpenChange={setOpen} className="glass-2 rounded-sheen-xl p-2">
<CollapsibleTrigger>12 more files</CollapsibleTrigger>
<CollapsiblePanel keepMounted>
<ul className="list-disc ps-5">
<li>report-q1.pdf</li>
<li>report-q2.pdf</li>
<li>report-q3.pdf</li>
</ul>
</CollapsiblePanel>
</Collapsible>
</div>
);
}Collapsible props
CollapsibleTrigger and CollapsiblePanel
Keyboard
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
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .