Skip to the content
human-kit design
47 — Layout

Scroll Area

A region that scrolls on its own, with a thin bar and edges that fade where there is more.

  • Note 1: follow-up after the transfer.
  • Note 2: follow-up after the transfer.
  • Note 3: follow-up after the transfer.
  • Note 4: follow-up after the transfer.
  • Note 5: follow-up after the transfer.
  • Note 6: follow-up after the transfer.
  • Note 7: follow-up after the transfer.
  • Note 8: follow-up after the transfer.
  • Note 9: follow-up after the transfer.
  • Note 10: follow-up after the transfer.
  • Note 11: follow-up after the transfer.
  • Note 12: follow-up after the transfer.
  • Note 13: follow-up after the transfer.
  • Note 14: follow-up after the transfer.
  • Note 15: follow-up after the transfer.
  • Note 16: follow-up after the transfer.
  • Note 17: follow-up after the transfer.
  • Note 18: follow-up after the transfer.
  • Note 19: follow-up after the transfer.
  • Note 20: follow-up after the transfer.
  • Note 21: follow-up after the transfer.
  • Note 22: follow-up after the transfer.
  • Note 23: follow-up after the transfer.
  • Note 24: follow-up after the transfer.

Installation

pnpm dlx @human-kit/design add scroll-area
npx @human-kit/design add scroll-area
yarn dlx @human-kit/design add scroll-area
bunx @human-kit/design add scroll-area

The command copies the files to src/lib/components/ui/scroll-area. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as ScrollArea from '$lib/components/ui/scroll-area';
</script>

<ScrollArea.Root label="Visit notes" class="h-48">
	<VisitNotes />
</ScrollArea.Root>

Guidelines

  • Use it for a part of the screen that holds more than its box: a list in a panel, a sidebar, the body of a dialog. Let the page itself scroll as the browser does.
  • Give it a height, or put it in a flex box that sets one: it scrolls only when something holds it smaller than its content.
  • Turn fade on where the cut would read as the end of the list, as a list with no edge of its own. It fades only an edge that the content goes on past.
  • Use horizontal for a row of items, as chips or days, and both for a wide table. fade does nothing with both.
  • Keep one scrolling region per direction in a view. A region inside a region traps the wheel.

Accessibility

  • It keeps the browser's own scrolling: the wheel, touch, the scrollbar and the keyboard work as they do on the page.
  • While its content overflows it takes the focus, so the arrow keys and Page Up and Page Down scroll it. With nothing to scroll it is no stop for Tab.
  • Give label and it becomes a role="region" with that name, so a screen reader can find it and say what the focus landed on.
  • The focus ring is drawn inside its edge, where an outer ring would be cut by its own box.

API reference

PropTypeDefault
orientation'vertical' | 'horizontal' | 'both'

The direction it scrolls in. The other one is clipped.

'vertical'
fadeboolean

Thins the content out at an edge it goes on past. Not for both.

false
labelstring

The name of the region, read when the keyboard reaches it.

—
elementHTMLDivElement | null

The scrolling element, to scroll it from code. Bindable.

—
classstring

Classes for the scrolling element: its height and its padding.

—

Plus every attribute of a <div>.