Scroll Area
Augments native scroll functionality for custom, cross-browser styling.
import { For } from "solid-js";import { ScrollArea } from "~/components/ui/scroll-area";import { Separator } from "~/components/ui/separator";
const tags = Array.from({ length: 50 }).map( (_, index, array) => `v1.2.0-beta.${array.length - index}`,);
export default function ScrollAreaDemo() { return ( <ScrollArea class="h-72 w-48 rounded-md border"> <div class="p-4"> <h4 class="mb-4 font-medium text-sm leading-none">Tags</h4> <For each={tags}> {(tag) => ( <> <div class="text-sm">{tag}</div> <Separator class="my-2" /> </> )} </For> </div> </ScrollArea> );}Installation
Usage
import { ScrollArea, ScrollBar } from "~/components/ui/scroll-area";<ScrollArea class="h-[200px] w-[350px] rounded-md border p-4"> Your scrollable content here.</ScrollArea>Composition
ScrollArea renders its own viewport and a vertical ScrollBar internally, so most usages only need
the root:
ScrollArea└── ScrollBar (horizontal, opt-in)Horizontal
Add a ScrollBar with orientation="horizontal" as a direct child for horizontal scrolling. The
vertical scrollbar is always present internally and simply stays hidden when its axis doesn't overflow.
/** biome-ignore-all lint/a11y/noRedundantAlt: upstream demo describes each photograph */import { For } from "solid-js";import { ScrollArea, ScrollBar } from "~/components/ui/scroll-area";
const artworks = [ { artist: "Ornella Binni", art: "https://images.unsplash.com/photo-1465869185982-5a1a7522cbcb?auto=format&fit=crop&w=300&q=80", }, { artist: "Tom Byrom", art: "https://images.unsplash.com/photo-1548516173-3cabfa4607e9?auto=format&fit=crop&w=300&q=80", }, { artist: "Vladimir Malyavko", art: "https://images.unsplash.com/photo-1494337480532-3725c85fd2ab?auto=format&fit=crop&w=300&q=80", },] as const;
export default function ScrollAreaHorizontalDemo() { return ( <ScrollArea class="w-96 rounded-md border whitespace-nowrap"> <div class="flex w-max space-x-4 p-4"> <For each={artworks}> {(artwork) => ( <figure class="shrink-0"> <div class="overflow-hidden rounded-md"> <img src={artwork.art} alt={`Photo by ${artwork.artist}`} class="aspect-[3/4] h-fit w-fit object-cover" width={300} height={400} /> </div> <figcaption class="pt-2 text-xs text-muted-foreground"> Photo by <span class="font-semibold text-foreground">{artwork.artist}</span> </figcaption> </figure> )} </For> </div> <ScrollBar orientation="horizontal" /> </ScrollArea> );}API Reference
ScrollArea
The root container. It renders a scrollable viewport around its children, a vertical ScrollBar, and
a corner element, and shows/hides scrollbars based on hover state and overflow.
All other props are forwarded to the root div.
ScrollBar
A scrollbar track and thumb for one axis. It is always mounted, but stays visually hidden
(opacity-0, non-interactive) unless its axis overflows and the scroll area is hovered or the thumb
is being dragged.
ScrollArea is a native SolidJS implementation and does not build on a Kobalte or Corvu primitive, so it does not expose a primitive API to link to.