Skip to content
Focsd homeFocsd homeFocsd
Forms

Virtual list

A list of any length that renders only the rows in view; this one holds 100,000 items.

  • Tag: focsd-virtual-list
  • Pattern: List or listbox rendering only visible rows, setsize/posinset
  • Category: Data

Example

HTML
<focsd-virtual-list
id="virtual-list-demo"
class="full"
label="Products"
item-height="36"
style="block-size: 16rem"></focsd-virtual-list>
<script type="module">
const list = document.getElementById('virtual-list-demo');
// The data: 100,000 rows. Each shows as text; set renderItem for richer rows.
list.items = Array.from({ length: 100000 }, (_, i) => 'Product ' + (i + 1));
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-virtual-list.js';
</script>
<focsd-virtual-list class="full" label="Products" item-height="36"></focsd-virtual-list>

API

Attributes

AttributePropertyTypeDefault
item-heightitemHeightnumber | undefined—
overscanoverscannumber5
labellabelstring—
selectableselectable'none' | 'single' | 'multiple'none

Methods

MethodDescription
scrollToIndex(index, { align = 'nearest' }, options)Scroll so row index is visible (align: start, center, end or nearest).

Events

EventDescription
changeFired when the selection changes.

CSS parts

Style the inside of the component with ::part(), for example focsd-virtual-list::part(viewport).

PartDescription
viewportThe scrolling area (the list or listbox).
spacerThe full-height content.
windowThe rendered rows, positioned at their offset.
rowA row.

Accessibility

  • Rows carry aria-setsize and aria-posinset, so screen readers announce "item 4,051 of 100,000".
  • The scrolling area is focusable, so keyboard users can scroll it.
  • With selectable="single" or "multiple" it is an APG listbox with aria-activedescendant, Shift ranges and Ctrl/⌘ + A.
  • Rows that grow above the view (images loading) keep what you are reading in place.

Keyboard

KeyAction
Arrow Up / DownMove the active row (listbox); with selectable="single" the row is also selected
Home / EndFirst / last row (listbox)
Page Up / Page DownMove by a page (listbox), or scroll
Space / EnterToggle the active row (listbox)
Shift + Arrow Up / Down, Home, End, Page Up / DownExtend the selection (multiple)
Ctrl / ⌘ + ASelect all, or clear when all are selected (multiple)