Component · in flow

Scroll row

Items in one row that scrolls sideways when it does not fit, with a fade on the side that has more. It starts at its current item and follows it, without moving the page.

Chips, the last one pressed

Days as links

Nothing to focus: a Tab stop

1
2
3
4
5
6
7
8
9
10

Right to left

Fits

S
M
L

React

Usage

Astro:

---
import ScrollRow from '@subfloor/astro/ScrollRow.astro'
---
<!-- Chips: the pressed one is the current item. -->
<ScrollRow role="group" label="Category">
  {chips.map((chip) => (
    <button type="button" class="chip" aria-pressed={chip === picked}>{chip}</button>
  ))}
</ScrollRow>

<!-- A list of links: the one with aria-current. -->
<ScrollRow as="ul" label="Days">
  {days.map((day) => (
    <li><a href={day.href} aria-current={day.picked ? 'date' : undefined}>{day.label}</a></li>
  ))}
</ScrollRow>

React:

import { ScrollRow } from '@subfloor/react'

<ScrollRow role="group" label="Category">
  {chips.map((chip) => (
    <button key={chip} type="button" className="chip"
      aria-pressed={chip === picked} onClick={() => setPicked(chip)}>
      {chip}
    </button>
  ))}
</ScrollRow>

Markup

<div class="sf-scroll-row" data-sf-scroll-row role="group" aria-label="Category">
  <button type="button" class="chip" aria-pressed="false">All</button>
  …
  <button type="button" class="chip" aria-pressed="true">Desserts</button>
</div>

<script type="module">
  import { initScrollRows } from '@subfloor/core'
  initScrollRows()
</script>

Behaviour

Without JavaScript

The row scrolls and fades. It starts at its beginning, except where the browser supports scroll-initial-target, and only some browsers make a row with nothing focusable a Tab stop.

Customisation

The gap, the length of the fade and the room for focus rings are tokens. A row that bleeds to the screen's edge on phones is your CSS, a negative margin with the same padding; so is a row that wraps from some width (flex-wrap: wrap; overflow: visible).

TokenDefault
--sf-scroll-row-gapvar(--sf-space-2)
--sf-scroll-row-fade2rem
--sf-scroll-row-ring4px

Background

Content 1. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 2. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 3. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 4. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 5. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 6. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 7. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 8. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 9. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 10. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 11. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.

Content 12. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.