Scroll Area
Augments native scroll functionality with custom cross-browser styled scrollbars built on Radix primitives.
scrollArea.tsx
Custom scrollbar area component supporting vertical, horizontal, and combined scroll orientations.
ReactRadix UITailwindUI ComponentScroll
"use client";
import * as React from "react";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import { cn } from "@/lib/utils";
export interface ScrollAreaProps
extends React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> {
orientation?: "vertical" | "horizontal" | "both";
}
const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
"flex touch-none select-none transition-colors p-0.5 bg-transparent",
orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent",
orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent",
className
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border hover:bg-muted-foreground/50 transition-colors" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
));
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
ScrollAreaProps
>(({ className, children, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn("relative overflow-hidden", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport className="size-full rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
{(orientation === "vertical" || orientation === "both") && (
<ScrollBar orientation="vertical" />
)}
{(orientation === "horizontal" || orientation === "both") && (
<ScrollBar orientation="horizontal" />
)}
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
));
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
export { ScrollArea, ScrollBar };
Vertical Scroll
Constrains vertical height and provides smooth custom scrollbar for long list content.
Horizontal Scroll
Set orientation to horizontal to manage wide content rows gracefully.
orientation:
vertical | horizontal | bothAPI Reference
Props — ScrollArea
Properties for configuring the ScrollArea component.
| Prop | Type | Default | Description |
|---|---|---|---|
| orientation | 'vertical' | 'horizontal' | 'both' | 'vertical' | Scrollbar axis direction rendered in the container viewport. |
| className | string | — | Tailwind CSS classes controlling explicit width, height, and border styles. |