Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

VirtualList

A high-performance list that recycles item views and renders only visible rows.

When To Use It

Use VirtualList for large datasets where creating a view for every item would be expensive. It is ideal for logs, long search results, large tables-of-content, and file lists.

Constructing a VirtualList

VirtualList::new takes a list source, fixed item height, and item builder.

let rows = Signal::new((0..10_000).collect::<Vec<usize>>());

VirtualList::new(cx, rows, 28.0, |cx, index, item| {
	Label::new(cx, item.map(|value| format!("Row {}: {}", index, value)))
})
.selectable(Selectable::Single)
.on_select(|cx, index| cx.emit(AppEvent::SelectRow(index)));

For custom data sources, use new_generic with explicit length/index accessors.

VirtualList Modifiers

ModifierTypeDescriptionDefault
selectionimpl Res<[usize]>Sets selected indices from external state.no selection
on_selectFn(&mut EventContext, usize)Called when an item is selected.-
selectableimpl Res<Selectable>Enables None, Single, or Multi selection.Selectable::None
selection_follows_focusimpl Res<bool>Select focused item during keyboard navigation.false
scroll_to_cursorboolScrollbar jumps to pointer when pressed.true
on_scrollFn(&mut EventContext, f32, f32)Called when list scroll position changes.-
scroll_ximpl Res<f32>Sets horizontal scroll position.0.0
scroll_yimpl Res<f32>Sets vertical scroll position.0.0
show_horizontal_scrollbarimpl Res<bool>Controls horizontal scrollbar visibility.false
show_vertical_scrollbarimpl Res<bool>Controls vertical scrollbar visibility.true

Components and Styling

SelectorDescription
virtual-listRoot element.
virtual-list.selectableApplied when selection is enabled.
virtual-list list-itemRecycled list item elements.
virtual-list list-item.focusedFocused item state.
virtual-list list-item:checkedSelected item state.

VirtualList uses a ScrollView internally and absolute positioning for visible rows.

Accessibility

VirtualList uses role List and row items use list-item semantics.

Keyboard interaction:

KeyAction
ArrowDown / ArrowUpMove focused item
Space / EnterSelect focused item

For horizontal virtualized lists, use custom key handling in your container logic.