# Accordion (`<z-accordion>`)

> Collapsible content panels with single or multiple open items, animated height transitions, and keyboard navigation.

- **Kind:** controller
- **Category:** layout
- **Inherits:** `Controller`, `Base`

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `multiple` | `boolean` | `false` | — | Allows several panels to stay open at once; otherwise opening one closes the others. |
| `no-collapsible` | `boolean` | `false` | — | Keeps at least one panel open: the last open panel cannot be closed, and the first enabled panel opens automatically. |
| `active` | `string` | — | — | Open panels as a comma- or space-separated list of indices, values, or ids; `-1` closes all. Kept in sync with the open state. |
| `duration` | `number` | `150` | — | Panel transition duration in milliseconds; `0` disables animation. |
| `no-animation` | `boolean` | `false` | — | Skips panel transitions entirely, showing and hiding content instantly. |
| `targets` | `string` | `''` | — | CSS selector for item elements within the container, replacing the default item detection. |
| `trigger` | `string` | `''` | — | CSS selector for the clickable trigger within each item, replacing `.z-accordion-title` detection. |
| `content` | `string` | `''` | — | CSS selector for the collapsible panel within each item, replacing `.z-accordion-content` detection. |

### Inherited from `Base`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `cls` | `string` | `''` | `Base` | Adds classes to named parts as `key: classes` pairs; a plain string targets the default part. |
| `stl` | `string` | `''` | `Base` | Adds inline styles to named parts as `key: styles` pairs; a plain string targets the default part. |

## Styling Parts (`cls` / `stl`)

Default `cls` target: `open`. Default `stl` target: `host-inner`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `open` | `z-open` | ✓ | — | Class applied to open items; the default `cls` target for this component. |

## Reference inventories

- [CSS Variables (6)](https://next.0build.dev/docs/components/accordion/css-vars.md)
- [CSS Classes (5)](https://next.0build.dev/docs/components/accordion/css-classes.md)

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-accordion:before-hide` | ✓ | `{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }` | Fires before a panel closes; `preventDefault()` cancels the change. |
| `z-accordion:before-show` | ✓ | `{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }` | Fires before a panel opens; `preventDefault()` cancels the change. |
| `z-accordion:change` | — | `{ activeIndices: number[]; index: number; open: boolean; item: HTMLElement \| null; trigger: HTMLElement \| null; content: HTMLElement \| null; value: string \| null }` | Fires after any open-state change; detail carries the active indices and the primarily affected item. |
| `z-accordion:hidden` | — | `{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }` | Fires after a panel's close transition completes. |
| `z-accordion:hide` | — | `{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }` | Fires when a panel starts closing. |
| `z-accordion:mount` | — | `Record<string, unknown>` | Fires when deferred template content is mounted into the container. |
| `z-accordion:show` | — | `{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }` | Fires when a panel starts opening. |
| `z-accordion:shown` | — | `{ index: number; item: HTMLElement; trigger: HTMLElement; content: HTMLElement; value: string }` | Fires after a panel's open transition completes. |

## Methods

| Method | Params | Returns | Description |
| --- | --- | --- | --- |
| `activeIndices()` | — | `number[]` | Returns the indices of open panels, sorted ascending. |
| `close()` | `target: number \| string`, `animate?: boolean = true` | `Promise<boolean>` | Closes the given panel; refuses to close the last one when `no-collapsible` is set. |
| `closeAll()` | `animate?: boolean = true` | `Promise<boolean>` | Closes all panels, keeping one open when `no-collapsible` is set. |
| `open()` | `target: number \| string`, `animate?: boolean = true` | `Promise<boolean>` | Opens the panel at the given index, value, or id; resolves `true` when open. |
| `openAll()` | `animate?: boolean = true` | `Promise<boolean>` | Opens every enabled panel; with `multiple` off, opens only the first enabled one. |
| `refresh()` | — | `void` | Re-scans the DOM and rebinds listeners after items change. |
| `toggle()` | `target: number \| string`, `animate?: boolean = true` | `Promise<boolean>` | Opens the given panel if closed, otherwise closes it. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-accordion-ignore` | — | `descendant` | `config` | Excludes the element from item detection. |
| `data-accordion-item` | `close-all`, `next`, `open-all`, `previous` | `descendant` | `trigger` | Turns the element into an accordion control: `open-all`, `close-all`, `next`, `previous`, or a target index, value, or id to toggle. |
| `data-fn` | `template` | `descendant` | `config` | Marks a deferred `<template>` child whose content is mounted into the container on demand. |
| `data-part` | `list` | `descendant` | `marker` | Marks the list container (`list`) when the host itself is not the accordion list. |
| `data-value` | — | `descendant` | `read-only` | Identifies the item for `active` and toggle targets; falls back to the item id or index. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `ArrowDown` / `ArrowUp` | Move focus to the next / previous enabled trigger, wrapping at the ends. | Focus is on a trigger |
| `Home` / `End` | Move focus to the first / last enabled trigger. | Focus is on a trigger |
| ` ` | Toggle the focused panel when the trigger is not a native button. | Focus is on a non-button trigger |
| `Enter` | Toggle the focused panel when the trigger is neither a button nor a link. | Focus is on a non-button, non-link trigger |

## Notes

- Items are detected from direct children with a `.z-accordion-title` trigger and a `.z-accordion-content` panel; nav lists (`.z-nav`) use links and sublists instead.
- Panel animation is skipped when the user prefers reduced motion.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)
