Virtual List
A windowed vertical list for large, fixed-height collections. Native scrolling keeps the expected scrollbar and input behavior while Puzzle mounts only the visible rows plus a small overscan cushion; caller-owned snippets provide the row design.
Build 00001
release/0.7.0
Build 00002
feat/snippets
Build 00003
feat/virtual-list
Build 00004
docs/pieces
Build 00005
release/0.7.0
Build 00006
feat/snippets
Build 00007
feat/virtual-list
Build 00008
docs/pieces
Build 00009
release/0.7.0
Build 00010
feat/snippets
Build 00011
feat/virtual-list
Build 00012
docs/pieces
Build 00013
release/0.7.0
Build 00014
feat/snippets
Build 00015
feat/virtual-list
Build 00016
docs/pieces
Build 00017
release/0.7.0
Build 00018
feat/snippets
Build 00019
feat/virtual-list
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece virtual-list
Virtual List has no registry or npm dependencies. It uses the pieces.css surface, border, text, and focus tokens.
Usage
import VirtualList from '@/components/ui/VirtualList.pzl';
<VirtualList items={ items } rowHeight={ 48 } height={ 400 } itemKey="id">
<Snippet fits="row" item index>
<div class="flex h-full items-center">{ index + 1 }. { item.label }</div>
</Snippet>
</VirtualList>Windowing model
The scroll viewport renders the rows it can show plus overscan rows on both sides (five by default). Top and bottom spacers reserve everything outside that window, so the scrollbar still represents the full collection. The row snippet receives the original item and its absolute array index.
// Default overscan is five rows above and below. itemKey names the
// stable item field used by keyed row wrappers; id/key/index are the fallbacks.
<VirtualList items={ results } rowHeight={ 44 } height={ 352 }
overscan={ 5 } itemKey="uuid" label="Search results">
<Snippet fits="row" item index>{ item.title }</Snippet>
</VirtualList>Sizing and the fixed-height limit
rowHeight is required and every caller row must fit it. Use height for a fixed viewport, or maxHeight by itself when a short list should shrink. Dynamic/measured row heights are deliberately out of scope in v1: they need a measurement cache and scroll-anchor correction that this small, predictable piece does not pretend to provide.
// Fixed viewport: always 480px tall.
<VirtualList items={ rows } rowHeight={ 48 } height={ 480 } />
// Capped viewport: short lists shrink; long lists scroll at 480px.
<VirtualList items={ rows } rowHeight={ 48 } maxHeight={ 480 } />
// v1 deliberately does not measure variable-height content.Accessibility
- The focusable scroll viewport carries
role="list"and a meaningful label, so keyboard users can focus and scroll it as one named region. - Mounted rows use
role="listitem"witharia-setsizeandaria-posinset, exposing each virtual row's position in the full collection. Spacer geometry is hidden from assistive tech. - The snippet owns interactive controls inside a row. Give those controls their usual native semantics and accessible names; Virtual List does not impose selection or roving focus.