Scroll Area

Augments native scroll functionality for custom, cross-browser styling.

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
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 ScrollAreaDemo() {
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) => (
<React.Fragment key={tag}>
<div className="text-sm">
{tag}
</div>
<Separator className="my-2" />
</React.Fragment>
))}
</div>
</ScrollArea>
)
}

Installation

CLI

bash
npx fivui add scroll-area

Manual

Install the following dependencies:

bash
npm install @radix-ui/react-scroll-area

Usage

tsx
import { ScrollArea } from "@/components/ui/scroll-area"
tsx
<ScrollArea className="h-[200px] w-[350px] rounded-md border p-4">
Jokester began sneaking into the castle in the middle of the night and
leaving jokes all over the place: under the king's pillow, in his soup,
even in the royal toilet. The king was furious, but he couldn't seem to
stop Jokester. And then, one day, the people of the kingdom discovered
that the jokes left by Jokester were so funny that they couldn't help
but laugh. And once they started laughing, they couldn't stop.
</ScrollArea>

Examples

Horizontal Scrolling

Use horizontal scrolling for content that extends beyond the container width.

Horizontal Scroll
Scrollable content in horizontal direction
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
tsx
import { ScrollArea } from "@/components/ui/scroll-area"
export function ScrollAreaHorizontal() {
return (
<ScrollArea className="w-96 whitespace-nowrap rounded-md border">
<div className="flex w-max space-x-4 p-4">
{Array.from({ length: 20 }).map((_, i) => (
<div
key={i}
className="shrink-0 rounded-md border border-slate-200 bg-white p-4 shadow-sm"
>
<div className="h-20 w-20 rounded-md bg-slate-100" />
<div className="mt-2 text-sm font-medium">Item {i + 1}</div>
</div>
))}
</div>
</ScrollArea>
)
}

Chat Messages

A common use case for scroll areas is displaying chat messages or conversation history.

Chat Interface
Scrollable chat messages with alternating layout
Hey there! How's it going?
I'm doing well, thanks for asking!
That's great to hear. What have you been up to lately?
Just working on some new projects. How about you?
Same here! I've been learning React and Next.js.
That's awesome! Those are great technologies to learn.
Yeah, I'm really enjoying it so far.
If you need any help, feel free to ask!
Thanks, I appreciate that!
No problem at all. Good luck with your learning!
tsx
import { ScrollArea } from "@/components/ui/scroll-area"
export function ScrollAreaChat() {
const messages = [
"Hey there! How's it going?",
"I'm doing well, thanks for asking!",
"That's great to hear. What have you been up to lately?",
"Just working on some new projects. How about you?",
"Same here! I've been learning React and Next.js.",
"That's awesome! Those are great technologies to learn.",
"Yeah, I'm really enjoying it so far.",
"If you need any help, feel free to ask!",
"Thanks, I appreciate that!",
"No problem at all. Good luck with your learning!",
]
return (
<ScrollArea className="h-64 w-full rounded-md border p-4">
<div className="space-y-4">
{messages.map((message, i) => (
<div
key={i}
className={`flex ${
i % 2 === 0 ? "justify-start" : "justify-end"
}`}
>
<div
className={`max-w-xs rounded-lg px-3 py-2 text-sm ${
i % 2 === 0
? "bg-muted text-muted-foreground"
: "bg-primary text-primary-foreground"
}`}
>
{message}
</div>
</div>
))}
</div>
</ScrollArea>
)
}

API Reference

ScrollArea

Contains all the parts of a scroll area.

PropTypeDefaultDescription
typeauto | always | scroll | hoverhoverDescribes the nature of scrollbar visibility.
scrollHideDelaynumber600If type is set to either scroll or hover, this prop determines the length of time, in milliseconds, before the scrollbars are hidden after the user stops interacting with scrollbars.
dirltr | rtlltrThe reading direction of the scroll area.

External Documentation

Scroll Area is built on top of Radix UI Scroll Area. For more advanced usage and API details, refer to the official documentation.

View Radix UI Scroll Area Documentation