Scroll Area
Scrolls its content with a slim custom scrollbar: 10px wide with an 8px thumb that keeps 3:1 contrast.
Installation
npx shadcn@latest add @sevenone/scroll-areaUsage
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"Examples
Vertical
<ScrollArea className="h-72 w-48 rounded-md border" aria-label="Tags">
<div className="p-4">
<h4 className="mb-4 text-sm leading-none font-medium">Tags</h4>
{tags.map((tag) => (
<React.Fragment key={tag}>
<div className="text-sm">{tag}</div>
<Separator className="my-2" />
</React.Fragment>
))}
</div>
</ScrollArea>Horizontal
Add a ScrollBar with orientation="horizontal".
<ScrollArea className="w-96 rounded-md border whitespace-nowrap" aria-label="Brand colors">
<div className="flex w-max gap-4 p-4">
{swatches.map((s) => (
<figure key={s.name} className="shrink-0">
<div className="h-24 w-32 rounded-md border" style={{ backgroundColor: s.hex }} />
<figcaption className="pt-2 text-sm text-muted-foreground">
<span className="font-medium text-foreground">{s.name}</span> {s.hex}
</figcaption>
</figure>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>Accessibility
- The scrolling area takes keyboard focus, so people can scroll it with the arrow keys; it shows the 2px focus ring.
- Name it with aria-label or aria-labelledby; it then becomes a named region for screen readers.
- The thumb uses the input-border color, which is 3:1 on the background, so it stays visible.