Accordion
Web/MobileA vertically stacked set of interactive headings that each reveal a section of content.
Installation
pnpm dlx cubix-ui@latest add accordion --base radixUsage
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/cubix/accordion"
const faqs = [
{
value: "accessible",
question: "آیا دسترسپذیر است؟",
answer: "بله. از الگوی WAI-ARIA پیروی میکند و همه بخشها با صفحهکلید باز و بسته میشوند.",
},
{
value: "styled",
question: "آیا ظاهر آماده دارد؟",
answer: "بله. با توکنهای Cubix رنگآمیزی شده و در حالت تیره هم درست نمایش داده میشود.",
},
{
value: "animated",
question: "آیا انیمیشن دارد؟",
answer:
"بله. ارتفاع بخشها نرم تغییر میکند و اگر کاهش حرکت در سیستم فعال باشد، انیمیشن حذف میشود.",
},
]
<Accordion defaultValue={["accessible"]} className="w-full max-w-md">
{faqs.map((item) => (
<AccordionItem key={item.value} value={item.value}>
<AccordionTrigger>{item.question}</AccordionTrigger>
<AccordionContent>{item.answer}</AccordionContent>
</AccordionItem>
))}
</Accordion>
Composition
Each AccordionItem holds one trigger and one content panel and is identified by its value. The chevron sits at the inline end, so it moves to the left in RTL without a flip.
Accordion
└── AccordionItem (value)
├── AccordionTrigger
└── AccordionContentAccessibility
Every trigger is a button inside an h3, so the section titles stay in the page outline. The trigger exposes aria-expanded and aria-controls, and each panel is a region labelled by its trigger. Panel height animates and the animation is removed when reduced motion is on.
| Key | Action |
|---|---|
| Enter / Space | Open or close the focused item. |
| Tab / Shift + Tab | Move to the next or previous focusable element on the page. |
| ArrowDown / ArrowUp | Move focus to the next or previous enabled trigger of the same accordion, wrapping at the ends. |
| Home / End | Move focus to the first or last enabled trigger. |
Examples
Multiple
Set multiple to keep any number of items open and pass every open item to defaultValue.
Controlled
Pass value and onValueChange to own the open items, for example to open or close every item from outside. Both modes use a string[]; in single mode it holds at most one value.
Disabled item
Set disabled on an AccordionItem to keep it visible but locked. Arrow key navigation skips it.
Disabled
Set disabled on Accordion to lock every item in its current state, for example a finished order timeline.
With icon
Pass icon to AccordionTrigger to show an icon at the inline start, before the heading text. The icon is hidden from assistive technology and SVGs default to 24px.
Custom styling
Every part accepts a className merged with cn. Here each item is a separate card with a muted surface, and the root adds a gap between them.
API Reference
Note: Parts render data-slot attributes (accordion, accordion-item, accordion-header, accordion-trigger, accordion-trigger-title, accordion-trigger-icon-start, accordion-trigger-icon, accordion-content) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.
Accordion
| Prop | Type | Default | Description |
|---|---|---|---|
| multiple | boolean | false | Keep more than one item open. Without it, opening an item closes the open one, and the open trigger closes its own item. |
| value | string[] | - | Controlled open items. Use an array in both modes and pass at most one value in single mode. |
| defaultValue | string[] | - | Items open on first render when uncontrolled. |
| onValueChange | (value: string[]) => void | - | Called with the open items whenever an item opens or closes. |
| disabled | boolean | false | Disable every item in the accordion. |
| dir | "ltr" | "rtl" | - | Text direction of the accordion. Defaults to the closest dir on the page. |
| lang | string | - | Language of the accordion. Defaults to the closest lang on the page. |
| className | string | - | Additional Tailwind classes merged with the root styles (last one wins). |
AccordionItem
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Unique value used in value, defaultValue and onValueChange. Required. |
| disabled | boolean | false | Disable the trigger and keep the item in its current state. Arrow key navigation skips it. |
| className | string | - | Additional Tailwind classes merged with the item styles (last one wins). |
AccordionTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Heading text. The chevron is added at the inline end and turns when the item opens. |
| icon | ReactNode | - | Icon rendered at the inline start, before the heading text, and hidden from assistive technology. SVGs default to 24px unless they set their own size- class. |
| className | string | - | Additional Tailwind classes merged with the trigger button styles (last one wins). |
AccordionContent
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Content revealed when the item opens. |
| className | string | - | Additional Tailwind classes merged with the inner content wrapper (last one wins). The outer panel keeps the height animation. |