A React component for creating accessible scroll areas with customizable scrollbars
npx @tessl/cli install tessl/npm-radix-ui--react-scroll-area@1.2.0A comprehensive React component for creating accessible scroll areas with customizable scrollbars. Built on Radix UI's accessibility-first design principles, it provides full control over scrollbar appearance and behavior while maintaining keyboard navigation, screen reader compatibility, and cross-browser consistency.
npm install @radix-ui/react-scroll-areaimport {
ScrollArea,
ScrollAreaViewport,
ScrollAreaScrollbar,
ScrollAreaThumb,
ScrollAreaCorner,
createScrollAreaScope,
} from "@radix-ui/react-scroll-area";CommonJS:
const {
ScrollArea,
ScrollAreaViewport,
ScrollAreaScrollbar,
ScrollAreaThumb,
ScrollAreaCorner,
createScrollAreaScope,
} = require("@radix-ui/react-scroll-area");Alternative imports using aliases:
import {
Root,
Viewport,
Scrollbar,
Thumb,
Corner,
} from "@radix-ui/react-scroll-area";import React from "react";
import {
ScrollArea,
ScrollAreaViewport,
ScrollAreaScrollbar,
ScrollAreaThumb,
ScrollAreaCorner,
} from "@radix-ui/react-scroll-area";
function MyScrollArea() {
return (
<ScrollArea style={{ width: 300, height: 200 }}>
<ScrollAreaViewport style={{ width: "100%", height: "100%" }}>
<div style={{ padding: 16 }}>
{/* Long content that exceeds the viewport */}
{Array.from({ length: 50 }, (_, i) => (
<div key={i} style={{ marginBottom: 8 }}>
Item {i + 1}
</div>
))}
</div>
</ScrollAreaViewport>
<ScrollAreaScrollbar orientation="vertical">
<ScrollAreaThumb />
</ScrollAreaScrollbar>
<ScrollAreaScrollbar orientation="horizontal">
<ScrollAreaThumb />
</ScrollAreaScrollbar>
<ScrollAreaCorner />
</ScrollArea>
);
}Radix UI Scroll Area follows a compositional API pattern with distinct components:
ScrollArea provides the context and coordination for all scrolling behaviorScrollAreaViewport defines the scrollable viewing area and manages overflowScrollAreaScrollbar components handle both horizontal and vertical scrollingScrollAreaThumb represents the draggable handle within scrollbarsScrollAreaCorner fills the space when both scrollbars are visibleThe fundamental building blocks for creating scroll areas with full compositional control over layout and behavior.
const ScrollArea: React.ForwardRefExoticComponent<
ScrollAreaProps & React.RefAttributes<ScrollAreaElement>
>;
interface ScrollAreaProps extends React.ComponentPropsWithoutRef<"div"> {
type?: "auto" | "always" | "scroll" | "hover"; // default: "hover"
dir?: "ltr" | "rtl";
scrollHideDelay?: number; // default: 600
}
const ScrollAreaViewport: React.ForwardRefExoticComponent<
ScrollAreaViewportProps & React.RefAttributes<ScrollAreaViewportElement>
>;
interface ScrollAreaViewportProps extends React.ComponentPropsWithoutRef<"div"> {
nonce?: string;
}Customizable scrollbar components that support multiple display modes, orientations, and accessibility features.
const ScrollAreaScrollbar: React.ForwardRefExoticComponent<
ScrollAreaScrollbarProps & React.RefAttributes<ScrollAreaScrollbarElement>
>;
interface ScrollAreaScrollbarProps extends React.ComponentPropsWithoutRef<"div"> {
orientation?: "horizontal" | "vertical";
forceMount?: true;
}
const ScrollAreaThumb: React.ForwardRefExoticComponent<
ScrollAreaThumbProps & React.RefAttributes<ScrollAreaThumbElement>
>;
interface ScrollAreaThumbProps extends React.ComponentPropsWithoutRef<"div"> {
forceMount?: true;
}Corner handling, context management, and advanced configuration options for complex scroll area implementations.
const ScrollAreaCorner: React.ForwardRefExoticComponent<
ScrollAreaCornerProps & React.RefAttributes<ScrollAreaCornerElement>
>;
interface ScrollAreaCornerProps extends React.ComponentPropsWithoutRef<"div"> {}
function createScrollAreaScope(): Scope;type ScrollAreaElement = React.ComponentRef<"div">;
type ScrollAreaViewportElement = React.ComponentRef<"div">;
type ScrollAreaScrollbarElement = React.ComponentRef<"div">;
type ScrollAreaThumbElement = React.ComponentRef<"div">;
type ScrollAreaCornerElement = React.ComponentRef<"div">;
// Context scope type for nested scroll areas
type Scope = any;
// Component aliases
const Root: typeof ScrollArea;
const Viewport: typeof ScrollAreaViewport;
const Scrollbar: typeof ScrollAreaScrollbar;
const Thumb: typeof ScrollAreaThumb;
const Corner: typeof ScrollAreaCorner;