oakoss/ui
Components

Accordion

Stacked sections that each show or hide their content.

SourceReact Aria

Orders ship within two business days and arrive in three to five.

Installation

npx shadcn@latest add @oakoss/accordion

Usage

import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from '#/components/ui/layout/accordion';

<Accordion>
  <AccordionItem id="shipping">
    <AccordionTrigger>Shipping</AccordionTrigger>
    <AccordionContent>Orders ship within two days.</AccordionContent>
  </AccordionItem>
</Accordion>;

Examples

Multiple

allowsMultipleExpanded lets several sections stay open at once; by default, opening one closes the others.

Change your name, email and password.

Update your card and see past invoices.

Accessibility

React Aria renders each section's trigger as a button with aria-expanded, linked to its panel with aria-controls, and the panel as a group labelled by its trigger. A closed panel is hidden="until-found", so the browser's find-in-page still searches it and opens the section on a match.

This component adds:

  • Headings: each trigger sits in a heading, level 3 by default. Set headingLevel on AccordionTrigger to fit the page's outline.
  • Target size: triggers are at least 44px tall.
  • Focus: the focus outline shows on triggers. The panel clips only while it's closed or animating, so once open, a control at the content's edge shows its whole outline.
  • Right to left: the label starts at the right and the chevron sits at the row's other end. The chevron turns over when open, so it needs no mirroring, and takes the trigger's text color in Windows High Contrast.
KeyAction
TabMoves focus to the next focusable element, including content in open sections
SpaceOpens or closes the focused section
EnterOpens or closes the focused section

React Aria adds no arrow keys between triggers, which the WAI-ARIA pattern lists as optional. Follows the WAI-ARIA accordion pattern.

API

Accordion

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

Data attributes

AttributePresent when
data-slotAlways accordion
data-disabledisDisabled is set

AccordionItem

Extends React Aria's Disclosure, and accepts all its props. Its id is the key expandedKeys refers to.

Data attributes

AttributePresent when
data-slotAlways accordion-item
data-expandedIt's open
data-disabledIt or the accordion is disabled

AccordionTrigger

Extends React Aria's Button, inside a Heading.

Props

Prop

Type

Also accepts all React Aria Button props.

Data attributes

AttributePresent when
data-slotAlways accordion-trigger; the chevron is accordion-trigger-icon
data-hoveredA pointer hovers it
data-focus-visibleIt has keyboard focus
data-disabledIts item is disabled

AccordionContent

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 accordion-content
data-focus-visible-withinSomething inside it has keyboard focus