# Scroll

A scroll container for content wider than the screen, such as a data table, so it scrolls on its own instead of widening the page.

_Diagram: A scroll region holds a data table wider than the content area, so the table scrolls sideways on its own and the page does not._

## Live example

### Scroll region

```html
<section data-scroll="inline" aria-labelledby="viewports-caption" tabindex="0">
  <table>
    <caption id="viewports-caption">Viewports every page is checked at</caption>
    <thead>
      <tr>
        <th scope="col">Width</th>
        <th scope="col">Height</th>
        <th scope="col">Engines</th>
        <th scope="col">Checks</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>320px</td>
        <td>640px</td>
        <td>Chromium, Firefox, WebKit</td>
        <td>No sideways page scroll, no axe violations</td>
      </tr>
      <tr>
        <td>375px</td>
        <td>812px</td>
        <td>Chromium, Firefox, WebKit</td>
        <td>No sideways page scroll, no axe violations</td>
      </tr>
    </tbody>
  </table>
</section>
```

## API

| Attribute or value | Effect |
| --- | --- |
| `data-scroll="inline"` | scroll along the inline axis (left/right in English) |
| `data-scroll="block inline"` | also scroll along the block axis, at most `--dui-size-pane` (the viewport) tall, so a sticky table header stays in view (`css/components/organisms/data-table.css`) |

- Add `tabindex="0"` so keyboard users can scroll it ([WCAG 2.1.1](https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html), [axe rule](https://dequeuniversity.com/rules/axe/4.10/scrollable-region-focusable)).
- **Our choice:** a `<section>` with `aria-labelledby`, not `<div role="region">`, because the native element already has the role.
- A table inside keeps `display: table`, or it can lose its semantics ([Adrian Roselli](https://adrianroselli.com/2018/02/tables-css-display-properties-and-aria.html)).

## Accessibility

- [WCAG 1.4.10](https://www.w3.org/WAI/WCAG22/Understanding/reflow.html) allows two-dimensional scrolling for data tables.
- A named `<section>` is a region landmark ([HTML-AAM](https://www.w3.org/TR/html-aam-1.0/#el-section)), so the focus stop is announced.

## Specifications

- [Deque University scrollable region focusable](https://dequeuniversity.com/rules/axe/4.10/scrollable-region-focusable)
- [W3C el section](https://www.w3.org/TR/html-aam-1.0/#el-section)
- [Adrian Roselli tables css display properties and aria](https://adrianroselli.com/2018/02/tables-css-display-properties-and-aria.html)
- [MDN `scroll`](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timeline/scroll)
- [MDN `mask-image`](https://developer.mozilla.org/en-US/docs/Web/CSS/mask-image)
- [WCAG Reflow](https://www.w3.org/WAI/WCAG22/Understanding/reflow.html)
- [MDN `overflow-x`](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-x)

## See also

- [Layouts](https://domestic-ui.odonckers.dev/layouts/index.md)
- [Component API convention](https://domestic-ui.odonckers.dev/index.md#component-api)
- [Accessibility baseline](https://domestic-ui.odonckers.dev/principles/accessibility-baseline-wcag-22-aa.md)
- Source: [`css/layout/scroll.css`](https://github.com/odonckers/domestic-ui/blob/main/css/layout/scroll.css), [`examples/base.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/base.html)

## How other systems do it

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

- Apple Human Interface Guidelines: No equivalent
- Material Design 3: No equivalent
- [Vercel Geist: Scroller](https://vercel.com/geist/scroller)
