suiss/ui · Component
Scroll Area
A scrollable region with slim, custom-styled scrollbars.
Scroll Area is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Scroll Area wraps the scroll area primitive of the chosen base. ScrollArea renders the root, a focusable viewport for your content, a vertical ScrollBar and a corner. Add a horizontal ScrollBar as a child when content scrolls sideways.
Use Scroll Area to give overflowing content a consistent scrollbar across platforms. For chat transcripts that should open at the latest message, use Message Scroller.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a ScrollArea:
Examples
Horizontal
A row of album covers that scrolls sideways. Make the content wider than the area, for example with w-max.
Include a ScrollBar with orientation="horizontal" to show the horizontal scrollbar.
Accessibility
- The viewport is focusable while its content overflows, so keyboard users can Tab to it and scroll with the arrow keys.
- The viewport is always focusable, so keyboard users can Tab to it and scroll with the arrow keys.
- Focus is shown with the standard focus ring around the viewport.
- The custom scrollbars are presentational; native scrolling by wheel, touch and keyboard still works.
API Reference
ScrollArea
The root that renders the viewport, the vertical scrollbar and the corner.
Also accepts the props of the primitive part it wraps.
The root that renders a natively scrolling viewport.
Also accepts the props of React.ComponentProps<"div">.
The viewport scrolls natively and shows the browser's thin scrollbars, tinted with the border color.
Give ScrollArea a fixed height or width with className so its content can overflow. Children render inside the viewport, which inherits the root's border radius, so rounded containers clip their content.
ScrollBar
A scrollbar track and thumb for one orientation, vertical by default.
| Prop | Type | Default |
|---|---|---|
orientation | "vertical" | "horizontal" | "vertical" |
Also accepts the props of the primitive part it wraps.
orientation sets the direction the scrollbar controls. Scrollbars expose data-orientation, and the thumb uses the border color.
Renders nothing. The viewport uses the browser's native scrollbars. ScrollBar is kept so code written for the other bases still compiles.
Each part sets a data-slot, such as scroll-area-viewport or scroll-area-thumb, for styling.
Each part sets a data-slot, scroll-area or scroll-area-viewport, for styling.