Scroll Area
Layout
Scrollable container with pixel styling.
Installation
npm install @radix-ui/react-scroll-areaImport
import { PixelScrollArea } from "@/components/ui/pixel-scroll-area"Usage
Component Source
Copy and paste the following code into your project at /src/components/ui/pixel-scroll-area.tsx
"use client";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import type * as React from "react";
import { cn } from "@/lib/utils";
function PixelScrollArea({
className,
children,
...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
return (
<ScrollAreaPrimitive.Root
className={cn("relative overflow-hidden", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
<PixelScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
);
}
function PixelScrollBar({
className,
orientation = "vertical",
...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
return (
<ScrollAreaPrimitive.ScrollAreaScrollbar
orientation={orientation}
className={cn(
"flex touch-none select-none transition-colors duration-0",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
className,
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 bg-black" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
);
}
export { PixelScrollArea, PixelScrollBar };
Accessibility
This component is built with accessibility in mind, including proper ARIA attributes, keyboard navigation, and focus management.