Skip to content
v2.5.0
English
Русский
Documentation

IndexedSnapScroller

IndexedSnapScroller is a compound component built on SnapScroller for virtualized, index-windowed paging.

Root Props

PropTypeDefault
startnumber-2
Starting index used to generate the initial sequence of pages. Acts as the logical origin for the sliding index window.
startDir-1 | 11
Direction in which the initial index sequence expands. 1 — indexes increase to the right (0, 1, 2…); -1 — indexes decrease to the right (0, -1, -2…). Controls the growth pattern of the initial index array.
sizenumber5
Number of index segments rendered at once. Defines the size of the virtual “window” that the scroller slides over when navigating left or right.
shiftnumber2
Number of pages appended when a scroll reaches the end of the window, so a fast swipe keeps going. Once the scroll settles, the window is re-centered on the snapped page.
indexnumber—
Controls the currently active logical index. When provided, the scroller keeps the given index in view, scrolling to it if possible or rebuilding the window if needed.
preserveScrollbooleantrue
Preserve the currently snapped item after content changes (e.g., when pages are prepended/appended). If true, the scroller will restore the same snapped index using an immediate scrollIntoView.
apiRefRef<IndexedSnapScrollerApiRef>—
Exposes the imperative API of the scroller. Allows programmatic control such as scrolling to an index or resetting the virtual window.
onOffset(value: number) => void—
Fires when the window grows at an edge. -1 — the scroll settled on the first page (left/top edge); +1 — the scroll reached the end (right/bottom edge). Useful for infinite loading: append/prepend pages based on the direction.
refRef<HTMLDivElement>—
Ref to the scroller’s element.
defaultIndexnumber—
Initial index of the item to snap to on mount.
onScrollSnapChange(element: HTMLElement, index: number) => void—
Fired when a scroll snap operation has fully completed and the scroller has settled on a new snap index. This callback is invoked after all scrolling and snapping animations have finished and the active snap position is considered stable.
onScrollSnapChanging(element: HTMLElement, index: number) => void—
Fired while a scroll snap operation is in progress and the active snap index is still changing. This callback may be invoked multiple times during a single scroll or swipe interaction as the scroller approaches its final snap position. Useful for optimistic UI updates, previews, or synchronizing transient state during scrolling.

Also accepts all <div> attributes.

Child Parts

  • IndexedSnapScrollerContent: content template bound to the current virtual index.

IndexedSnapScrollerContent

PropTypeDefault
refRef<HTMLDivElement>—
External ref to the item's root element. Will be merged with internal itemRef(index) to participate in snapping logic.
asChildboolean—
Render the content as a child (via Slot) instead of a native <div>. Keeps attributes/refs bound to the passed child element.

Also accepts all <div> attributes.

Types

  • IndexedSnapScrollerProps
  • IndexedSnapScrollerContentProps
  • IndexedSnapScrollerApiRef

State Model

  • The root manages a sliding window of logical indexes.
  • Controlled index can either scroll to an existing item or trigger a window reset.
  • While a scroll reaches the end, pages are appended so it can keep going; once the scroll settles, the window is re-centered on the snapped page.
  • next() / prev() count from the page the scroll is already heading to and grow the window first when the target is outside it.