$npx @dinachi/cli@latest add scroll-area
Tags
v1.2.0-beta.50
v1.2.0-beta.49
v1.2.0-beta.48
v1.2.0-beta.47
v1.2.0-beta.46
v1.2.0-beta.45
v1.2.0-beta.44
v1.2.0-beta.43
v1.2.0-beta.42
v1.2.0-beta.41
v1.2.0-beta.40
v1.2.0-beta.39
v1.2.0-beta.38
v1.2.0-beta.37
v1.2.0-beta.36
v1.2.0-beta.35
v1.2.0-beta.34
v1.2.0-beta.33
v1.2.0-beta.32
v1.2.0-beta.31
v1.2.0-beta.30
v1.2.0-beta.29
v1.2.0-beta.28
v1.2.0-beta.27
v1.2.0-beta.26
v1.2.0-beta.25
v1.2.0-beta.24
v1.2.0-beta.23
v1.2.0-beta.22
v1.2.0-beta.21
v1.2.0-beta.20
v1.2.0-beta.19
v1.2.0-beta.18
v1.2.0-beta.17
v1.2.0-beta.16
v1.2.0-beta.15
v1.2.0-beta.14
v1.2.0-beta.13
v1.2.0-beta.12
v1.2.0-beta.11
v1.2.0-beta.10
v1.2.0-beta.9
v1.2.0-beta.8
v1.2.0-beta.7
v1.2.0-beta.6
v1.2.0-beta.5
v1.2.0-beta.4
v1.2.0-beta.3
v1.2.0-beta.2
v1.2.0-beta.1
orientationvertical
horizontal
both
tagsrelease-tags.tsx
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 ReleaseTags() {
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>
)
}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
Tags
v1.2.0-beta.50
v1.2.0-beta.49
v1.2.0-beta.48
v1.2.0-beta.47
v1.2.0-beta.46
v1.2.0-beta.45
v1.2.0-beta.44
v1.2.0-beta.43
v1.2.0-beta.42
v1.2.0-beta.41
v1.2.0-beta.40
v1.2.0-beta.39
v1.2.0-beta.38
v1.2.0-beta.37
v1.2.0-beta.36
v1.2.0-beta.35
v1.2.0-beta.34
v1.2.0-beta.33
v1.2.0-beta.32
v1.2.0-beta.31
v1.2.0-beta.30
v1.2.0-beta.29
v1.2.0-beta.28
v1.2.0-beta.27
v1.2.0-beta.26
v1.2.0-beta.25
v1.2.0-beta.24
v1.2.0-beta.23
v1.2.0-beta.22
v1.2.0-beta.21
v1.2.0-beta.20
v1.2.0-beta.19
v1.2.0-beta.18
v1.2.0-beta.17
v1.2.0-beta.16
v1.2.0-beta.15
v1.2.0-beta.14
v1.2.0-beta.13
v1.2.0-beta.12
v1.2.0-beta.11
v1.2.0-beta.10
v1.2.0-beta.9
v1.2.0-beta.8
v1.2.0-beta.7
v1.2.0-beta.6
v1.2.0-beta.5
v1.2.0-beta.4
v1.2.0-beta.3
v1.2.0-beta.2
v1.2.0-beta.1
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>
);
}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
A row of tiles that scrolls sideways.
import { ScrollArea } from '@/components/ui/scroll-area';
export function Example() {
const items = Array.from({ length: 20 }).map((_, i) => ({
title: `Item ${i + 1}`,
color: `hsl(${i * 18}, 70%, 80%)`,
}));
return (
<ScrollArea className="w-full max-w-md rounded-md border" orientation="horizontal">
<div className="flex gap-3 p-4">
{items.map((item) => (
<div
key={item.title}
className="flex h-20 w-20 shrink-0 items-center justify-center rounded-md text-xs font-medium"
style={{ backgroundColor: item.color }}
>
{item.title}
</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.overflowEdgeThresholdnumber | { xStart, xEnd, yStart, yEnd } = 0
Pixels to scroll before the overflow edge attributes apply.Takes the props of the element it renders.
Takes the props of the element it renders.
orientation"vertical" | "horizontal" = "vertical"
The axis it scrolls.keepMountedboolean = false
Keeps the scrollbar mounted when there is nothing to scroll.Takes the props of the element it renders.
Takes the props of the element it renders.
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.
Keyboard
TabFocuses the viewport when it can scroll
↑↓←→Scrolls the focused viewport
Page UpPage DownScrolls by a page
HomeEndScrolls to the start or end
TabFocuses the viewport when it can scroll
↑↓←→Scrolls the focused viewport
Page UpPage DownScrolls by a page
HomeEndScrolls to the start or end