Scroll Area
A scrolling region with thin scrollbars that follow the theme. Fixed or content heights, vertical, horizontal, or both bars, and a bordered table frame for wide data grids.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/scroll-area.jsonCopies Scroll Area into your app, installs the packages, and adds the styles. Then import it from @/components/ui/scroll-area. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @base-ui/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Copy and paste the following code into your project.
'use client'; import { ScrollArea as BaseScrollArea } from '@base-ui/react/scroll-area'; import { stateClassName } from '@/lib/sprout/classes'; export const scrollAreaSizeNames = ['sm', 'md'] as const; export const scrollAreaVariantNames = ['plain', 'table'] as const; export const scrollAreaOrientationNames = ['vertical', 'horizontal', 'both'] as const; export type ScrollAreaSize = (typeof scrollAreaSizeNames)[number]; export type ScrollAreaVariant = (typeof scrollAreaVariantNames)[number]; export type ScrollAreaOrientation = (typeof scrollAreaOrientationNames)[number]; export interface ScrollAreaProps extends BaseScrollArea.Root.Props { size?: ScrollAreaSize; variant?: ScrollAreaVariant; orientation?: ScrollAreaOrientation; viewportLabel?: string | undefined; } export function ScrollArea({ className, children, size, variant = 'plain', orientation = 'vertical', viewportLabel, ...props }: ScrollAreaProps) { return ( <BaseScrollArea.Root data-slot="scroll-area" data-size={size} data-variant={variant} className={stateClassName<BaseScrollArea.Root.State>('sprout-scroll-area', className)} {...props} > <BaseScrollArea.Viewport data-slot="scroll-area-viewport" role={variant === 'table' ? 'region' : undefined} aria-label={viewportLabel} className="sprout-scroll-area-viewport" > {children} </BaseScrollArea.Viewport> {orientation !== 'horizontal' && <ScrollBar />} {orientation !== 'vertical' && <ScrollBar orientation="horizontal" />} <BaseScrollArea.Corner data-slot="scroll-area-corner" className="sprout-scroll-area-corner" /> </BaseScrollArea.Root> ); } export type ScrollBarProps = BaseScrollArea.Scrollbar.Props; export function ScrollBar({ className, orientation = 'vertical', ...props }: ScrollBarProps) { return ( <BaseScrollArea.Scrollbar data-slot="scroll-area-scrollbar" orientation={orientation} className={stateClassName<BaseScrollArea.Scrollbar.State>('sprout-scroll-area-scrollbar', className)} {...props} > <BaseScrollArea.Thumb data-slot="scroll-area-thumb" className="sprout-scroll-area-thumb" /> </BaseScrollArea.Scrollbar> ); }Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-scroll-area { min-width: 0; position: relative; } .sprout-scroll-area[data-size="sm"] { height: 10rem; } .sprout-scroll-area[data-size="md"] { height: 16rem; } .sprout-scroll-area[data-variant="table"] { border: 1px solid var(--sprout-input); border-radius: calc(var(--sprout-radius-control) + 2px); background: var(--sprout-surface); width: 100%; } .sprout-scroll-area-viewport { border-radius: inherit; overscroll-behavior: contain; width: 100%; height: 100%; } .sprout-scroll-area-viewport:focus-visible { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: -1px; } .sprout-scroll-area[data-variant="table"] > .sprout-scroll-area-viewport { max-height: 60dvh; } .sprout-scroll-area-scrollbar { z-index: 30; touch-action: none; user-select: none; padding: 1px; display: flex; } .sprout-scroll-area-scrollbar[data-orientation="vertical"] { border-left: 1px solid #0000; width: 10px; height: 100%; } .sprout-scroll-area-scrollbar[data-orientation="horizontal"] { border-top: 1px solid #0000; flex-direction: column; height: 10px; } .sprout-scroll-area-thumb { background: color-mix(in oklab, var(--sprout-muted) 40%, transparent); border-radius: 9999px; flex: 1 1 0; position: relative; } @media (hover: hover) { .sprout-scroll-area-thumb:hover { background: color-mix(in oklab, var(--sprout-muted) 60%, transparent); } } .sprout-scroll-area-scrollbar[data-scrolling] > .sprout-scroll-area-thumb, .sprout-scroll-area-thumb:active { background: color-mix(in oklab, var(--sprout-muted) 60%, transparent); } .sprout-scroll-area-corner { background: none; } @media (prefers-reduced-motion: no-preference) { .sprout-scroll-area-viewport { transition: outline-color var(--sprout-motion-fast) var(--sprout-motion-ease); } .sprout-scroll-area-thumb { transition: background-color var(--sprout-motion-fast) var(--sprout-motion-ease); } } }Import it from
@/components/ui/scroll-area. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/scroll-area.
Sizes
Each size with the variant and orientation it is used with. The bars appear only on axes that overflow.
Data grid
variant="table" with orientation="both". The table label names the region, and the header stays pinned while rows scroll.
Horizontal
orientation="horizontal" for a single row of cards. Shift + wheel, a trackpad swipe, or arrow keys on the focused region scroll it.
States
Loading and error content keep the table frame. Empty content does not overflow, so no bars draw and the region is skipped by Tab.
Usage
import { ScrollArea } from "@tulipfarm/sprout/scroll-area";
<ScrollArea size="sm" viewportLabel="Recent activity">
{records.map((record) => <p key={record.id}>{record.title}</p>)}
</ScrollArea>
<ScrollArea size="md" orientation="both" viewportLabel="Wide report">
<div className="w-160">…</div>
</ScrollArea>
<ScrollArea
variant="table"
orientation="both"
viewportLabel="Bulb plantings"
data-slot="table-container"
>
<table aria-label="Bulb plantings">…</table>
</ScrollArea>size is "sm" (10rem tall) or "md" (16rem tall). Leave it out to follow the content or your className. orientation is "vertical" (default),"horizontal", or "both". Each bar appears only while its axis overflows, and the corner fills the gap when both show.
variant="table" adds a 1px input-tone border, rounded corners, and the surface color. It caps the viewport at 60dvhand gives it role="region", named by viewportLabel. A sticky thead inside it stays pinned while rows scroll. Pass the table's own aria-label as viewportLabel. Other root props, such as data-slot, pass through to the root.
ScrollBar
import { ScrollBar } from "@tulipfarm/sprout/scroll-area";
<ScrollBar orientation="horizontal" className="my-bar" />ScrollArea draws its bars for you. ScrollBar is the same 10px track and pill thumb, exported for custom Base UI scroll area compositions. It takes Base UI scrollbar props, and classNamemay be a state function.
Accessibility
Scrolling stays native, so wheel, trackpad, touch, and keyboard all work. When content overflows, the viewport joins the Tab order and shows a focus ring; arrow keys, Page Up, Page Down, Home, and End then scroll it. When nothing overflows it leaves the Tab order. The bars are hidden from screen readers. Thumb color changes take 120ms and stop when reduced motion is requested.
Theme tokens
Thumbs use --sprout-muted at 40%, and 60% on hover or while scrolling. The table frame uses --sprout-input and --sprout-surface. Focus uses --sprout-focus.