Collapsible
A trigger that shows or hides one panel of content.
Installation
npx shadcn@latest add @oakoss/collapsibleUsage
import { buttonStyles } from '#/components/ui/inputs/button';
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '#/components/ui/layout/collapsible';
<Collapsible>
<CollapsibleTrigger className={buttonStyles({ variant: 'outline' })}>
Order details
</CollapsibleTrigger>
<CollapsibleContent>Ships in two days.</CollapsibleContent>
</Collapsible>;CollapsibleTrigger has no look of its own beyond the focus outline, so it
takes any button style. Put vertical padding on the content, not the panel,
since the panel's own padding would show while it's closed.
Examples
Open by default
defaultExpanded starts the panel open; isExpanded with
onExpandedChange controls it.
Adds Accordion and Collapsible, with animated panels.
Accessibility
React Aria renders the trigger as a button with aria-expanded, linked to its
panel with aria-controls. A closed panel is hidden="until-found", so the
browser's find-in-page still searches it and opens it on a match. The panel
clips only while it's closed or its height animates, so once open, a control
at the content's edge shows its whole focus outline.
| Key | Action |
|---|---|
Space | Opens or closes the panel |
Enter | Opens or closes the panel |
Follows the WAI-ARIA disclosure pattern.
API
Collapsible
Extends React Aria's Disclosure,
and accepts all its props.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always collapsible |
data-expanded | It's open |
data-disabled | isDisabled is set |
CollapsibleTrigger
Extends React Aria's Button, and
accepts all its props.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always collapsible-trigger |
data-focus-visible | It has keyboard focus |
data-disabled | The collapsible is disabled |
CollapsibleContent
Extends React Aria's
DisclosurePanel, and accepts
all its props. Its height animates from React Aria's
--disclosure-panel-height.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | Always collapsible-content |
data-focus-visible-within | Something inside it has keyboard focus |