Fair Case

ScrollArea

A native vertical scroller with an eased fade at each edge, shown only while more content lies beyond that edge. The fades sit inside the scroller, so its scrollbar draws above them: with a mouse or trackpad it is thin, and on touch it is the platform's.

The fades

A 288 by 256px box of 30 rows, drawn scrolled to the top, the middle and the bottom. Each fade shows only while more lies beyond its edge.

  • Row 1
  • Row 2
  • Row 3
  • Row 4
  • Row 5
  • Row 6
  • Row 7
At the top: the end fade only
  • Row 12
  • Row 13
  • Row 14
  • Row 15
  • Row 16
  • Row 17
  • Row 18
In the middle: both fades
  • Row 24
  • Row 25
  • Row 26
  • Row 27
  • Row 28
  • Row 29
  • Row 30
At the bottom: the start fade only

TSX

<ScrollArea
  className="h-64 w-72 rounded-12 ring-1 ring-rule"
  viewportClassName="h-full"
  viewportProps={{ tabIndex: 0, role: "region", "aria-label": "Rows" }}
>
  <ul className="px-3">
    {rows.map((row) => (
      <li key={row} className="flex min-h-11 items-center text-base">{row}</li>
    ))}
  </ul>
</ScrollArea>

Scroll it

The same box with all 30 rows. Hover it or put focus in it and the thin scrollbar appears, above the fades.

  • Row 1
  • Row 2
  • Row 3
  • Row 4
  • Row 5
  • Row 6
  • Row 7
  • Row 8
  • Row 9
  • Row 10
  • Row 11
  • Row 12
  • Row 13
  • Row 14
  • Row 15
  • Row 16
  • Row 17
  • Row 18
  • Row 19
  • Row 20
  • Row 21
  • Row 22
  • Row 23
  • Row 24
  • Row 25
  • Row 26
  • Row 27
  • Row 28
  • Row 29
  • Row 30
The fades follow your scroll in CSS where the browser supports it. Elsewhere an observer draws them on the site, and this page runs no script, so it shows none.

TSX

<ScrollArea
  className="h-64 w-72 rounded-12 ring-1 ring-rule"
  viewportClassName="h-full"
  viewportProps={{ tabIndex: 0, role: "region", "aria-label": "Rows" }}
>
  <ul className="px-3">
    {rows.map((row) => (
      <li key={row} className="flex min-h-11 items-center text-base">{row}</li>
    ))}
  </ul>
</ScrollArea>

Code

TSX

<ScrollArea
  className="flex min-h-0 flex-col"
  viewportClassName="relative min-h-0 outline-none"
  viewportProps={{ tabIndex: -1 }}
>
  <Combobox.List aria-label={text.label} className="outline-none">
    {rowsReady ? renderRow : null}
  </Combobox.List>
</ScrollArea>

From the language menu's list (language-menu.tsx). The story gives it a fixed box: className "h-64 w-72 rounded-12 ring-1 ring-rule", viewportClassName "h-full" and viewportProps { tabIndex: 0, role: "region", "aria-label": "Rows" }.

Variants

Variants
PropValueHow it looks
edge fadedefaultTwo 32px bands, the first and last children of the scroller, each sticky to its edge and taking no room, in the page colour (#FAFDFF light, #00172E dark) under an ease-in-out mask sampled at 12 stops, so the edge dissolves instead of cutting in a line. Set --scroll-area-surface to fade into another surface.
scrollbarmouse or trackpad6px wide with a 3px radius, the text colour at 35%, shown only while the pointer is over the area or focus is inside. The track is transparent, and the thumb runs the full height, above the fades.
scrollbartouchThe platform's overlay bar.

States

States
StateHow it looks
at the topOnly the end (bottom) fade shows.
in the middleBoth fades show. The start fade rises over the first fade-length of scrolling, and the end fade falls over the last.
at the bottomOnly the start (top) fade shows.
no overflowContent that does not overflow leaves the timeline inactive: both fades at opacity 0.
hover or focus insideThe scrollbar thumb appears.
focusA focus ring inside draws above the fades. Keyboard focus and a highlighted option scroll clear of them.
no scroll-driven animationAn observer on a marker at each end sets data-more-start and data-more-end on the root, and the fades ease in over 150ms. This part runs in script.

Props

Import from @repo/ui/scroll-area.

Props
PropTypeDefaultWhat it does
childrenReactNodedefault requiredThe scrolling content.
fadenumberdefault 32The fade's length at each edge, in px. Also the scroll padding.
classNamestring | undefinedClasses for the root element.
viewportClassNamestring | undefinedClasses for the scrolling element.
contentClassNamestring | undefinedClasses for a wrapper around the children, where padding belongs. Padding on the scrolling element would narrow the fades and hold the end fade off the edge. Without it, the children sit directly in the scrolling element.
viewportPropsOmit<ComponentProps<"div">, "children" | "className">Props for the scrolling element, such as tabIndex or a label.
...restOmit<ComponentProps<"div">, "children">Passed to the root. style is merged after the --scroll-area-fade property.

Use it well

  • A scroller with nothing focusable inside is focusable itself, so the keyboard can scroll it. Give it tabIndex 0 and a name, as the story does.

  • Where a field keeps focus and moves a highlight (the language list), the scroller is not a Tab stop: use tabIndex -1.

  • Nothing re-renders on scroll. The fades follow the scroll position in CSS.

  • It scrolls vertically only. The fades run top to bottom, so right to left changes nothing but the side of the scrollbar.