Scroll area
A scrolling region whose edges fade where more content is hidden.
Demo
Usage
import { List, ScrollArea } from '@tuttn/slant'
// Vertical by default: give it a height, and the top and bottom fade only
// where content is hidden past them.
<ScrollArea label="Recent activity" style={{ maxHeight: 200 }}>
<List>{rows}</List>
</ScrollArea>
// Sideways, with a longer fade; start and end follow the text direction.
<ScrollArea orientation="horizontal" fadeSize={40} label="Tags">
<div style={{ display: 'flex', gap: 8, width: 'max-content' }}>{chips}</div>
</ScrollArea>
// Both axes, no fade: just the thin scrollbar.
<ScrollArea orientation="both" fade={false} style={{ height: 320 }}>
<Table columns={columns} rows={rows} />
</ScrollArea>
// The ref is the scrolling element itself.
const ref = useRef<HTMLDivElement>(null)
ref.current?.scrollTo({ top: 0 })Props
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'vertical' | 'horizontal' | 'both' | 'vertical' | The direction the content scrolls in; the other axis is clipped. |
fade | boolean | true | Fades the edges where content is hidden past them. |
fadeSize | number | 24 | How far the fade reaches in from an edge, in pixels. |
label | string | — | The region's accessible name. With it, the area is a `role="region"` landmark named by it. |
…rest | HTMLAttributes<HTMLDivElement> | — | The ref, className, style and other attributes go on the scrolling div itself; there is no wrapper. |
ScrollArea is one element: the div that scrolls. It sets data-overflow-top, -bottom, -start and -end on the edges with content hidden past them, as it scrolls and whenever it or its first child changes size, and the stylesheet fades those edges with a mask. Start and end are logical, so under right-to-left text the start is on the right. The fade is dropped while the area has keyboard focus, so the focus ring shows in full.
While its content overflows, the area is in the tab order, so the arrow keys, Page Up and Page Down can scroll it. Give it a label to make it a named region a screen reader can find; without one it is a plain div. Its scrollbar is the thin one, coloured from the theme.