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
Right to left
Fits
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
- Its items stay in one row. When they do not fit, the row scrolls sideways; it never widens its parent or the page, and scrolling it to an end does not move the page. Focus rings around the items are not cut off.
- A side that has more fades out, by CSS alone; there is no fade where the browser lacks scroll-driven animations, or in forced colours.
- The current item is the first that has, or whose direct child has (a list's link, a label's input), one of
aria-current,aria-pressed="true",aria-selected="true"or:checked. A pressed toggle deeper inside an item, such as a card's "favourite" button, does not count. The row starts with it in view, and follows when another item becomes current, however that happens: React state, a router or a script. It never scrolls the page, and a row the user scrolled stays. - With
labelthe row is aregionof that name, or theroleyou give, such asgroupfor chips orlist. A labelled row that scrolls with nothing focusable in it becomes a Tab stop, so the arrow keys scroll it; a row with buttons or links never is one itself. - Not
scrollIntoView: it can scroll the page as well as the row.
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).
| Token | Default |
|---|---|
--sf-scroll-row-gap | var(--sf-space-2) |
--sf-scroll-row-fade | 2rem |
--sf-scroll-row-ring | 4px |
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.