vael-ui v0.5.7

Positioning & data

useVirtualizer

Renders only the visible rows of a long list, so the DOM stays small. Use it for your own long lists.

Renders only the visible rows of a long list, plus a few extra rows past each edge (overscan). Select, Combobox and DataTable use it for large lists. Use it to do the same for a scrolling list of your own.

Install

import { useVirtualizer } from 'vael-ui'

Examples

Parameters

NameTypeDescription
containerElRef<HTMLElement | null>The scroll container.
countMaybeRefOrGetter<number>The total number of rows.
itemSizeMaybeRefOrGetter<number | undefined>The row size in px. Omit it to measure the first rendered row, with a 36 px estimate until then.
overscanMaybeRefOrGetter<number>The extra rows rendered past each edge. Default 8.
onReachEnd() => voidFires once when the rendered window's last index reaches count - 1 - overscan. Fires again after count changes.

Returns

NameTypeDescription
listStyleRef<Record<string, string>>Gives the container its full scroll height. Bind it to a relatively positioned spacer inside the container.
itemsReadonly<Ref<VirtualRow[]>>The rows to render now: { index, start, size, style }.
scrollToIndex(index, align?: 'nearest' | 'start' | 'end' | 'center') => voidScrolls a row into view. Default 'nearest', which suits keyboard navigation: it doesn't scroll when the row is already visible.
measuredSizeReadonly<Ref<number | null>>The resolved row size.