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.
Accessibility
- Content scrolls natively: touch, trackpad, Shift+wheel, and arrow keys once the viewport has focus.
- The viewport gets
tabIndex=0only while its content overflows, so keyboard users can reach and scroll it. - Arrow buttons are
aria-hiddenand 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-motionarrow 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.
| Prop | Type | Default | Description |
|---|---|---|---|
| arrowOffsetX | string | number | 0 | Distance of the arrows from the inline edges (CSS length or px). |
| arrowOffsetY | string | number | 0 | Vertical shift of the arrows from the center (CSS length or px). |
| arrowSize | "s" | "m" | m | |
| className | string | — | |
| contentAs | ElementType<any, keyof IntrinsicElements> | div | Element rendered inside the viewport around the children, e.g. `"ul"`. |
| contentClassName | string | — | |
| getScrollToNext | HorizontalScrollStep | pageStep(1) | Target offset for the "next" arrow. Defaults to one viewport width forward. |
| getScrollToPrev | HorizontalScrollStep | pageStep(-1) | Target offset for the "previous" arrow. Defaults to one viewport width back. |
| scrollOnAnyWheel | boolean | false | Map vertical mouse-wheel movement to horizontal scrolling. Shift+wheel always works natively. |
| showArrows | boolean | "always" | true | `true` shows arrows on devices with a fine pointer, `"always"` on every device. |
| viewportClassName | string | — | Classes for the scrolling viewport element. |
| viewportRef | Ref<HTMLDivElement> | — | Ref to the scrolling viewport element. |