Ir al contenido
Español
Lista virtual viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

Rows and headers have fixed heights, so the offset of every row is computed once and the window is found with a binary search on each scroll frame; nothing is measured and the scrollbar never jumps. Rows are placed with translateY inside one spacer, and the scroller uses contain: strict, so scrolling 10,000 rows renders about twenty. The pinned header is a separate layer drawn over the top edge and pushed up by the next header.

Úsalo para

  • Directories, logs, transactions or any list of thousands of uniform rows.
  • Pickers that must let people scroll the whole set, not just search it.

Busca otra opción cuando

  • Rows of very different heights: use paging or an infinite list.
  • Under a few hundred rows: a plain list is simpler and supports find-in-page.

Uso

import { useState } from 'react'
import { VirtualList } from './VirtualList.jsx'

export function Directory({ people }) {
  const [picked, setPicked] = useState(null)
  return (
    <VirtualList
      label="Contacts"
      items={people}
      getKey={(p) => p.id}
      getGroup={(p) => p.name[0]}
      rowHeight={56}
      height={400}
      value={picked}
      onSelect={(p) => setPicked(p.id)}
      renderItem={(p) => <span>{p.name}</span>}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
itemsT[]—All rows, already sorted so that groups are contiguous.
renderItem(item, index, { selected, active }) => ReactNode—Renders one row at rowHeight.
getKey(item, index) => Keyitem.id ?? indexStable key; also what value compares against.
getGroup(item, index) => string—Group label; a header is inserted wherever it changes and pinned while its rows are in view.
rowHeightnumber52Fixed height of every row in px.
headerHeightnumber32Fixed height of group headers in px.
heightnumber400Height of the scroll area in px.
overscannumber6Extra rows rendered above and below the view, so fast scrolling never shows gaps.
valueKey—Key of the selected row.
onSelect(item, index) => void—Called on click, Enter or Space.
onRangeChange({ first, last, rendered }) => void—Called when the rendered window changes; useful for prefetching.
labelstring—Accessible name of the listbox.

Accesibilidad

  • The scroller is a focusable listbox; rows are options with aria-setsize and aria-posinset, so position is announced as "5,231 of 10,000".
  • Focus stays on the listbox and the active row is aria-activedescendant; that row is always kept in the DOM, even off screen.
  • Keyboard: Up / Down, PageUp / PageDown, Home / End move and scroll the row into view below the pinned header; Enter or Space selects.
  • Group headers are visual only (the pinned copy is aria-hidden). Browser find-in-page cannot see rows that are not rendered; offer search.

Movimiento

Scrolling is native. The pinned header gains a hairline over 200ms once the list leaves the top; row hover and active fills change in 120ms.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

VirtualList.jsxvirtual-list.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Listas
Carrusel en arco viene con Pro. La vista previa aparece al desbloquearlo.
Carrusel cilíndrico viene con Pro. La vista previa aparece al desbloquearlo.