Scroll Area

A fixed-size scrolling box with thin styled scrollbars.

Source
$npx @dinachi/cli@latest add scroll-area
orientation
tags

Usage

import { ScrollArea } from "@/components/ui/scroll-area"

export function ReleaseNotes() {
  return (
    <ScrollArea className="h-64 w-72 rounded-md border">
      <div className="p-4">{/* long content */}</div>
    </ScrollArea>
  )
}

Examples

A long list in a fixed height.
import { ScrollArea } from '@/components/ui/scroll-area';
import { Separator } from '@/components/ui/separator';

const tags = Array.from({ length: 50 }).map(
  (_, i, a) => `v1.2.0-beta.${a.length - i}`
);

export function Example() {
  return (
    <ScrollArea className="h-72 w-48 rounded-md border">
      <div className="p-4">
        <h4 className="mb-4 text-sm font-medium leading-none">Tags</h4>
        {tags.map((tag) => (
          <div key={tag}>
            <div className="text-sm">{tag}</div>
            <Separator className="my-2" />
          </div>
        ))}
      </div>
    </ScrollArea>
  );
}

Notes

Compound or parts

ScrollArea builds every part; wrap content in it. Use ScrollAreaRoot and the parts only for a custom layout, such as relocated scrollbars.

Scrollbars on hover

Scrollbars show whenever there is overflow. To show them only on hover or while scrolling, style on data-hovering and data-scrolling.

Edge fades

The root sets data-overflow-y-start, data-overflow-y-end and the x versions while content continues past that edge. Use them to fade only cut-off edges.

API

orientation"vertical" | "horizontal" | "both" = "vertical"
Which scrollbars to render. both adds the corner.
viewportClassNamestring
Classes for the inner viewport.
scrollbarClassNamestring
Classes for every scrollbar.
overflowEdgeThresholdnumber | { xStart, xEnd, yStart, yEnd } = 0
Pixels to scroll before the overflow edge attributes apply.
classNamestring
Size the area here, such as h-64. It does not grow to fit.

Accessibility

  • The viewport scrolls natively: wheel, touch and keyboard all work.
  • The viewport is focusable while it has overflow.
  • The native scrollbar is replaced by the styled one; its thumb is draggable.