Scroll Area
Named, keyboard-focusable scroll region with thin themed scrollbars, optional edge fade masks, and scroll containment.
pnpm dlx shadcn@latest add @haze/scroll-area---
import { cn } from "../../../lib/haze/utils";
interface Props {
label?: string;
direction?: "vertical" | "horizontal" | "both";
/** Adds dynamic edge fade masks at scrolled boundaries. */
fade?: boolean;
/** Reserves stable scrollbar gutter space to avoid layout shifts. */
scrollbarGutter?: boolean;
class?: string;
}
const { label = "Scrollable content", direction = "vertical", fade = false, scrollbarGutter = true, class: className } = Astro.props;
const directions = {
vertical: "max-h-44 overflow-y-auto overflow-x-hidden",
horizontal: "overflow-x-auto overflow-y-hidden",
both: "max-h-44 overflow-auto",
};
const fadeMasks = {
vertical: "[mask-image:linear-gradient(to_bottom,transparent_0,currentColor_var(--fade-top,0px),currentColor_calc(100%-var(--fade-bottom,0px)),transparent_100%)]",
horizontal: "[mask-image:linear-gradient(to_right,transparent_0,currentColor_var(--fade-left,0px),currentColor_calc(100%-var(--fade-right,0px)),transparent_100%)]",
both: "[mask-image:linear-gradient(to_bottom,transparent_0,currentColor_var(--fade-top,0px),currentColor_calc(100%-var(--fade-bottom,0px)),transparent_100%)]",
};
---
<div
role="region"
aria-label={label}
tabindex="0"
data-haze-scroll-area
data-fade={fade ? "" : undefined}
data-direction={direction}
class={cn(
"min-w-0 rounded-xl border border-border bg-card text-card-foreground [scrollbar-color:var(--color-border-strong)_transparent] [scrollbar-width:thin]",
"overscroll-contain focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
scrollbarGutter && direction !== "horizontal" && "[scrollbar-gutter:stable]",
directions[direction],
fade && fadeMasks[direction],
className,
)}
>
<slot><p class="px-3 py-2 text-[0.8125rem]/5">Scrollable content appears here.</p></slot>
</div>
<script>
function enhanceScrollAreas() {
document.querySelectorAll<HTMLElement>("[data-haze-scroll-area][data-fade]:not([data-enhanced])").forEach((el) => {
const update = () => {
const top = el.scrollTop > 2 ? 20 : 0;
const bottom = el.scrollTop + el.clientHeight < el.scrollHeight - 2 ? 20 : 0;
const left = el.scrollLeft > 2 ? 20 : 0;
const right = el.scrollLeft + el.clientWidth < el.scrollWidth - 2 ? 20 : 0;
el.style.setProperty("--fade-top", `${top}px`);
el.style.setProperty("--fade-bottom", `${bottom}px`);
el.style.setProperty("--fade-left", `${left}px`);
el.style.setProperty("--fade-right", `${right}px`);
};
el.addEventListener("scroll", update, { passive: true });
if ("ResizeObserver" in window) new ResizeObserver(update).observe(el);
update();
el.setAttribute("data-enhanced", "");
});
}
enhanceScrollAreas();
if (!document.documentElement.hasAttribute("data-haze-scroll-area-listener")) {
document.documentElement.setAttribute("data-haze-scroll-area-listener", "");
document.addEventListener("astro:page-load", enhanceScrollAreas);
}
</script>When to use
- One panel contains a long list or log with a bounded height.
- Horizontal tag strips or vertical sidebars need subtle scroll edge cues.
When not to use
- The content can use normal page scrolling without obscuring nearby controls.
Installation
Add the Haze registry to components.json once, then install Scroll Area with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/scroll-areanpx shadcn@latest add @haze/scroll-areayarn dlx shadcn@latest add @haze/scroll-areabunx --bun shadcn@latest add @haze/scroll-areaFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | Scrollable content | Accessible name for the scroll region. |
| direction | "vertical" | "horizontal" | "both" | vertical | Axes on which the content can overflow. |
| fade | boolean | false | Fades overflowed edges when scrolled away from a boundary. |
| scrollbarGutter | boolean | true | Reserves space for vertical scrollbars to prevent layout shift. |
| class | string | – | Classes for the region, including an optional height limit. |
Keyboard interactions
- Tab
- Focus the scroll region.
- Arrow keysPage UpPage Down
- Scroll the focused region.
Accessibility
- The region is named and its scrollbar is native.
- Keyboard scrolling works while focus is inside the region.
- Edge fade masks update progressively via script and never trap clicks or content.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Scroll Area" with `npx shadcn@latest add @haze/scroll-area`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ScrollArea from "@/components/haze/ui/scroll-area.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/scroll-area.md
Customize with real content
Adapt the Haze scroll-area ui for our product. Replace the demo values of these props with our real content: label, direction, fade, scrollbarGutter, class. Keep the layout, the heading level rules and these accessibility details: The region is named and its scrollbar is native. Keyboard scrolling works while focus is inside the region. Edge fade masks update progressively via script and never trap clicks or content. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using scroll-area, check it fits: use it when one panel contains a long list or log with a bounded height.; horizontal tag strips or vertical sidebars need subtle scroll edge cues.. Avoid it when the content can use normal page scrolling without obscuring nearby controls.. Alternatives: @haze/card, @haze/scroll-progress, @haze/carousel.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.