Searching Puzzle Pieces

Type to search Puzzle Pieces.

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.

#1

Build 00001

release/0.7.0

Passed
#2

Build 00002

feat/snippets

Running
#3

Build 00003

feat/virtual-list

Queued
#4

Build 00004

docs/pieces

Failed
#5

Build 00005

release/0.7.0

Passed
#6

Build 00006

feat/snippets

Running
#7

Build 00007

feat/virtual-list

Queued
#8

Build 00008

docs/pieces

Failed
#9

Build 00009

release/0.7.0

Passed
#10

Build 00010

feat/snippets

Running
#11

Build 00011

feat/virtual-list

Queued
#12

Build 00012

docs/pieces

Failed
#13

Build 00013

release/0.7.0

Passed
#14

Build 00014

feat/snippets

Running
#15

Build 00015

feat/virtual-list

Queued
#16

Build 00016

docs/pieces

Failed
#17

Build 00017

release/0.7.0

Passed
#18

Build 00018

feat/snippets

Running
#19

Build 00019

feat/virtual-list

Queued

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" with aria-setsize and aria-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.