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.
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.
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
| Prop | Value | How it looks |
|---|---|---|
| edge fade | default | Two 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. |
| scrollbar | mouse or trackpad | 6px 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. |
| scrollbar | touch | The platform's overlay bar. |
States
| State | How it looks |
|---|---|
| at the top | Only the end (bottom) fade shows. |
| in the middle | Both fades show. The start fade rises over the first fade-length of scrolling, and the end fade falls over the last. |
| at the bottom | Only the start (top) fade shows. |
| no overflow | Content that does not overflow leaves the timeline inactive: both fades at opacity 0. |
| hover or focus inside | The scrollbar thumb appears. |
| focus | A focus ring inside draws above the fades. Keyboard focus and a highlighted option scroll clear of them. |
| no scroll-driven animation | An 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.
| Prop | Type | Default | What it does |
|---|---|---|---|
| children | ReactNode | default required | The scrolling content. |
| fade | number | default 32 | The fade's length at each edge, in px. Also the scroll padding. |
| className | string | undefined | Classes for the root element. | |
| viewportClassName | string | undefined | Classes for the scrolling element. | |
| contentClassName | string | undefined | Classes 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. | |
| viewportProps | Omit<ComponentProps<"div">, "children" | "className"> | Props for the scrolling element, such as tabIndex or a label. | |
| ...rest | Omit<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.