# Accordion

Sections stacked under each other, with one or several open at a time.

```vue
<template>
  <NuiAccordion v-model="question" :heading-level="3" class="w-full max-w-md">
    <NuiAccordionItem value="delivery" label="How much is delivery?">
      A courier in the city costs $15, and orders over $500 ship free. Pickup is always free.
    </NuiAccordionItem>
    <NuiAccordionItem value="return" label="How do I return an item?">
      Request a return within 14 days of delivery, and a courier picks the item up.
    </NuiAccordionItem>
    <NuiAccordionItem value="installments" label="Can I pay in installments?">
      Yes, orders over $150 split into four payments with no extra fees.
    </NuiAccordionItem>
  </NuiAccordion>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { NuiAccordion, NuiAccordionItem } from '@numior/kit';

const question = ref<string | null>('delivery');
</script>
```

## Installation

```ts
import { NuiAccordion, NuiAccordionItem } from '@numior/kit';
```

## Usage

Change the look and open one section at a time or several at once.

```vue
<template>
  <NuiAccordion class="w-full max-w-md">
    <NuiAccordionItem value="delivery" label="Delivery">
      A courier brings the order on September 18, between 10 a.m. and 2 p.m.
    </NuiAccordionItem>
    <NuiAccordionItem value="payment" label="Payment">
      Paid by bank transfer. The receipt went to the customer by email.
    </NuiAccordionItem>
    <NuiAccordionItem value="refund" label="Returns">
      We take the item back within 14 days of delivery.
    </NuiAccordionItem>
  </NuiAccordion>
</template>

<script setup lang="ts">
import { NuiAccordion, NuiAccordionItem } from '@numior/kit';
</script>
```

## Examples

### Open several sections

Add `multiple` and keep the open sections in `v-model:values`.

```vue
<template>
  <NuiAccordion v-model:values="sections" multiple variant="card" class="w-full max-w-md">
    <NuiAccordionItem value="delivery" label="Delivery">
      A courier brings order 20411 to Austin on September 28, between 10 am and 6 pm.
    </NuiAccordionItem>
    <NuiAccordionItem value="payment" label="Payment">
      Bank transfer, the invoice went to nina.hart@example.com.
    </NuiAccordionItem>
    <NuiAccordionItem value="promo" label="Promo codes do not apply to discounted items" disabled />
  </NuiAccordion>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { NuiAccordion, NuiAccordionItem } from '@numior/kit';

const sections = ref(['delivery', 'payment']);
</script>
```

## Behavior

Without `multiple`, `v-model` holds the `value` of the open section, or `null` when all are
closed. With `:collapsible="false"`, a second click leaves the open section open: it closes only
when another one opens.

## Accessibility

Section headings are buttons, and a screen reader says whether a section is open. The up and
down arrows move between headings and wrap around; Home and End jump to the first and the last.
The keys work only on a heading: in a field inside a section they move the caret as usual.

| Keys | Action |
| --- | --- |
| `ArrowDown` | Moves the focus to the next heading, from the last one to the first. |
| `ArrowUp` | Moves the focus to the previous heading, from the first one to the last. |
| `Home` | Moves the focus to the first heading. |
| `End` | Moves the focus to the last heading. |
| `Enter` | Opens or closes the section. |
| `Space` | Opens or closes the section. |

## API

### NuiAccordion

```ts
import { NuiAccordion } from '@numior/kit';
```

#### Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `id` | `string` |  | Id attribute of the root element. |
| `multiple` | `boolean` | `false` | Lets several sections stay open at once. The `values` model holds them. |
| `collapsible` | `boolean` | `true` | Closes the open section on a second click on its heading. |
| `variant` | `NuiCollapsibleVariant` | `"plain"` | Style: `plain` without a frame, `card` puts each section in a card. |
| `headingLevel` | `NuiHeadingLevel` |  | Wraps the section headings in `h2`–`h6`, so the sections appear in the page outline. Without it the heading is a `div`. |
| `disabled` | `boolean` | `false` | Turns off every section heading: no section opens or closes. |

#### Models

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `string \| null` | `null` | Value of the open section, or `null` when every section is closed. |
| `v-model:values` | `string[]` | `[]` | Values of the open sections when `multiple` is on. |

#### Slots

| Name | Slot props | Description |
| --- | --- | --- |
| `default` | `any` | `NuiAccordionItem` sections. |

### NuiAccordionItem

```ts
import { NuiAccordionItem } from '@numior/kit';
```

#### Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` (required) | `string` |  | Value that goes into the accordion model while the section is open. |
| `label` | `string` |  | Heading text. |
| `disabled` | `boolean` | `false` | Turns off the section heading: the section does not open or close, and an open one stays open. |

#### Slots

| Name | Slot props | Description |
| --- | --- | --- |
| `trigger` | `NuiCollapsibleTriggerSlot` | Custom section heading. Receives `open`, whether the section is open. |
| `default` | `any` | Section content. |
