Accordion

A vertically stacked set of interactive headings that each reveal a section of content.

Yes. It adheres to the WAI-ARIA design pattern.

Installation

pnpm dlx cubix@latest add accordion --base aria

Usage

Import
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@/components/cubix/accordion"
Example
<Accordion defaultValue={["item-1"]} className="w-full">
  <AccordionItem value="item-1">
    <AccordionTrigger>Is it accessible?</AccordionTrigger>
    <AccordionContent>
      Yes. It adheres to the WAI-ARIA design pattern.
    </AccordionContent>
  </AccordionItem>
  <AccordionItem value="item-2">
    <AccordionTrigger>Is it styled?</AccordionTrigger>
    <AccordionContent>
      Yes. It comes with default styles that match the other Cubix
      components.
    </AccordionContent>
  </AccordionItem>
  <AccordionItem value="item-3">
    <AccordionTrigger>Is it animated?</AccordionTrigger>
    <AccordionContent>
      Yes. The content opens and closes with a height animation.
    </AccordionContent>
  </AccordionItem>
</Accordion>

Examples

Multiple

Set multiple to keep more than one item open at a time.

Yes. Pass multiple to keep more than one section open.

Pass an array to defaultValue or value when multiple is set.

Single item

Omit multiple so only one item is open at a time. Click the open item to close it.

Opening another item closes this one. Click the trigger again to collapse it.

Disabled

This item can be opened and closed.

RTL

Wrap the accordion in dir="rtl" and lang="fa" so layout, chevron placement, and IRANSans XV follow Persian.

بله. از الگوی WAI-ARIA پیروی می‌کند.

API Reference

Accordion

The root that manages open state and keyboard movement between triggers.

PropTypeDefaultDescription
multiplebooleanfalseWhen true, more than one item can stay open at a time.
valuestring[]-Controlled open values.
defaultValuestring[]-Initial open value(s) for uncontrolled usage.
onValueChange(value: string[]) => void-Called when the open value(s) change.
classNamestring-Additional Tailwind classes merged with the root styles (last one wins).

AccordionItem

A single section. Wrap a trigger and content and give it a unique value.

PropTypeDefaultDescription
valuestring-Unique value used to control this item. Required.
disabledbooleanfalseDisables the trigger and prevents this item from opening.
classNamestring-Additional Tailwind classes merged with the item styles (last one wins).

AccordionTrigger

The heading button that opens and closes the section.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the trigger styles (last one wins).
...propsReact.ComponentProps<'button'>-All native button attributes are forwarded to the trigger.

AccordionContent

The collapsible panel revealed by the trigger.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the content styles (last one wins).
...propsReact.ComponentProps<'div'>-All native div attributes are forwarded to the content panel.