# Collapsible

One section that opens in place. A square key sits at the start of its head with a printed chevron; opening latches the key below the plate and turns the chevron down, and the text slides out under the head on a grid row that grows from nothing, so it is never given a height of its own. It is a native details element, so it works with no script.

Kit part · Free · https://tactileui.dev/parts/collapsible

- Element: `<details class="tui-collapsible">`
- Needs: `kit.css` and `kit.mjs` ([how to install the kit](https://tactileui.dev/docs/installation#the-kit))
- Categories: Accordions
- Finishes: Aluminium, Graphite, Oak, Walnut, Porcelain, Black, Daylight, Night, Paper, Phosphor, E-paper, AMOLED
- Volumes: Tactile, Quiet

## Variants

### Closed

```html
<div style="width:min(100%,360px)"><details class="tui-collapsible"><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">Advanced options</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><p>Exports run in the background now, and the settings page loads in half the time.</p></div></div></details></div>
```

### Open

```html
<div style="width:min(100%,360px)"><details class="tui-collapsible" open><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">Advanced options</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><p>Exports run in the background now, and the settings page loads in half the time.</p></div></div></details></div>
```

### With a count at the end

```html
<div style="width:min(100%,360px)"><details class="tui-collapsible"><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">Attachments</span> <span class="tui-collapsible__meta">4 files</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><p>Quarterly letter.pdf, Map.png, Notes.txt and Sketch.png.</p></div></div></details></div>
```

### On a plate · .tui-collapsible--plate

```html
<div style="width:min(100%,360px)"><details class="tui-collapsible tui-collapsible--plate" open><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">Delivery notes</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><p>Leave with the neighbour at number 14 if nobody answers.</p></div></div></details></div>
```

### Long head wraps

```html
<div style="width:min(100%,280px)"><details class="tui-collapsible"><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">A head that is a good deal longer than the row it sits in, so it wraps under its key</span> <span class="tui-collapsible__meta">2</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><p>Exports run in the background now, and the settings page loads in half the time.</p></div></div></details></div>
```

## Every state

- Closed
- Hover
- Pressing
- Open
- Focus

Hover, pressed and focus are forced with `.is-hover`, `.is-down` and `.is-focus`; checked and disabled are real.

## API

| Name | Kind | Values | What it does |
| - | - | - | - |
| details.tui-collapsible | element | open attribute | One section. Add open to start it open. A plain details with no name, so opening it never closes another one. |
| summary > .tui-collapsible__key + __title (+ __meta) | element | in this order | The head. The key is aria-hidden; the title is the section’s name; the meta is a count or a small fact at the end. |
| .tui-collapsible__body > .tui-collapsible__inner | element | two boxes | The text, in its own grid row so it can grow from 0fr to 1fr. Put the content in the inner box and give neither of them a height. |
| --plate | modifier | tui-collapsible--plate | The section on a plate of its own, for one that stands apart on a page. |
| toggleCollapsible(details, open?) | function | needs kit.mjs | Opens, closes or flips one from code, easing the close like a press does. |
| toggle | event | native | Fires from the details element after it has opened or, for a close, after the text has slid away. |
| Enter · Space | key | on the head | The browser’s own: flips the section. |

## Markup

```html
<!-- One section. The key is drawn, so it is hidden from a screen reader; the head says the state. -->
<details class="tui-collapsible">
  <summary>
    <span class="tui-collapsible__key" aria-hidden="true"></span>
    <span class="tui-collapsible__title">What changed in 4.2</span>
    <span class="tui-collapsible__meta">3 changes</span>
  </summary>
  <div class="tui-collapsible__body">
    <div class="tui-collapsible__inner">
      <p>Exports run in the background now.</p>
    </div>
  </div>
</details>
```

```js
import { toggleCollapsible } from '/kit/kit.mjs';

// Opens or closes one from code, easing the close as a press does.
toggleCollapsible(document.querySelector('.tui-collapsible'));      // flip it
toggleCollapsible(details, true);                                   // open it

details.addEventListener('toggle', () => save(details.open));       // native, fires after the close is done
```

The demo on the page:

```html
<div class="tui-panel" style="width:min(100%,460px);display:grid;gap:16px;text-align:left"><div class="tui-panel__head" style="margin-bottom:0"><span class="tui-label">Release 4.2 · Lode</span><span class="tui-status"><span class="tui-lamp" data-on></span>Current</span></div><div>
  <details class="tui-collapsible" open><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">What changed</span> <span class="tui-collapsible__meta">3 changes</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><ul style="margin:0;padding-left:18px"><li>Exports run in the background.</li><li>The settings page loads in half the time.</li><li>Keyboard shortcuts are listed under Help.</li></ul></div></div></details>
  <details class="tui-collapsible"><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">Known issues</span> <span class="tui-collapsible__meta">1 open</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><p>Very long project names are cut short in the sidebar. A fix is planned for 4.3.</p></div></div></details>
  <details class="tui-collapsible"><summary><span class="tui-collapsible__key" aria-hidden="true"></span> <span class="tui-collapsible__title">Upgrading from 4.1</span></summary><div class="tui-collapsible__body"><div class="tui-collapsible__inner"><p>Nothing to do: your settings move across the first time you sign in.</p></div></div></details>
</div></div>
```

## Usage notes

Press the head, or Tab to it and press Space: the key sinks, the chevron turns and the text slides out, and pressing again slides it away. Each section is on its own, so opening one never closes another. The one on a plate stands apart on a page.

## Accessibility

- It is a `<details>` with a `<summary>`, so a screen reader says “Release notes, collapsed” or “expanded” and the keyboard works with no script and no ARIA.
- The chevron and the key are drawn and hidden from a screen reader, since the head already says the state; the state is also told by the key sitting lower with its chevron turned, so it is not colour.
- Closed text is not in the page for a screen reader or the Tab key, because the browser takes it out, and while it slides away it cannot be pressed.
- Focus is a 2px ring round the whole head. On a phone the head is at least 48px tall and the key grows to 28px, and the whole row is the press.
- Under reduced motion the key and the chevron do not move between states, the text arrives and leaves at once, and nothing is left out.

## How it’s built

The head is the accordion’s: a summary that is a row, with the same cap on a skirt that latches below the plate. The key is a separate little box so the chevron on it can turn on its own as the key sinks. The text is a grid whose one row grows from 0fr to 1fr when the section opens; closing runs the same row back with a transition, held by the script for the 200ms it takes before the details element is allowed to hide it.

## Rules

Fold away one section of a page behind a square key: release notes, advanced options, a long note. The accordion’s single-row cousin.

The full rules are in `collapsible.rules.md` in the brain, which ships with the Kit.

## Related parts

- [Accordion](https://tactileui.dev/parts/accordion): Printed sections that open in place. Each head ends in a small square key printed +; open, the key latches below the plate and reads −.
- [Panel](https://tactileui.dev/parts/panel): A face plate that groups what belongs together: a head, a rule, then the parts. Screws only on device-like panels.
- [Key](https://tactileui.dev/parts/key): Every button, and every link that acts like one: a cap on a skirt that drops below the plate when pressed.
