oakoss/ui
Components

Collapsible

A trigger that shows or hides one panel of content.

SourceReact Aria

Installation

npx shadcn@latest add @oakoss/collapsible

Usage

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.

KeyAction
SpaceOpens or closes the panel
EnterOpens or closes the panel

Follows the WAI-ARIA disclosure pattern.

API

Collapsible

Extends React Aria's Disclosure, and accepts all its props.

Data attributes

AttributePresent when
data-slotAlways collapsible
data-expandedIt's open
data-disabledisDisabled is set

CollapsibleTrigger

Extends React Aria's Button, and accepts all its props.

Data attributes

AttributePresent when
data-slotAlways collapsible-trigger
data-focus-visibleIt has keyboard focus
data-disabledThe 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

AttributePresent when
data-slotAlways collapsible-content
data-focus-visible-withinSomething inside it has keyboard focus