Skip to main content

Scroll Area

A native scroll container with custom scrollbars.

Features

Installation

typo3 ui:add scroll-area

Read more about installing Components and Primitives.

Examples

Horizontal Scroll

Enable horizontal scrolling for wide content.

Both Directions

Support scrolling in both vertical and horizontal directions.

API Reference

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

scrollArea.root

Provides the scroll area container and shared state. Renders a <div> element.

Rendered data attributes

AttributeDescription
data-scopescroll-area
data-partroot
data-overflow-xPresent when the content overflows the x-axis
data-overflow-yPresent when the content overflows the y-axis

scrollArea.viewport

Provides the native scrollable viewport. Renders a <div> element.

Rendered data attributes

AttributeDescription
data-scopescroll-area
data-partviewport
data-at-topPresent when scrolled to the top edge
data-at-bottomPresent when scrolled to the bottom edge
data-at-leftPresent when scrolled to the left edge
data-at-rightPresent when scrolled to the right edge
data-overflow-xPresent when the content overflows the x-axis
data-overflow-yPresent when the content overflows the y-axis

scrollArea.content

Wraps the scrollable content to measure its size. Renders a <div> element.

Rendered data attributes

AttributeDescription
data-scopescroll-area
data-partcontent
data-overflow-xPresent when the content overflows the x-axis
data-overflow-yPresent when the content overflows the y-axis

scrollArea.scrollbar

Displays a custom scrollbar track. Renders a <div> element.

NameDescriptionRequiredDefault
orientationEnum\Orientation
The orientation of the scrollbar.
No
Vertical

Rendered data attributes

AttributeDescription
data-scopescroll-area
data-partscrollbar
data-orientationThe orientation of the scrollbar
data-scrollingPresent when scrolling
data-hoverPresent when hovered
data-draggingPresent when in the dragging state
data-overflow-xPresent when the content overflows the x-axis
data-overflow-yPresent when the content overflows the y-axis

scrollArea.thumb

Displays the draggable scrollbar thumb. Renders a <div> element.

Rendered data attributes

AttributeDescription
data-scopescroll-area
data-partthumb
data-orientationThe orientation of the thumb
data-hoverPresent when hovered
data-draggingPresent when in the dragging state

Machine JavaScript API

NameTypeDescription
isAtTopbooleanWhether the scroll area is at the top
isAtBottombooleanWhether the scroll area is at the bottom
isAtLeftbooleanWhether the scroll area is at the left
isAtRightbooleanWhether the scroll area is at the right
hasOverflowXbooleanWhether the scroll area has horizontal overflow
hasOverflowYbooleanWhether the scroll area has vertical overflow
getScrollProgress() => PointGet the scroll progress as values between 0 and 1
scrollToEdge(details: ScrollToEdgeDetails) => voidScroll to the edge of the scroll area
scrollTo(details: ScrollToDetails) => voidScroll to specific coordinates
getScrollbarState(props: ScrollbarProps) => ScrollbarStateReturns the state of the scrollbar

Anatomy

<primitives:scrollArea.root>
    <primitives:scrollArea.viewport>
        <primitives:scrollArea.content />
    </primitives:scrollArea.viewport>
    <primitives:scrollArea.scrollbar>
        <primitives:scrollArea.thumb />
    </primitives:scrollArea.scrollbar>
</primitives:scrollArea.root>