Skip to Content
CodeUI

VirtualizedListbox

@codeui/solid v0.3.0

A scrolling list that mounts only visible options and nearby rows.

When to use

Use VirtualizedListbox for hundreds of visible choices in a fixed-height scrolling area.

When to choose another component

Use Listbox for a short collection or sections. Use Combobox when typing is the main way to find an option.

Live demo

Selected: None

virtualized-listbox/basic.tsx
import "./layout.css";
import { VirtualizedListbox } from "@codeui/solid";
import { createSignal } from "solid-js";
const topics = ["Authentication", "Cache", "Database", "Export", "File upload", "GraphQL", "HTTP", "Image resize", "JSON", "Keyboard"];
const operations = ["validation", "retry", "timeout", "pagination", "serialization", "logging", "streaming", "cancellation", "error handling", "configuration"];
const languages = ["TypeScript", "Rust", "Python", "Go", "Kotlin"];
const snippets = languages.flatMap(language => topics.flatMap(topic => operations.map(operation => ({
	value: `${language}-${topic}-${operation}`,
	label: `${language}: ${topic} ${operation}`,
}))));
export default function Basic() {
	const [selected, setSelected] = createSignal(new Set<string>());
	return <div><VirtualizedListbox aria-label="500 code snippets" options={snippets} selectionMode="single" value={selected()} onChange={setSelected} size="sm" virtualizerOptions={{ overscan: 8 }} class="virtualized-demo" classes={{ itemLabel: "snippet-title" }} /><p>Selected: {Array.from(selected()).join(", ") || "None"}</p></div>;
}

This collection contains 500 snippet records across five languages, ten topics, and ten operations. Only the visible rows and overscan rows mount. The root class supplies a fixed height and overflow: auto. Without a bounded scroll container, virtualization cannot limit the visible window.

Use @codeui/solid/virtualized-listbox when the control needs to render only the visible options. To customize option markup in a non-virtualized list, see Listbox parts.

Anatomy

Tap a part to outline it in the demo.

  1. 01VirtualizedListboxlistboxclasses.root
  2. 02ListboxItemlistbox-itemclasses.item
  3. 03Item labellistbox-item-labelclasses.itemLabel
  4. 04Item indicatorlistbox-item-indicatorclasses.itemIndicator
ExportRendersclasses keydata-cuiRole
VirtualizedListboxulrootlistboxlistbox
Internal spacerPositioned divnonenoneScroll geometry
Internal ListboxItemPositioned liitemlistbox-itemoption
Internal labeldivitemLabellistbox-item-labelLabel text
Internal indicatordivitemIndicatorlistbox-item-indicatorSelection check

Variants

xs

sm

md

virtualized-listbox/sizes.tsx
import "./layout.css";
import { VirtualizedListbox } from "@codeui/solid";
import { For } from "solid-js";
const options = ["JetBrains Mono", "Fira Code", "Source Code Pro"].map(label => ({ value: label, label, disabled: label === "Source Code Pro" }));
export default function Sizes() {
	return <For each={["xs", "sm", "md"] as const}>{size => <div><p>{size}</p><VirtualizedListbox class="virtualized-demo" aria-label={`${size} fonts`} options={options} size={size} selectionMode="multiple" defaultValue={["Fira Code"]} /></div>}</For>;
}

Rows use the shared sm height (32px compact, 36px comfortable, 40px touch). The virtualizer measures that height for its default estimate. virtualizerOptions.estimateSize overrides the estimate. Keep labels on one line and match estimates to rendered row height. overscan defaults to five rows. Smooth scrolling is unsupported.

States

The size gallery includes multiple selection, an initial selection, and a disabled font. The main demo uses controlled single selection. Selection uses string keys in a set, as it does in Listbox. selectionMode="none" disables selection while preserving navigation. disallowEmptySelection prevents clearing the last selected key.

No matching snippets.

virtualized-listbox/empty.tsx
import "./layout.css";
import { VirtualizedListbox } from "@codeui/solid";
export default function Empty() {
	return <div><VirtualizedListbox class="virtualized-demo" aria-label="Matching snippets" options={[]} /><p>No matching snippets.</p></div>;
}

An empty collection has no rows. Supply your own empty message outside the list.

Ready API

VirtualizedListbox

Renders the shared Listbox with a virtual spacer and positioned rows.

Prop

Type

Prop

Type

Options are a flat array of { value: string; label: string; disabled?: boolean } objects. The component fixes optionValue, optionTextValue, and optionDisabled to those fields. It owns scrollToItem and the virtualized renderer. Grouped options are not supported by this flat renderer. class targets the scroll root. classes uses the shared Listbox part keys. The public props do not accept style. Other selection props follow the Kobalte Listbox contract.

Accessibility

Keyboard

KeyAction
TabEnters the list at the selected or first enabled option, then leaves the list.
Up Arrow, Down ArrowMoves focus between enabled options.
Home, EndMoves to the first or last enabled option.
Enter, SpaceSelects the focused option according to the selection mode.
CharactersMoves focus to the next matching text value.
Shift + ArrowExtends a multiple selection when the selection behavior supports ranges.

ARIA

The root has role="listbox". Items have role="option", aria-selected, and aria-disabled when applicable. Multiple selection adds aria-multiselectable. Supply aria-label or aria-labelledby for the list. optionTextValue provides the plain text used for typeahead when labels contain custom markup.

Focus

Options take DOM focus. Hover focuses options by default. Disabled options are skipped. The list stays inline, so there is no open or close cycle and no focus restoration target.

Keyboard focus navigation calls the virtualizer's scrollToIndex for the target key, so offscreen options can receive focus. This hook follows focus navigation. It is not an imperative scroll-to-selection API.

SSR notes

The root and virtual spacer render on the server. There is no measured viewport on the server, so visible rows are established on the client. Keep the option array, keys, and initial selection stable for hydration. There is no portal.

Theming hooks

The list reads --cui-surface-menu, --cui-surface-menu-hover, --cui-text-menu, --cui-text-selected, and --cui-accent-selection. Geometry uses --cui-radius-xs, --cui-radius-sm, --cui-radius-lg, --cui-space-1, --cui-space-2, --cui-space-3. Text uses --cui-font-size-sm, --cui-font-size-md, and --cui-font-weight-normal. The legacy bordered mode reads --cui-border-width, --cui-border-divider, and --cui-focus-color. The styles also reference --cui-shadow-menu and --cui-border-menu. Keep the neutral variant and borderless default for Inkstone. The primary highlight and bordered mode are legacy styles.

Composition examples

The main demo combines a bounded collection, controlled selection, an external selection summary, and part classes. Keep the summary outside the scrolling root so changing selection does not alter row geometry.

  • Listbox supports short collections and section headings.
  • Combobox adds text entry and filtering.

On this page