Scroll Area
A native scroll container with a thin scrollbar that fades in while you hover or scroll, and fades away after. Built on ui-sdk’s Scroll Area.
Usage
import {
ScrollArea,
ScrollAreaContent,
ScrollAreaScrollbar,
ScrollAreaViewport,
} from 'nyctoui/scroll-area'
<ScrollArea sx={styles.frame}>
<ScrollAreaViewport>
<ScrollAreaContent>…</ScrollAreaContent>
</ScrollAreaViewport>
<ScrollAreaScrollbar />
</ScrollArea>The area takes its size from outside: give the root a height with sx, or let a flex or grid parent size it. Padding belongs on ScrollAreaContent, so the scrollbar overlays it instead of eating into it.
The thumb darkens a step on hover and again while dragged. The bar stays while the thumb is held, even if the pointer leaves the area, and fades out a moment after both hovering and scrolling stop.
Good for
- A long list inside a fixed-height popover or a sidebar.
- A chat history that scrolls inside the conversation pane.
- A wide code sample or a log that scrolls sideways.
- A grid of templates inside a dialog.
Anatomy
<ScrollArea>
<ScrollAreaViewport>
<ScrollAreaContent />
</ScrollAreaViewport>
<ScrollAreaScrollbar>
<ScrollAreaThumb />
</ScrollAreaScrollbar>
</ScrollArea>A scrollbar renders its own thumb, so ScrollAreaThumb is only needed to style it. Leave a scrollbar out and that axis still scrolls, with no bar.
Examples
Horizontal
A scrollbar with orientation="horizontal" runs along the bottom. Leave room under the content for it.
Both directions
One scrollbar per axis. Each shows only while its axis overflows, and the fade covers all four edges.
Always visible
visibility="always" keeps the bar in place, for lists where the amount left to scroll matters.
Styled
Every part takes sx. Here the scrollbar gets a track and the thumb its own opacity steps.
Without fade
fade={false} on the viewport keeps a hard edge, as in a bordered list.
Best practices
- Give the area a height or a max height; it can only scroll if something limits it.
- Pick the
orientationfrom the content: vertical for lists, horizontal for a wide row, both for a canvas. - Set
visibilityto keep the bar showing when people need to see there’s more, such as a short list that ends exactly at the edge.
- Hide the scrollbar with nothing else to show there’s more content.
- Nest a scroll area in another that scrolls the same way. One container should own the scrolling.
API reference
ScrollArea
Groups the viewport and scrollbars. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
overflowEdgeThresholdPixels to scroll past before an edge counts as overflowing. | number | { xStart, xEnd, yStart, yEnd } | 0 |
renderReplaces the rendered element, e.g. render={<ul />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ScrollAreaViewport
The element that scrolls. Renders a <div>; takes a ref.
| Prop | Type | Default |
|---|---|---|
fadeFades content at an edge with more to scroll to. The fade grows with the distance scrolled. | boolean | true |
renderReplaces the rendered element, e.g. render={<ul />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ScrollAreaContent
Wraps what scrolls, so the area can track its size. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
renderReplaces the rendered element, e.g. render={<ul />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ScrollAreaScrollbar
A thin overlay bar for one axis. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
orientationThe axis the bar controls. | 'vertical' | 'horizontal' | 'vertical' |
visibilityShows the bar on hover and scroll only, or keeps it in place. | 'auto' | 'always' | 'auto' |
keepMountedKeeps the bar in the DOM when its axis does not overflow. | boolean | false |
childrenThe thumb. Pass one to style it. | ReactNode | <ScrollAreaThumb /> |
renderReplaces the rendered element, e.g. render={<ul />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ScrollAreaThumb
The draggable thumb. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
renderReplaces the rendered element, e.g. render={<ul />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |