Scroll area
A scroll container with styled scrollbars on Base UI ScrollArea.
Vertical
import { ScrollArea } from "@/components/ui/scroll-area"
const releases = Array.from({ length: 18 }, (_, index) => {
const minor = 18 - index
return { version: `4.${minor}`, changes: 3 + ((minor * 7) % 11) }
})
export default function ScrollAreaVertical() {
return (
<ScrollArea className="h-56 w-full max-w-xs rounded-md border">
<ul aria-label="Releases" className="flex flex-col p-1 text-sm">
{releases.map(({ version, changes }) => (
<li key={version} className="flex justify-between gap-4 px-2 py-1.5">
<span>Release {version}</span>
<span className="text-muted-foreground tabular-nums">{changes} changes</span>
</li>
))}
</ul>
</ScrollArea>
)
}
Horizontal
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"
const columns = ["Backlog", "To do", "In progress", "In review", "Ready to ship", "Done"]
export default function ScrollAreaHorizontal() {
return (
<ScrollArea className="w-full max-w-md rounded-md border">
<ul aria-label="Board columns" className="flex w-max gap-2 p-3 text-sm">
{columns.map((column, index) => (
<li key={column} className="flex h-24 w-36 flex-col justify-between rounded-md bg-muted p-2.5">
<span className="font-medium">{column}</span>
<span className="text-muted-foreground tabular-nums">{2 + index * 3} tasks</span>
</li>
))}
</ul>
<ScrollBar orientation="horizontal" />
</ScrollArea>
)
}
Installation
npx shadcn@latest add @khaeli/scroll-areabunx --bun shadcn@latest add @khaeli/scroll-areaInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- @base-ui/react ^1.7.0
Keyboard
Tab- Moves focus to the viewport when its content overflows.
Arrow keysPage UpPage DownHomeEnd- Scroll the focused viewport, as in any scrolling region.
Accessible name
- The viewport has no role and no name. Name what is inside it instead, for example an
aria-labelon the list. - For sideways scrolling add
<ScrollBar orientation="horizontal" />after the content.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/scroll-area.json