Scroll Area

A box that scrolls its content natively under the kit's thin scrollbars, up and down by default, on Radix Scroll Area.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 21
Item 22
Item 23
Item 24
Item 25
Item 26
Item 27
Item 28
Item 29
Item 30
import { ScrollArea } from "@produkto/ui/ScrollArea";

const items: string[] = Array.from(
  { length: 30 },
  (_, index) => `Item ${index + 1}`,
);

const Example = () => (
  <ScrollArea className="h-72 w-48 rounded-md border border-border">
    <div className="flex flex-col gap-2 p-4 body-sm">
      {items.map((item) => (
        <div key={item}>{item}</div>
      ))}
    </div>
  </ScrollArea>
);

export default Example;

Usage

import { ScrollArea } from "@produkto/ui/ScrollArea";
<ScrollArea className="h-50 w-88 rounded-md border p-4">
  Content goes here.
</ScrollArea>

Examples

Orientation

orientation scrolls the content up and down (vertical, the default), sideways (horizontal) or both ways, with a bar on each side and a corner where they meet.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 21
Item 22
Item 23
Item 24
Item 25
Item 26
Item 27
Item 28
Item 29
Item 30
Item 31
Item 32
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 21
Item 22
Item 23
Item 24
Item 25
Item 26
Item 27
Item 28
Item 29
Item 30
Item 31
Item 32
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 21
Item 22
Item 23
Item 24
Item 25
Item 26
Item 27
Item 28
Item 29
Item 30
Item 31
Item 32
import { Label } from "@produkto/ui/Label";
import {
  ScrollArea,
  type ScrollAreaOrientation,
} from "@produkto/ui/ScrollArea";

const orientations: { orientation: ScrollAreaOrientation; label: string }[] = [
  { orientation: "vertical", label: "Vertical" },
  { orientation: "horizontal", label: "Horizontal" },
  { orientation: "both", label: "Both" },
];

const items: string[] = Array.from(
  { length: 32 },
  (_, index) => `Item ${index + 1}`,
);

const Example = () => (
  <div className="flex w-full max-w-sm flex-col gap-4">
    {orientations.map((item) => (
      <div className="flex flex-col gap-2" key={item.orientation}>
        <Label id={`scroll-area-orientation-${item.orientation}`}>
          {item.label}
        </Label>
        <ScrollArea
          aria-labelledby={`scroll-area-orientation-${item.orientation}`}
          className="h-40 rounded-md border border-border"
          orientation={item.orientation}
        >
          <div className="grid w-max grid-cols-8 gap-2 p-4">
            {items.map((tile) => (
              <div
                className="flex size-20 items-center justify-center rounded-lg bg-muted body-sm text-muted-foreground"
                key={tile}
              >
                {tile}
              </div>
            ))}
          </div>
        </ScrollArea>
      </div>
    ))}
  </div>
);

export default Example;

Type

type sets when the scrollbar shows: on hover and while scrolling (hover, the default), only while scrolling, whenever the content overflows (auto) or always.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
import { Label } from "@produkto/ui/Label";
import { ScrollArea, type ScrollAreaProps } from "@produkto/ui/ScrollArea";

const types: { type: NonNullable<ScrollAreaProps["type"]>; label: string }[] = [
  { type: "hover", label: "Hover" },
  { type: "scroll", label: "Scroll" },
  { type: "auto", label: "Auto" },
  { type: "always", label: "Always" },
];

const items: string[] = Array.from(
  { length: 20 },
  (_, index) => `Item ${index + 1}`,
);

const Example = () => (
  <div className="flex flex-wrap items-start gap-4">
    {types.map((item) => (
      <div className="flex flex-col gap-2" key={item.type}>
        <Label id={`scroll-area-type-${item.type}`}>{item.label}</Label>
        <ScrollArea
          aria-labelledby={`scroll-area-type-${item.type}`}
          className="h-40 w-32 rounded-md border border-border"
          type={item.type}
        >
          <div className="flex flex-col gap-2 p-4 body-sm">
            {items.map((entry) => (
              <div key={entry}>{entry}</div>
            ))}
          </div>
        </ScrollArea>
      </div>
    ))}
  </div>
);

export default Example;

API Reference

ScrollArea

ScrollAreaProps ยท components/ScrollArea/ScrollArea.types.ts
PropTypeDefault
orientationScrollAreaOrientation"vertical" | "horizontal" | "both""vertical"
viewportRefRef<HTMLDivElement>-

ScrollBar

ScrollBarProps ยท also takes the props of Radix ScrollArea.Scrollbar
PropTypeDefault
orientation"horizontal" | "vertical""vertical"

It also takes the props of Radix ScrollArea.Root.