Components

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

Do
  • Give the area a height or a max height; it can only scroll if something limits it.
  • Pick the orientation from the content: vertical for lists, horizontal for a wide row, both for a canvas.
  • Set visibility to keep the bar showing when people need to see there’s more, such as a short list that ends exactly at the edge.
Don’t
  • 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>.

PropTypeDefault
overflowEdgeThreshold
Pixels to scroll past before an edge counts as overflowing.
number | { xStart, xEnd, yStart, yEnd }0
render
Replaces the rendered element, e.g. render={<ul />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ScrollAreaViewport

The element that scrolls. Renders a <div>; takes a ref.

PropTypeDefault
fade
Fades content at an edge with more to scroll to. The fade grows with the distance scrolled.
booleantrue
render
Replaces the rendered element, e.g. render={<ul />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ScrollAreaContent

Wraps what scrolls, so the area can track its size. Renders a <div>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<ul />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ScrollAreaScrollbar

A thin overlay bar for one axis. Renders a <div>.

PropTypeDefault
orientation
The axis the bar controls.
'vertical' | 'horizontal''vertical'
visibility
Shows the bar on hover and scroll only, or keeps it in place.
'auto' | 'always''auto'
keepMounted
Keeps the bar in the DOM when its axis does not overflow.
booleanfalse
children
The thumb. Pass one to style it.
ReactNode<ScrollAreaThumb />
render
Replaces the rendered element, e.g. render={<ul />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ScrollAreaThumb

The draggable thumb. Renders a <div>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<ul />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—