Loading component…
Loading component…
A box that scrolls the browser's own way with a slim scrollbar of its own
To reuse this local React demo, copy all files from the Code tab into the same folder, then import ScrollArea from ./scroll-area.
import { ScrollArea } from "@/components/ui/scroll-area";
export function Sources({ items }: { items: { title: string; site: string }[] }) {
return (
<ScrollArea maxHeight={240} fade aria-label="Sources">
<ul>
{items.map((s) => (
<li key={s.title}>
{s.title} · {s.site}
</li>
))}
</ul>
</ScrollArea>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| orientation | "vertical" \| "horizontal" \| "both" | "vertical" | Which way it scrolls; the other way is clipped |
| type | "hover" \| "scroll" \| "always" | "hover" | When the bar shows: while the pointer is over the box or it scrolls · only while it scrolls · always, as long as there is more |
| fade | boolean | false | Soft fades at the edges where there is more to scroll; they shrink as you reach an end |
| maxHeight | number \| string | How tall it grows before it scrolls. Or give it a fixed height with className or style | |
| viewportRef | Ref<HTMLDivElement> | The element that scrolls – for scrollTo, scrollTop or an IntersectionObserver root | |
| onScroll | UIEventHandler<HTMLDivElement> | Fires on the element that scrolls | |
| aria-label | string | Names the scrolling region for screen readers (or aria-labelledby) | |
| ...div props | ComponentProps<"div"> | className, style, id, ref … go to the outer box |
Follows its box and its content as either changes size – new rows, a narrower window, fonts loading
Touch screens scroll with the finger as usual; the slim bar only shows where you are while you scroll
Right to left: the bar sits on the left and the sideways thumb runs from the right
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.