Accordion

Web/Mobile

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

بله. از الگوی WAI-ARIA پیروی می‌کند و همه بخش‌ها با صفحه‌کلید باز و بسته می‌شوند.

Installation

pnpm dlx cubix-ui@latest add accordion --base radix

Usage

Import
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:
      "بله. ارتفاع بخش‌ها نرم تغییر می‌کند و اگر کاهش حرکت در سیستم فعال باشد، انیمیشن حذف می‌شود.",
  },
]
Example
<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.

Structure
Accordion
└── AccordionItem (value)
    ├── AccordionTrigger
    └── AccordionContent

Accessibility

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.

KeyAction
Enter / SpaceOpen or close the focused item.
Tab / Shift + TabMove to the next or previous focusable element on the page.
ArrowDown / ArrowUpMove focus to the next or previous enabled trigger of the same accordion, wrapping at the ends.
Home / EndMove 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

PropTypeDefaultDescription
multiplebooleanfalseKeep more than one item open. Without it, opening an item closes the open one, and the open trigger closes its own item.
valuestring[]-Controlled open items. Use an array in both modes and pass at most one value in single mode.
defaultValuestring[]-Items open on first render when uncontrolled.
onValueChange(value: string[]) => void-Called with the open items whenever an item opens or closes.
disabledbooleanfalseDisable every item in the accordion.
dir"ltr" | "rtl"-Text direction of the accordion. Defaults to the closest dir on the page.
langstring-Language of the accordion. Defaults to the closest lang on the page.
classNamestring-Additional Tailwind classes merged with the root styles (last one wins).

AccordionItem

PropTypeDefaultDescription
valuestring-Unique value used in value, defaultValue and onValueChange. Required.
disabledbooleanfalseDisable the trigger and keep the item in its current state. Arrow key navigation skips it.
classNamestring-Additional Tailwind classes merged with the item styles (last one wins).

AccordionTrigger

PropTypeDefaultDescription
childrenReactNode-Heading text. The chevron is added at the inline end and turns when the item opens.
iconReactNode-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.
classNamestring-Additional Tailwind classes merged with the trigger button styles (last one wins).

AccordionContent

PropTypeDefaultDescription
childrenReactNode-Content revealed when the item opens.
classNamestring-Additional Tailwind classes merged with the inner content wrapper (last one wins). The outer panel keeps the height animation.