Scroll Area
A native scroll container with Dify overlay scrollbars.
Recent activity
Usage guidelines
- Use
ScrollAreafor a fixed-size panel, list or code block whose content can overflow. Let the page itself scroll natively. ScrollAreaViewportis the element that scrolls and takes focus. Put scroll refs,onScroll,role, the accessible name and overscroll behavior on the viewport, not on the root.- The viewport becomes a
Tabstop whenever its content overflows, so name what it scrolls: addrole="region"witharia-labelledbypointing at a visible title, otherwise witharia-label. - Wrap the content in
ScrollAreaContent. It keeps the scrollbars in sync when the content changes size. - Base UI sets the viewport's
overflowand the content'smin-widthinline. Override them withstyle, such asstyle={{ minWidth: 0 }}onScrollAreaContentso a vertical list truncates long text;min-w-0andoverflow-*utilities do not apply. - Render one
ScrollAreaScrollbarper scrolling axis. AddScrollAreaCornerwhen both axes scroll. ScrollAreaScrollbarstays hidden at rest and reveals while hovering the scroll area, scrolling, or keyboard-focusing the viewport. OverrideclassNamewithpointer-events-auto opacity-100if a surface requires a persistent scrollbar.
Anatomy
The root draws the focus ring above the content when the viewport has keyboard focus, so the ring is not clipped or masked by the scrolling content.
Examples
Truncating a vertical list
style={{ minWidth: 0 }} on ScrollAreaContent lets long file names truncate instead of adding a horizontal scroll.
Horizontal
Set orientation="horizontal" on the scrollbar for a row that overflows sideways.
Scroll fade
The viewport exposes --scroll-area-overflow-y-start and --scroll-area-overflow-y-end. Use them in a mask so the edges fade only when there is more content in that direction, and give each var() a fallback so the mask is valid before hydration.
Both axes
Render a vertical and a horizontal ScrollAreaScrollbar together with ScrollAreaCorner when content overflows in both directions, such as a wide log table.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the viewport when its content overflows. The root draws the focus ring and reveals the scrollbar. |
| Down arroworUp arrow | Scrolls the focused viewport down or up. |
| Right arroworLeft arrow | Scrolls the focused viewport right or left. |
| PageDownorPageUp | Scrolls down or up by about one viewport height. |
| SpaceorShift+Space | Scrolls down or up by about one viewport height. |
| HomeorEnd | Scrolls to the top or bottom. |
API reference
ScrollArea
Groups a scrollable viewport with custom overlay scrollbars. Renders a <div> element.
ScrollAreaViewport owns scroll refs, events, and focus; use inline style to override Base UI's inline overflow on Viewport or minWidth on Content.
| Prop | Type | Default | Details |
|---|---|---|---|
style | React.CSSProperties | ((state: ScrollAreaRootState) => React.CSSProperties | undefined) | No default | |
overflowEdgeThreshold | number | Partial<{ xStart: number; xEnd: number; yStart: number; yEnd: number; }> | 0 | |
className | string | ((state: ScrollAreaRootState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ScrollAreaRootState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
| Attribute | Description |
|---|---|
data-scrolling | Present when the user scrolls inside the scroll area. |
data-has-overflow-x | Present when the scroll area content is wider than the viewport. |
data-has-overflow-y | Present when the scroll area content is taller than the viewport. |
data-overflow-x-start | Present when there is overflow on the horizontal start side. |
data-overflow-x-end | Present when there is overflow on the horizontal end side. |
data-overflow-y-start | Present when there is overflow on the vertical start side. |
data-overflow-y-end | Present when there is overflow on the vertical end side. |
| Variable | Description |
|---|---|
--scroll-area-corner-height | Values: The scroll area's corner height. |
--scroll-area-corner-width | Values: The scroll area's corner width. |
ScrollAreaContent
A container for the content of the scroll area. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: ScrollAreaContentState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ScrollAreaContentState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ScrollAreaContentState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-scrolling | Present when the user scrolls inside the scroll area. |
data-has-overflow-x | Present when the scroll area content is wider than the viewport. |
data-has-overflow-y | Present when the scroll area content is taller than the viewport. |
data-overflow-x-start | Present when there is overflow on the horizontal start side. |
data-overflow-x-end | Present when there is overflow on the horizontal end side. |
data-overflow-y-start | Present when there is overflow on the vertical start side. |
data-overflow-y-end | Present when there is overflow on the vertical end side. |
ScrollAreaCorner
A small rectangular area that appears at the intersection of horizontal and vertical scrollbars. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: ScrollAreaCornerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ScrollAreaCornerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ScrollAreaCornerState) => React.CSSProperties | undefined) | No default | |
ScrollAreaScrollbar
Overlay scrollbar track that reveals while hovering the scroll area, scrolling, or keyboard-focusing the viewport. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'vertical' | |
keepMounted | boolean | false | |
className | string | ((state: ScrollAreaScrollbarState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ScrollAreaScrollbarState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ScrollAreaScrollbarState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-orientation | Values: Indicates the orientation of the scrollbar. |
data-hovering | Present when the pointer is over the scroll area. |
data-scrolling | Present when the user scrolls inside the scroll area. |
data-has-overflow-x | Present when the scroll area content is wider than the viewport. |
data-has-overflow-y | Present when the scroll area content is taller than the viewport. |
data-overflow-x-start | Present when there is overflow on the horizontal start side. |
data-overflow-x-end | Present when there is overflow on the horizontal end side. |
data-overflow-y-start | Present when there is overflow on the vertical start side. |
data-overflow-y-end | Present when there is overflow on the vertical end side. |
| Variable | Description |
|---|---|
--scroll-area-thumb-height | Values: The scroll area thumb's height. |
--scroll-area-thumb-width | Values: The scroll area thumb's width. |
ScrollAreaThumb
The draggable part of the scrollbar that indicates the current scroll position. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: ScrollAreaThumbState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ScrollAreaThumbState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ScrollAreaThumbState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-orientation | Values: Indicates the orientation of the scrollbar. |
data-scrolling | Present when the user scrolls inside the scroll area. |
ScrollAreaViewport
The actual scrollable container of the scroll area. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: ScrollAreaViewportState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ScrollAreaViewportState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ScrollAreaViewportState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-scrolling | Present when the user scrolls inside the scroll area. |
data-has-overflow-x | Present when the scroll area content is wider than the viewport. |
data-has-overflow-y | Present when the scroll area content is taller than the viewport. |
data-overflow-x-start | Present when there is overflow on the horizontal start side. |
data-overflow-x-end | Present when there is overflow on the horizontal end side. |
data-overflow-y-start | Present when there is overflow on the vertical start side. |
data-overflow-y-end | Present when there is overflow on the vertical end side. |
| Variable | Description |
|---|---|
--scroll-area-overflow-x-start | Values: The distance from the horizontal start edge in pixels. |
--scroll-area-overflow-x-end | Values: The distance from the horizontal end edge in pixels. |
--scroll-area-overflow-y-start | Values: The distance from the vertical start edge in pixels. |
--scroll-area-overflow-y-end | Values: The distance from the vertical end edge in pixels. |