No results found

Scroll Area

A customizable container that adds scrollbars when content overflows its boundaries.

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiisofficiiserrorminimaeos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.

Features

  • Custom scrollbar visibility modes (hover, scroll, auto, always)
  • Draggable thumb with smooth scroll tracking
  • Two-axis scrolling support (vertical and horizontal)
  • Overflow detection and automatic scrollbar display
  • Click-to-scroll on track functionality
  • Zoom level detection and overflow adjustment
  • WAI-ARIA compliant scrollable region
  • Scroll position memory during thumb dragging
  • Configurable scrollbar hide delay
  • Responsive to window resize events
  • Cross-browser zoom handling
  • Dynamic thumb size based on content

Anatomy

PartDescription
<ScrollArea.Root>A root component for scrollable content areas with customizable scrollbar behavior
<ScrollArea.Viewport>—
<ScrollArea.Scrollbar>A scrollbar component that can be oriented vertically or horizontally
<ScrollArea.Thumb>A draggable thumb component for the scrollbar that handles scroll position

Examples

Basic Usage

The scroll area component provides a customizable scrolling experience with different visibility modes for the scrollbars. The type prop controls when scrollbars are visible:

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.

Visual Features

Horizontal Scrolling

For content that extends beyond the horizontal bounds, use the orientation="horizontal" prop on ScrollArea.Scrollbar.

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.

Both Axes Scrolling

When content overflows in both directions, you can include both vertical and horizontal scrollbars.

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiisofficiiserrorminimaeos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.

Advanced Usage

Custom Hide Delay

For scroll-triggered visibility (type="scroll"), customize how long scrollbars remain visible after scrolling stops using the hideDelay prop (in milliseconds).

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiisofficiiserrorminimaeos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.

Note: The examples demonstrate the core functionality of the scroll area component. The hideDelay prop (default: 600ms) determines how long scrollbars remain visible after scrolling stops when using type="scroll".

Component State

The ScrollArea component offers several ways to control its scrollbar visibility and behavior through state management.

Using Component State

Scrollbar Visibility Types

The ScrollArea provides four visibility modes controlled through the type prop on ScrollArea.Root:

  1. Auto Mode Shows scrollbars when content overflows and hides them when it doesn't.

Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiisofficiiserrorminimaeos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.

  1. Always Mode Keeps scrollbars visible whenever content overflows, regardless of user interaction.
  2. Hover Mode Shows scrollbars only when the user hovers over the scroll area.
  3. Scroll Mode Displays scrollbars only during active scrolling.

Hide Delay Configuration

When using the "scroll" visibility type, you can customize how long the scrollbars remain visible after scrolling stops using the hideDelay prop:

<ScrollArea.Root type="scroll" hideDelay={1000}>
  {/* Content */}
</ScrollArea.Root>

State Interactions

Overflow Detection

The ScrollArea automatically detects content overflow and updates its state accordingly. This state is reflected through the data-has-overflow attribute on the root element.

Scrollbar State

Scrollbars expose their current visibility state through the data-state attribute, which can be either "visible" or "hidden". This state updates automatically based on:

Thumb Position

The thumb position automatically updates to reflect the current scroll position. You can programmatically control the scroll position through the viewport:

const viewport = document.querySelector('[data-qds-scroll-area-viewport]');
if (viewport) {
  viewport.scrollTop = 100; // Scroll vertically
  viewport.scrollLeft = 50; // Scroll horizontally
}

Drag State

During thumb dragging, the thumb element receives a data-dragging attribute that can be used for styling:

[data-qds-scroll-area-thumb][data-dragging] {
  /* Styles for dragging state */
}

The ScrollArea maintains the scroll position relative to the drag position, ensuring smooth scrolling even when the cursor moves outside the scrollbar bounds.

Based on the provided implementation and examples, I'll document the ScrollArea configuration options:

Scrollbar Visibility

Core Behavior

The ScrollArea component supports four visibility modes controlled by the type prop on ScrollArea.Root:

Hide Delay

For the scroll type, you can customize how long scrollbars remain visible after scrolling stops using the hideDelay prop:

type ScrollAreaRootProps = {
  hideDelay?: number; // milliseconds, defaults to 600
}

As shown in the custom-delay-test example above, this allows fine-tuning of the scrollbar fade-out timing.

Scrollbar Configuration

Orientation Support

ScrollArea supports both vertical and horizontal scrollbars through the orientation prop on ScrollArea.Scrollbar:

type ScrollbarOrientation = "vertical" | "horizontal";

As shown in the both example above, you can include both orientations simultaneously for content that overflows in both directions.

Technical Constraints

Performance Considerations

The ScrollArea implements several optimizations:

API Reference

Scroll Area Thumb

Inherits from: <div />

Props

PropTypeDefaultDescription
refSignal<HTMLDivElement | undefined>-
onDragStart$PropFunction<(e: MouseEvent) => void>-
onDragMove$PropFunction<(e: MouseEvent) => void>-
onDragEnd$PropFunction<() => void>-

Data Attributes

AttributeDescription
data-draggingIndicates whether the thumb is currently being dragged

Scroll Area Scrollbar

Inherits from: <div />

Props

PropTypeDefaultDescription
orientation"vertical" | "horizontal""vertical"
onScroll$QRL<(e: Event) => void>-

Data Attributes

AttributeDescription
data-orientation
data-stateIndicates the visibility state of the scrollbar (visible or hidden)

Scroll Area Root

Inherits from: <div />

Data Attributes

AttributeDescription
data-typeDefines the scrollbar visibility behavior (hover, scroll, auto, or always)
data-has-overflowIndicates whether the content exceeds the viewport dimensions

Scroll Area View Port

Inherits from: <div />

Props

PropTypeDefaultDescription
onScroll$PropFunction<(e: Event) => void>-

Accessibility

Keyboard Interactions

KeyDescription
ArrowDownScrolls the viewport content vertically downward when focus is on the viewport
ArrowUpScrolls the viewport content vertically upward when focus is on the viewport
ArrowRightScrolls the viewport content horizontally to the right when focus is on the viewport
ArrowLeftScrolls the viewport content horizontally to the left when focus is on the viewport
PageDownScrolls the viewport content down by a larger increment when focus is on the viewport
PageUpScrolls the viewport content up by a larger increment when focus is on the viewport
HomeScrolls to the top of the viewport content when focus is on the viewport
EndScrolls to the bottom of the viewport content when focus is on the viewport
Ctrl/Cmd + 0Triggers overflow check when zooming to default level
Ctrl/Cmd + +/=Triggers overflow check when zooming in
Ctrl/Cmd + -Triggers overflow check when zooming out