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
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies and add the
cnhelper:
- Copy the source into
components/ui/scroll-area.tsx:
- Update the import paths to match your project.
Usage
Give ScrollArea a fixed height or width with className so its content can overflow. Children render inside the viewport. For horizontal scrolling, make the content wider than the area (for example with w-max) and include ScrollBar with orientation="horizontal".
Examples
Horizontal
A row of album covers that scrolls sideways with a horizontal scrollbar.
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.
ScrollBar
A scrollbar track and thumb for one orientation, vertical by default.
Also accepts the props of the primitive part it wraps.
Accessibility
- The viewport is 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.
Notes
- Styling hooks:
data-slotvaluesscroll-area,scroll-area-viewport,scroll-area-scrollbarandscroll-area-thumb. Scrollbars exposedata-orientation. - The thumb uses the
bordercolor. - The viewport inherits the root's border radius, so rounded containers clip their content.