datui
Color scheme

Layout

HorizontalScroll

A horizontal strip that scrolls natively and adds prev/next arrows for pointer users. Arrows hide at the start and end.

import { HorizontalScroll } from "datui";

Examples

Basic

Arrows page by one viewport width.

Custom step and wheel

getScrollToNext/getScrollToPrev choose the target offset; scrollOnAnyWheel maps the vertical wheel.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Accessibility

  • Content scrolls natively: touch, trackpad, Shift+wheel, and arrow keys once the viewport has focus.
  • The viewport gets tabIndex=0 only while its content overflows, so keyboard users can reach and scroll it.
  • Arrow buttons are aria-hidden and out of the tab order; they duplicate native scrolling for pointer users.
  • Arrows follow DirectionProvider: in RTL the previous arrow sits on the right and points right.
  • Under prefers-reduced-motion arrow clicks scroll instantly instead of smoothly.

API

HorizontalScroll

Horizontal strip that scrolls natively (touch, trackpad, Shift+wheel, keyboard on the focusable viewport) and adds prev/next arrows for pointer users. Arrows hide at the start/end.

PropTypeDefaultDescription
arrowOffsetXstring | number0Distance of the arrows from the inline edges (CSS length or px).
arrowOffsetYstring | number0Vertical shift of the arrows from the center (CSS length or px).
arrowSize"s" | "m"m
classNamestring—
contentAsElementType<any, keyof IntrinsicElements>divElement rendered inside the viewport around the children, e.g. `"ul"`.
contentClassNamestring—
getScrollToNextHorizontalScrollSteppageStep(1)Target offset for the "next" arrow. Defaults to one viewport width forward.
getScrollToPrevHorizontalScrollSteppageStep(-1)Target offset for the "previous" arrow. Defaults to one viewport width back.
scrollOnAnyWheelbooleanfalseMap vertical mouse-wheel movement to horizontal scrolling. Shift+wheel always works natively.
showArrowsboolean | "always"true`true` shows arrows on devices with a fine pointer, `"always"` on every device.
viewportClassNamestring—Classes for the scrolling viewport element.
viewportRefRef<HTMLDivElement>—Ref to the scrolling viewport element.