# Accordion

Vertically stacked collapsible sections built on Radix Accordion, with single or multiple open items, keyboard navigation, and animated expand and collapse.

- Category: Overlays & Navigation
- License: MIT
- Page: https://www.saasuji.com/components/accordion
- Install: npx shadcn@latest add https://www.saasuji.com/r/accordion.json

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| type (Accordion) | `"single" | "multiple"` | — | Whether one item or several items can be open at the same time; required. |
| collapsible (Accordion) | `boolean` | `false` | In single mode, allows the open item to close so no section stays expanded. |
| value (Accordion) | `string | string[]` | — | Controlled value of the open item or items. |
| defaultValue (Accordion) | `string | string[]` | — | Item value or values open on first render. |
| onValueChange (Accordion) | `(value: string | string[]) => void` | — | Called when the set of open items changes. |
| disabled (Accordion, AccordionItem) | `boolean` | `false` | Prevents the accordion root or a single item from being toggled. |
| value (AccordionItem) | `string` | — | Unique identifier matched against the root value to determine the open item; required. |
| asChild (AccordionTrigger, AccordionContent) | `boolean` | `false` | Merges props onto a single child element instead of rendering the default button or panel. |
| className (Accordion, AccordionItem, AccordionTrigger, AccordionContent) | `string` | — | Additional classes merged onto the part that receives it. |
| children (Accordion, AccordionItem, AccordionTrigger, AccordionContent) | `React.ReactNode` | — | Trigger label and collapsible panel content; items sit inside the root and trigger/content pairs inside each item. |
| ...props (Accordion) | `React.ComponentProps<typeof AccordionPrimitive.Root>` | — | All remaining Radix Accordion root props are forwarded (dir, orientation, …). |
| ...props (AccordionItem) | `React.ComponentProps<typeof AccordionPrimitive.Item>` | — | All remaining Radix Accordion item props are forwarded to the rendered div. |
| ...props (AccordionTrigger) | `React.ComponentProps<typeof AccordionPrimitive.Trigger>` | — | All remaining Radix trigger props are forwarded to the rendered button. |
| ...props (AccordionContent) | `React.ComponentProps<typeof AccordionPrimitive.Content>` | — | All remaining Radix content props are forwarded (forceMount, …). |

## Source

```tsx
"use client"

import * as React from "react"
import ChevronDownIcon from "lucide-react/dist/esm/icons/chevron-down"
import { Accordion as AccordionPrimitive } from "radix-ui"

import { cn } from "@/lib/utils"

function Accordion({
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
  return <AccordionPrimitive.Root data-slot="accordion" {...props} />
}

function AccordionItem({
  className,
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
  return (
    <AccordionPrimitive.Item
      data-slot="accordion-item"
      className={cn("border-b last:border-b-0", className)}
      {...props}
    />
  )
}

function AccordionTrigger({
  className,
  children,
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
  return (
    <AccordionPrimitive.Header className="flex">
      <AccordionPrimitive.Trigger
        data-slot="accordion-trigger"
        className={cn(
          "flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
          className
        )}
        {...props}
      >
        {children}
        <ChevronDownIcon className="pointer-events-none size-4 shrink-0 translate-y-0.5 text-muted-foreground transition-transform duration-200" />
      </AccordionPrimitive.Trigger>
    </AccordionPrimitive.Header>
  )
}

function AccordionContent({
  className,
  children,
  ...props
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
  return (
    <AccordionPrimitive.Content
      data-slot="accordion-content"
      className="overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
      {...props}
    >
      <div className={cn("pt-0 pb-4", className)}>{children}</div>
    </AccordionPrimitive.Content>
  )
}

export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }

```
