# Accordion

Sections that expand and collapse; Disclosure is a single expandable section.

- Family: navigation
- Import: `import { Accordion, Disclosure } from "@senvenli/react/navigation";`
- Page: https://design.senvenli.com/docs/components/accordion
- JSON: https://design.senvenli.com/docs/components/accordion.json

## Example: Questions and answers

Opening one section closes the others.

```tsx
import { Accordion } from "@senvenli/react/navigation";

export default function Example() {
  return (
    <Accordion
      defaultExpandedKeys={["plans"]}
      items={[
        { id: "plans", title: "Can I change plans later?", content: "Yes. Upgrade or downgrade at any time; the price is adjusted on your next invoice." },
        { id: "trial", title: "Is there a free trial?", content: "Every plan starts with 14 days free. No card is needed until the trial ends." },
        { id: "invoices", title: "Where do I find my invoices?", content: "Under Settings, then Billing. Each invoice is also emailed to the billing contact." },
      ]}
    />
  );
}
```

## Examples

### Several open at once

For sections people compare; some start expanded.

```tsx
import { DescriptionList } from "@senvenli/react/display";
import { Accordion } from "@senvenli/react/navigation";

export default function Example() {
  return (
    <Accordion
      allowsMultipleExpanded
      headingLevel={4}
      defaultExpandedKeys={["customer", "payment"]}
      items={[
        {
          id: "customer",
          title: "Customer",
          content: <DescriptionList items={[{ label: "Name", value: "Ada Lovelace" }, { label: "Email", value: "ada@example.com" }]} />,
        },
        {
          id: "payment",
          title: "Payment",
          content: <DescriptionList items={[{ label: "Method", value: "Card ending 4242" }, { label: "Total", value: "$248.00" }]} />,
        },
        { id: "notes", title: "Notes", content: "Prefers delivery before noon." },
      ]}
    />
  );
}
```

### Composed from Disclosures

`Disclosure` children with an `id` each: a section can hold anything, here a list and a link.

```tsx
import { Link } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Accordion, Disclosure } from "@senvenli/react/navigation";

export default function Example() {
  return (
    <Accordion defaultExpandedKeys={["shipping"]}>
      <Disclosure id="shipping" title="How long does shipping take?">
        <ul className="m-0 flex list-disc flex-col gap-ds-050 ps-ds-300">
          <li>Standard: 3 to 5 working days</li>
          <li>Express: next working day, ordered before 2 pm</li>
        </ul>
      </Disclosure>
      <Disclosure id="returns" title="Can I return an order?">
        <Text>
          Within 30 days, unused and in its box. <Link href="#returns">Start a return</Link>
        </Text>
      </Disclosure>
      <Disclosure id="contact" title="How do I reach support?">
        <Text>Write to us from the Help page; we answer within one working day.</Text>
      </Disclosure>
    </Accordion>
  );
}
```

### A single Disclosure

One expandable section on its own, here controlled.

```tsx
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Disclosure } from "@senvenli/react/navigation";
import { useState } from "react";

export default function Example() {
  const [isExpanded, setIsExpanded] = useState(false);
  return (
    <Stack space="space-100">
      <Disclosure title="Advanced settings" isExpanded={isExpanded} onExpandedChange={setIsExpanded}>
        Requests time out after 30 seconds and are retried three times.
      </Disclosure>
      <Text size="body-small" tone="subtle">
        The section is {isExpanded ? "open" : "closed"}.
      </Text>
    </Stack>
  );
}
```

## Guidelines

### When to use it

- Long content people scan by heading, like an FAQ.

### Use something else when

- [tabs](https://design.senvenli.com/docs/components/tabs.md): Views are parallel and only one shows at a time.
- [tree](https://design.senvenli.com/docs/components/tree.md): The sections nest more than one level.

## Accessibility

Keyboard:

- Enter, Space: Expands or collapses a section.

Built in:

- Each header is a button with aria-expanded inside a heading.

You provide:

- A heading level that fits the page.
- With children: an id on every Disclosure inside an Accordion (expandedKeys uses it).

## API reference

### Accordion

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| items | `readonly AccordionItem[]` |  | no | FAQ entries, settings groups, long-form sections. Leave it out to compose `Disclosure`s as children instead. |
| children | `React.ReactNode` |  | no | With no `items`: `Disclosure`s, each with an `id` (the key `expandedKeys` uses). |
| expandedKeys | `Iterable<Key>` |  | no |  |
| defaultExpandedKeys | `Iterable<Key>` |  | no |  |
| onExpandedChange | `(keys: Set<Key>) => void` |  | no |  |
| allowsMultipleExpanded | `boolean` |  | no | Several open at once; by default opening one closes the others. |
| headingLevel | `4 \| 2 \| 3 \| 5 \| 6` |  | no |  |
| motion | `ComponentMotion` |  | no | `auto` (follow the device), `reduce` or `none`, for this component; the provider's setting otherwise. |

### Disclosure

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| title | `React.ReactNode` |  | yes | A full question or a clear section name ("When is my deposit refunded?"). |
| children | `React.ReactNode` |  | yes |  |
| isExpanded | `boolean` |  | no |  |
| defaultExpanded | `boolean` |  | no |  |
| onExpandedChange | `(isExpanded: boolean) => void` |  | no |  |
| headingLevel | `4 \| 2 \| 3 \| 5 \| 6` |  | no | The heading level of the title in the page outline; the Accordion's, or 3 by default. |
| id | `Key` |  | no | Inside an Accordion: its key. |
| motion | `ComponentMotion` |  | no | `auto` (follow the device), `reduce` or `none`, for this component; the provider's setting otherwise. |

### Tokens it reads

`--ds-border`, `--ds-border-focused`, `--ds-easing-standard`, `--ds-icon-subtle`, `--ds-radius-small`, `--ds-space-150`, `--ds-space-200`, `--ds-text`, `--ds-text-subtle`
