Accordion
A collapsible accordion component with single and multiple expand modes, built on Radix UI.
Basic
Collapsible content sections for organizing information. Supports single and multiple expand modes with animated transitions.
Installation
Install the component via the CLI in one command.
npx @work-rjkashyap/unified-ui add accordionpnpm dlx @work-rjkashyap/unified-ui add accordionnpx @work-rjkashyap/unified-ui add accordionbunx @work-rjkashyap/unified-ui add accordionIf you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.
Or install the full package
Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.
npm install @work-rjkashyap/unified-uipnpm add @work-rjkashyap/unified-uiyarn add @work-rjkashyap/unified-uibun add @work-rjkashyap/unified-uiAnatomy
import {
Accordion,
AccordionItem,
AccordionTrigger,
AccordionContent,
} from "@work-rjkashyap/unified-ui";Single Expand Mode
Only one item can be open at a time. Set collapsible to allow closing all items.
Multiple Expand Mode
Multiple items can be open simultaneously.
Variants
Bordered (default)
The default variant renders items with borders between them.
Borderless
A cleaner look without dividing borders. Useful inside cards or already-bordered containers.
Sizes
Two sizes are available for different content density needs.
Small
Medium (default)
Disabled Items
Individual accordion items can be disabled.
Controlled
Control the expanded state externally with value and onValueChange.
// Single mode
const [value, setValue] = useState("item-1");
<Accordion type="single" collapsible value={value} onValueChange={setValue}>
<AccordionItem value="item-1">
<AccordionTrigger>Section 1</AccordionTrigger>
<AccordionContent>Content 1</AccordionContent>
</AccordionItem>
<AccordionItem value="item-2">
<AccordionTrigger>Section 2</AccordionTrigger>
<AccordionContent>Content 2</AccordionContent>
</AccordionItem>
</Accordion>;
// Multiple mode
const [values, setValues] = useState(["item-1"]);
<Accordion type="multiple" value={values} onValueChange={setValues}>
<AccordionItem value="item-1">
<AccordionTrigger>Section 1</AccordionTrigger>
<AccordionContent>Content 1</AccordionContent>
</AccordionItem>
<AccordionItem value="item-2">
<AccordionTrigger>Section 2</AccordionTrigger>
<AccordionContent>Content 2</AccordionContent>
</AccordionItem>
</Accordion>;FAQ Pattern
A common pattern for FAQ sections.
Props
Accordion
| Prop | Type | Default | Description |
|---|---|---|---|
type | "single" | "multiple" | required | Whether one or multiple items can be open. |
collapsible | boolean | false | Allow closing all items (single mode only). |
value | string | string[] | — | Controlled expanded value(s). |
defaultValue | string | string[] | — | Default expanded value(s) (uncontrolled). |
onValueChange | (value: string | string[]) => void | — | Callback when expanded state changes. |
variant | "bordered" | "borderless" | "bordered" | Visual variant. |
size | "sm" | "md" | "md" | Size of the accordion items. |
className | string | — | Additional CSS classes. |
AccordionItem
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | required | Unique identifier for this item. |
disabled | boolean | false | Whether this item is disabled. |
className | string | — | Additional CSS classes. |
AccordionTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Additional CSS classes. |
children | ReactNode | — | Trigger label content. |
AccordionContent
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Additional CSS classes. |
children | ReactNode | — | Collapsible content. |
Accessibility
Built on @radix-ui/react-accordion which provides full WAI-ARIA Accordion pattern compliance.
- Keyboard navigation —
Enter/Spacetoggles an item.Arrow Up/Arrow Downmoves focus between triggers.Home/Endjumps to first/last trigger. - Focus ring — Visible on keyboard navigation via
focus-visible. - ARIA attributes —
aria-expanded,aria-controls, androleattributes are managed automatically by Radix. - Disabled — Disabled items are excluded from keyboard navigation and marked with
aria-disabled. - Animation — Content expand/collapse uses CSS grid animation. Respects
prefers-reduced-motion. - Chevron indicator — Rotates 180° when the item is expanded, providing a visual cue for the current state.
Design Tokens
| Token | Usage |
|---|---|
--foreground | Trigger text color |
--muted-foreground | Trigger hover and content text |
--border | Bordered variant dividers |
--duration-normal | Chevron rotation and content animation |
--easing-standard | Animation easing curve |