Import
Basic Usage
Key Features
- Custom Scrollbars: Full control over scrollbar appearance and behavior.
- Cross-Browser: Consistent scrolling experience across all browsers.
- Overflow Detection: Track scroll position and overflow edges with state attributes.
- Touch Support: Optimized for touch devices with proper modality detection.
- Accessibility: Keyboard navigation and focus management built-in.
- Hover States: Automatically tracks when the scroll area is hovered.
- Overflow Edge Threshold: Configure when overflow edge indicators appear.
Components
ScrollArea.Root
The root container for the scroll area. Renders a<div> element.
Props:
overflowEdgeThreshold- Threshold in pixels before overflow edge attributes are applied (default:0). Can be a number or an object withxStart,xEnd,yStart,yEndproperties.
data-scrolling- Present when scrolling is activedata-overflow-x-start- Overflow detected at horizontal startdata-overflow-x-end- Overflow detected at horizontal enddata-overflow-y-start- Overflow detected at vertical startdata-overflow-y-end- Overflow detected at vertical end
ScrollArea.Viewport
The actual scrollable container. Renders a<div> element with overflow: scroll.
State attributes:
Inherits all state attributes from ScrollArea.Root.
ScrollArea.Scrollbar
A vertical or horizontal scrollbar. Renders a<div> element.
Props:
orientation- Direction of scrolling:'vertical'or'horizontal'(default:'vertical')keepMounted- Keep scrollbar in DOM when not scrollable (default:false)
data-hovering- Present when scroll area is hovereddata-scrolling- Present when scrolling in this orientationdata-orientation- The orientation value (verticalorhorizontal)
ScrollArea.Thumb
The draggable part of the scrollbar that indicates scroll position. Renders a<div> element.
State attributes:
data-orientation- The orientation value from parent scrollbar
ScrollArea.Corner
The corner element where horizontal and vertical scrollbars meet. Renders a<div> element.
Styling Example
Overflow Edge Detection
Use overflow edge thresholds to trigger visual indicators when content can be scrolled:CSS Variables
The component provides CSS variables for dynamic styling:--scroll-area-thumb-height- Height of vertical thumb in pixels--scroll-area-thumb-width- Width of horizontal thumb in pixels--scroll-area-corner-height- Height of corner element in pixels--scroll-area-corner-width- Width of corner element in pixels--scroll-area-overflow-x-start- Distance scrolled from start (horizontal)--scroll-area-overflow-x-end- Distance remaining to end (horizontal)--scroll-area-overflow-y-start- Distance scrolled from start (vertical)--scroll-area-overflow-y-end- Distance remaining to end (vertical)