Scroll area
A region with its own vertical scroll and a styled scrollbar, for long lists inside a fixed-height container.
type
<ScrollArea type="hover" />When to use
- A long list or log inside a panel that must keep its size, such as the history of a process.
- A side panel or popup whose content can outgrow the available height.
- A block that scrolls on its own while the rest of the page stays still.
When not to use
- The whole page. Let the page scroll. Nested scroll regions trap the wheel and the keyboard.
- Lists the user searches. Use
CommandorCombobox, which carry their own scroll. - Tables with a sticky header. Use
Tableand its container. - Two panels the user resizes. Use
Resizable.
Examples
Default
The scrollbar appears while the pointer is over the area. Give the area a height (h-64), otherwise it grows with its content and never scrolls.
Always visible
type="always" keeps the bar on screen, so people see at once that there is more to read. Prefer it for lists the user must go through to the end.
type |
The scrollbar shows |
|---|---|
hover |
Default. While the pointer is over the area. |
scroll |
While scrolling, then hides after scrollHideDelay. |
auto |
Only when the content overflows. |
always |
Always. |
Content
- Cut the content at a natural point: the last visible row is half hidden, which tells people there is more.
- Keep the first rows the ones people need most.
- Say how much there is when you can: “12 eventos”.
Do and don’t
Accessibility
- Built on Radix Scroll Area. The viewport is a native scrolling element, so the mouse wheel, touch and trackpad work as usual.
- Keyboard scrolling works when focus is inside the area, for example on a link or a button in it. Arrow keys,
PageUp,PageDown,HomeandEndscroll the viewport. - The viewport is not focusable by itself, and
ScrollAreadoes not let you give it atabindex. When the content has no focusable element, keyboard users cannot scroll it. Put a focusable item in the content, or use a different pattern.
Code
import { ScrollArea } from "@repo/ui/scroll-area";
<ScrollArea className="h-64 w-80 rounded-lg border border-primary">
{events.map((event) => (
<p key={event.id}>{event.label}</p>
))}
</ScrollArea>;
Props
ScrollArea| Prop | Type | Default | Description |
|---|---|---|---|
scrollHideDelay | unknown | 600 | Milliseconds before the scrollbar hides, when `type` is `hover` or `scroll` |
type | "auto" | "always" | "hover" | "scroll" | hover | When the scrollbar shows: on hover, while scrolling, only when content overflows, or always |
ScrollBar| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "vertical" | "horizontal" | "vertical" | Which axis the bar controls. `ScrollArea` already renders the vertical one. |
Known issues
| Issue | Effect |
|---|---|
The viewport has no tabindex and ScrollArea forwards props to the root only. |
A region with text only cannot be scrolled with the keyboard. This breaks keyboard access (WCAG 2.1.1) in that case. |
The thumb uses bg-stroke-secondary, a 10% opacity color. |
The thumb is almost invisible on a light background, which makes it hard to see where you are in the list. |
The scrollbar is 10px wide (w-2.5). |
Below the 24px minimum hit target. Hard to grab with a mouse. |
ScrollArea renders only the vertical ScrollBar. |
Content wider than the area has no styled horizontal bar unless the app also mounts ScrollBar orientation="horizontal". |