Virtual list
A list of thousands of rows that keeps only the rows in view in the page, so it scrolls as smoothly at 100,000 rows as at 100. Rows can share one height or be measured, and a heading can pin each group to the top. For a few hundred rows a plain list or a paginated table is simpler.
Install
npx shadcn@latest add @thrum-pro/virtual-listThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
type VirtualListItem = {
id: string;
label: string;
description?: string;
meta?: string;
group?: string;
};const contacts: VirtualListItem[] = [
{ id: "c1", label: "Ada Abbott", meta: "#1", group: "A" },
{ id: "c2", label: "Ada Baker", description: "Prefers email.", meta: "#2", group: "A" },
{ id: "c3", label: "Ben Chen", meta: "#3", group: "B" },
];Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | readonly VirtualListItem[] | Required | Every item. Only those in view, plus the overscan and the focused row, are in the page. |
aria-label | string | – | The list's name. Or point aria-labelledby at a visible heading. |
rowHeight | number | Default 40 | The height of a row in pixels. With measure it is the first guess and the smallest height. |
measure | boolean | Default false | Rows differ in height: each one is measured once drawn, and the list corrects its guesses as you scroll. |
overscan | number | Default 6 | Rows drawn beyond each edge of the view, so a fast scroll does not show a gap. |
stickyGroups | boolean | Default false | Start each run of one group with a heading, and pin the current group's heading to the top. |
value | string | null | – | The selected id, when the parent holds it. |
defaultValue | string | null | Default null | The id selected at first, when the list holds it itself. |
onValueChange | (id: string) => void | – | Called with the id of the row picked by a click, Enter or Space. |
scrollToIndex | number | – | Scroll so this item, counted from 0, is at the top, with its heading. It scrolls again whenever the number changes. |
onRangeChange | (range: { start: number; end: number; rendered: number }) => void | – | Called when the drawn rows change: the first and last item drawn, and how many item rows are in the page. |
emptyLabel | string | Default "No items" | Shown when there are no items. |
sound | boolean | Default true | Play a click when a row is picked, if the visitor has sound on. |
className | string | – | Classes for the frame. Set the height here: the default is h-80, 320 pixels. |
layoutRows(), rowAt(), visibleRange() | functions | – | More exports: the offsets of rows from their heights, the row under a point, and the rows to draw for a view. |
Motion and sound
Motion
- Nothing animates: the rows move with the scroll and nothing else.
- A row's shade changes at once under the pointer.
Sound
- A click when a different row is picked.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- It follows the WAI-ARIA listbox pattern: the scrolling box is the listbox and holds the focus; aria-activedescendant points at the outlined row.
- Every drawn row carries aria-setsize with the whole length and aria-posinset with its place, so a screen reader says 4,213 of 10,000 although only a few rows exist.
- The outlined row stays in the page even after it scrolls far out of view, so the active descendant always exists.
- The selected row is shaded, set in medium weight and marked by a bar at its start, and carries aria-selected.
- Group headings are drawn for the eye and hidden from screen readers; each row says its group at the end of its name instead.
- The list frame is a panel surface (data-surface="panel"): under a glass material it becomes translucent while keeping row text and group headings readable.
| Keys | Action |
|---|---|
| Tab | Focus the list. The row last moved to is outlined. |
| ↓ / ↑ | Move to the next or previous row, scrolling just enough to show it. |
| Page Down / Page Up | Move by one view's worth of rows. |
| Home / End | Move to the first or the last row, 10,000 rows away or more. |
| Enter / Space | Pick the outlined row. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/virtual-list.tsx- Packages
- None
- Brings along
- Sound engine
Changelog
- 1.0.0 · 2026-12-03First release.