Scroll Area
Custom-styled scrollbar that matches your design system. Hides native OS scrollbars.
Examples
Horizontal
Use ScrollBar with orientation='horizontal' for horizontal scrolling.
import { ScrollArea, ScrollAreaScrollbar } from "@codefast/ui/scroll-area";
import { Image } from "@unpic/react";
export interface Artwork {
artist: string;
art: string;
}
export const works: Array<Artwork> = [
{
artist: "Ornella Binni",
art: "https://images.unsplash.com/photo-1465869185982-5a1a7522cbcb?auto=format&fit=crop&w=300&q=80",
},
{
artist: "Tom Byrom",
art: "https://images.unsplash.com/photo-1548516173-3cabfa4607e9?auto=format&fit=crop&w=300&q=80",
},
{
artist: "Vladimir Malyavko",
art: "https://images.unsplash.com/photo-1494337480532-3725c85fd2ab?auto=format&fit=crop&w=300&q=80",
},
];
export function ScrollAreaHorizontalDemo() {
return (
<ScrollArea className="w-96 rounded-md border border-ui-border whitespace-nowrap">
<div className="flex w-max space-x-4 p-4">
{works.map((artwork) => (
<figure key={artwork.artist} className="shrink-0">
<div className="overflow-hidden rounded-md">
<Image
alt={`Photo by ${artwork.artist}`}
className="aspect-[3/4] w-[150px] object-cover"
height={400}
layout="constrained"
src={artwork.art}
width={300}
/>
</div>
<figcaption className="pt-2 text-xs text-ui-muted">
Photo by <span className="font-semibold text-ui-fg">{artwork.artist}</span>
</figcaption>
</figure>
))}
</div>
<ScrollAreaScrollbar orientation="horizontal" />
</ScrollArea>
);
}
RTL
Right-to-left layout support for languages such as Arabic and Hebrew.
Translations are AI-generated for demonstration and may be imperfect.
import { ScrollArea } from "@codefast/ui/scroll-area";
import { Separator } from "@codefast/ui/separator";
import * as React from "react";
import type { Translations } from "#/features/components-catalog/components/detail/language";
import { useTranslation } from "#/features/components-catalog/components/detail/language-context";
const tags = Array.from({ length: 50 }).map((_, i, a) => `v1.2.0-beta.${a.length - i}`);
const translations: Translations = {
en: {
dir: "ltr",
values: {
tags: "Tags",
},
},
ar: {
dir: "rtl",
values: {
tags: "العلامات",
},
},
he: {
dir: "rtl",
values: {
tags: "תגיות",
},
},
};
export function ScrollAreaRtl() {
const { dir, t } = useTranslation(translations, "ar");
return (
<ScrollArea className="h-72 w-48 rounded-md border" dir={dir}>
<div className="p-4">
<h4 className="mb-4 text-sm leading-none font-medium">{t.tags}</h4>
{tags.map((tag) => (
<React.Fragment key={tag}>
<div className="text-sm">{tag}</div>
<Separator className="my-2" />
</React.Fragment>
))}
</div>
</ScrollArea>
);
}
Usage
The minimal import and composition — see Examples below for styled, real-world variants.
import { ScrollArea } from "@codefast/ui/scroll-area";
export function ScrollAreaUsage() {
return (
<ScrollArea className="h-72 w-48 rounded-md border">
<div className="p-4">
{Array.from({ length: 20 }, (_, index) => (
<p key={index} className="text-sm">
Item {index + 1}
</p>
))}
</div>
</ScrollArea>
);
}
Anatomy
How the parts nest — every slot the component exposes, in composition order.
Features
- Replaces the native scrollbar visually only — real scroll and keyboard behaviour stay intact underneath.
- Add a second ScrollAreaScrollbar orientation="horizontal" alongside the default vertical one for two-axis scrolling.
- size (from context) controls scrollbar thickness for both orientations at once.
API reference
Props for each part of the component. All native element props are also forwarded.
ScrollArea
A viewport with a styled scrollbar that replaces the native one.
classNamestringSet the fixed size (e.g. h-44 w-48) the content scrolls within.
ScrollAreaScrollbar
orientation"vertical" | "horizontal"Render a horizontal scrollbar in addition to the vertical one.
Accessibility
Built to be keyboard-navigable and screen-reader friendly out of the box.
- The viewport stays keyboard-scrollable and focusable as normal.
- Custom scrollbars are visual; native scroll behaviour is preserved underneath.
- Ensure content has enough contrast against the scroll surface.
Guidelines
Conventions that keep usage consistent across an app.
Do
- Use for constrained lists, menus, and panels.
- Give the area a clear fixed size so the scrollbar makes sense.
Don’t
- Don’t wrap the whole page — let it scroll natively.
- Don’t hide that content is scrollable; show a peek of the next row.
Explore further
Ready to integrate?
Follow the Getting Started guide to install @codefast/ui, or browse the full component gallery.