# Disclosure

A summary that shows or hides more content, built on `<details>` and `<summary>`.

_Diagram: Disclosures are summary rows in the content area, such as an accordion of questions, that each open to show their content below._

## Live example

### Disclosure

```html
<details>
  <summary>What is included in the plan?</summary>
  <p>Unlimited projects, five collaborators and email support.</p>
</details>
```

### Exclusive accordion

```html
<div data-disclosure="accordion">
  <details name="faq" open>
    <summary>Shipping</summary>
    <p>Orders ship within two working days.</p>
  </details>
  <details name="faq">
    <summary>Returns</summary>
    <p>Return unused items within 30 days for a full refund.</p>
  </details>
  <details name="faq">
    <summary>Warranty</summary>
    <p>Every product has a two-year warranty.</p>
  </details>
</div>
```

### Accordion with several open

```html
<div data-disclosure="accordion">
  <details>
    <summary>Monthly plan</summary>
    <p>Pay each month and cancel any time.</p>
  </details>
  <details>
    <summary>Yearly plan</summary>
    <p>Pay once a year and get two months free.</p>
  </details>
</div>
```

### Inline show more

```html
<p>The release adds pagination, tabs and toasts.</p>
<details data-disclosure="plain">
  <summary>Show the full list of changes</summary>
  <ul>
    <li>Twelve molecules with example pages.</li>
    <li>Five small web components.</li>
    <li>Four explainers for custom patterns.</li>
  </ul>
</details>
```

## Attributes

| Attribute or value | Where | Effect |
| --- | --- | --- |
| `data-disclosure="accordion"` | a wrapper around several `<details>` | joins them into one bordered block |
| `data-disclosure="plain"` | a `<details>` | no box, for "Show more" text inside prose |
| `name="group"` | each `<details>` (native) | only one open |
| `open` | a `<details>` (native) | open on load |

### Keyboard

| Key | Action |
| --- | --- |
| <kbd>Tab</kbd> | moves to the next summary / Shift+Tab: previous |
| <kbd>Enter</kbd> / <kbd>Space</kbd> | opens or closes the focused section |

## Accessibility

- `<summary>` is a button with `aria-expanded` ([HTML-AAM](https://www.w3.org/TR/html-aam-1.0/#el-summary)), so there is no ARIA to write.
- Unlike the [APG Accordion](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/), headers are not headings and have no arrow keys. Both are optional there.
- Avoid exclusive groups ([`name`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details#name)) when people compare sections.

## Specifications

- [HTML `<details>` element](https://html.spec.whatwg.org/multipage/interactive-elements.html#the-details-element)
- [APG Disclosure pattern](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/)
- [MDN `details`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details)

## See also

- [Molecules](https://domestic-ui.odonckers.dev/molecules/index.md)
- Source: [`css/components/molecules/disclosure.css`](https://github.com/odonckers/domestic-ui/blob/main/css/components/molecules/disclosure.css), [`examples/molecules/disclosure.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/molecules/disclosure.html)
- Demos: Dashboard view ([Plain HTML](https://github.com/odonckers/domestic-ui/blob/main/demos/vanilla/index.html), [React](https://github.com/odonckers/domestic-ui/blob/main/demos/react/src/DashboardPage.tsx), [Angular](https://github.com/odonckers/domestic-ui/tree/main/demos/angular/src/app/dashboard), [Astro](https://github.com/odonckers/domestic-ui/blob/main/demos/astro/src/pages/index.astro), [Vue](https://github.com/odonckers/domestic-ui/blob/main/demos/vue/src/DashboardPage.vue), [Svelte](https://github.com/odonckers/domestic-ui/blob/main/demos/svelte/src/DashboardPage.svelte))

## How other systems do it

For comparison only; these are not the standard this system follows.

- [Apple Human Interface Guidelines: Disclosure controls](https://developer.apple.com/design/human-interface-guidelines/disclosure-controls)
- Material Design 3: No equivalent
- [Vercel Geist: Collapse](https://vercel.com/geist/collapse)
