# Accordion

> List of expandable items built from an array, in three variants, with a chevron or plus icon and optional single-open behavior.

- Kind: ui · Category: Data display · Interactivity: native
- Install: `npx shadcn@latest add @haze/accordion`
- File: `src/components/haze/ui/accordion.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/accordion

## Use when
- A short list of questions and answers or settings groups, written as plain text
- Keeping a long help page scannable with one open item at a time
- Content that comes from data rather than from hand-written markup

## Avoid when
- Items need rich content such as links or images; stack collapsible components instead
- A full-width FAQ section; use the faq blocks

## Alternatives
- [collapsible](https://hazeui.com/ui/collapsible.md)
- [tabs](https://hazeui.com/ui/tabs.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| items | `{ title: string; content: string; open?: boolean }[]` |  | yes | One entry per row; content renders as one paragraph. |
| name | `string` |  | no | Shared details name; when set, opening one item closes the others. |
| variant | `"contained" \| "plain" \| "separated"` | "contained" | no | contained: one bordered panel with dividers. plain: hairlines only, for long FAQ lists. separated: each item is its own panel. |
| icon | `"chevron" \| "plus"` | "chevron" | no | chevron turns over when the item opens. plus turns into a cross. |
| class | `string` |  | no | Extra classes on the outer element. |

## Accessibility
- Each row is a native details element, so the summary is announced as an expandable button without extra ARIA.
- In the contained and plain variants rows are separated by hairline dividers, so the group reads as a single list; in separated each row is its own panel.
- The panel animates its height over 300 ms where the browser supports interpolate-size; elsewhere its content rises in. Both are switched off under prefers-reduced-motion.
- With a name set, the browser closes the previous item itself and no script runs.
- Key Enter / Space: Open or close the focused item
- Key Tab: Move to the next item's summary

## Agent prompts

### Install and use

Install the Haze UI component "Accordion" with `npx shadcn@latest add @haze/accordion`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Accordion from "@/components/haze/ui/accordion.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/accordion.md

### Customize with real content

Adapt the Haze accordion ui for our product. Replace the demo values of these props with our real content: items, name, variant, icon, class. Keep the layout, the heading level rules and these accessibility details: Each row is a native details element, so the summary is announced as an expandable button without extra ARIA. In the contained and plain variants rows are separated by hairline dividers, so the group reads as a single list; in separated each row is its own panel. The panel animates its height over 300 ms where the browser supports interpolate-size; elsewhere its content rises in. Both are switched off under prefers-reduced-motion. With a name set, the browser closes the previous item itself and no script runs. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using accordion, check it fits: use it when a short list of questions and answers or settings groups, written as plain text; keeping a long help page scannable with one open item at a time; content that comes from data rather than from hand-written markup. Avoid it when items need rich content such as links or images; stack collapsible components instead; a full-width faq section; use the faq blocks. Alternatives: @haze/collapsible, @haze/tabs.

## Example requests that should lead here
- Add an accordion with four billing questions, one open at a time
- Show three shipping answers with the first item open

## Source

```astro
---
import { ChevronDown, Plus } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Item {
  title: string;
  content: string;
  open?: boolean;
}

interface Props {
  items: Item[];
  /** When set, only one item is open at a time. */
  name?: string;
  /** contained: one bordered panel. plain: hairlines only, for long FAQ lists. separated: each item is its own panel. */
  variant?: "contained" | "plain" | "separated";
  /** chevron turns over when the item opens. plus turns into a cross. */
  icon?: "chevron" | "plus";
  class?: string;
}

const { items, name, variant = "contained", icon = "chevron", class: className } = Astro.props;

const roots = {
  contained: "divide-y divide-border overflow-hidden rounded-xl border border-border bg-card",
  plain: "divide-y divide-border border-y border-border",
  separated: "grid gap-2",
};
const itemLooks = {
  contained: "",
  plain: "",
  separated:
    "overflow-hidden rounded-xl border border-border bg-card transition-[border-color] duration-200 ease-snappy open:border-border-strong",
};
const summaries = {
  contained: "px-4 [details:not([open])>&]:hover:bg-accent",
  plain: "px-0 hover:text-foreground/80",
  separated: "px-4 [details:not([open])>&]:hover:bg-accent",
};
const bodies = { contained: "px-4", plain: "px-0", separated: "px-4" };

// Where the browser can animate to height:auto, the panel slides open and shut. Elsewhere its content rises in.
const slide =
  "supports-[interpolate-size:allow-keywords]:[interpolate-size:allow-keywords] supports-[interpolate-size:allow-keywords]:details-content:h-0 supports-[interpolate-size:allow-keywords]:details-content:overflow-clip supports-[interpolate-size:allow-keywords]:details-content:transition-[height,content-visibility] supports-[interpolate-size:allow-keywords]:details-content:transition-discrete supports-[interpolate-size:allow-keywords]:details-content:duration-300 supports-[interpolate-size:allow-keywords]:details-content:ease-snappy supports-[interpolate-size:allow-keywords]:open:details-content:h-auto";
const Icon = icon === "plus" ? Plus : ChevronDown;
---

<div class={cn(roots[variant], className)}>
  {
    items.map((item) => (
      <details name={name} open={item.open} class={cn(slide, itemLooks[variant])}>
        <summary
          class={cn(
            "flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 py-3 text-[0.8125rem]/5 font-medium text-foreground transition-colors duration-150 ease-snappy focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&::-webkit-details-marker]:hidden",
            summaries[variant],
          )}
        >
          <span>{item.title}</span>
          <Icon
            class={cn(
              "size-4 shrink-0 text-muted-foreground transition-[rotate,color] duration-200 ease-spring motion-reduce:transition-none [[open]>summary_&]:text-foreground",
              icon === "plus" ? "[[open]>summary_&]:rotate-45" : "[[open]>summary_&]:rotate-180",
            )}
            aria-hidden="true"
          />
        </summary>
        <div class={cn("pb-4 text-[0.8125rem]/5 text-muted-foreground not-supports-[interpolate-size:allow-keywords]:animate-rise", bodies[variant])}>
          <p>{item.content}</p>
        </div>
      </details>
    ))
  }
</div>
```
