Fragiola

API: components

CommandVirtual

A Command List over thousands of actions that renders only the shown Items in view, the keys and the highlight reaching every match.

A Command for a long list of actions: CommandVirtual.List replaces the Command's List, filters its items with the Root's text and filter, and renders only the shown Items in view (with 10 000 items, a few dozen options in the DOM), while the keys, the highlight on the best match and aria-activedescendant reach every match. It is opt-in, in an entry of its own, /command-virtual: a Command that does not use it ships no virtualizer.

The APG has no virtual list pattern; it only says that a set whose options are not all in the DOM gives each option aria-setsize and aria-posinset. Everything else is the Command's (the APG combobox pattern): a virtual list behaves as the same list rendered whole.

Behaviour

  • The Command's part: the List is a Command List (data-primitives-part="command-list", the same role and state attributes, data-empty and data-loading included), so a Command recipe and its selectors apply. Its options are Command.Items that you render for each row in view.
  • It filters its items, { value, keywords?, disabled? } (more fields allowed), with the Root's text and filter (the toolkit's commandMatches): only the matching entries are rows. No groups.
  • Only the rows in view are rendered, plus overscan rows beyond each end and the pinned rows: the first and last matches, the highlighted one with its neighbours and the best match. So the arrows, Home and End and the highlight behave as with every Item rendered.
  • The place in the set: each rendered option has aria-setsize (the number of matching entries), aria-posinset (its index + 1) and data-index.
  • Sizes, loading: itemSize, measure, overscan, loading and onLoadMore as every virtual list's (ListboxVirtual); pages from a loader come through the async list.

The row style

The rows keep the list's flow layout: no wrapper and no spacer element. Each rendered option gets, inline, the room of the unrendered rows before it as margin-block-start (the last one, the room after it as margin-block-end), flex-shrink: 0 and overflow-anchor: none. So lay the options out in a flex or grid column with no margin of their own, make the List the scroll container (a height and overflow-y: auto on it), and set itemSize to the typical row height.

Anatomy

The Command's parts, the List replaced:

partelementdata-primitives-partrole
Listdivcommand-listthe listbox, a Command List that renders the matching entries in view
(options)divcommand-itemyour Command.Item for each row in view

Usage

import { Command, CommandVirtual } from "@fragiola/primitives-react/command-virtual";

<Command.Root>
    <Command.Input aria-label="Command" />
    <Command.Empty>No results.</Command.Empty>
    <CommandVirtual.List items={ACTIONS} className="flex h-80 flex-col overflow-y-auto">
        {(entry) => (
            <Command.Item value={entry.value} disabled={entry.disabled} onSelect={run}>
                {entry.value}
            </Command.Item>
        )}
    </CommandVirtual.List>
</Command.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. The names below are React's; Vue binds them the same way (@load-more), and Angular as inputs and outputs ((loadMore)). The other parts are the Command's.

List

proptypedefaultdescription
items{ value, keywords?, disabled? }[]required: the entries, filtered with the Root's text and filter
itemSizenumber | (index: number) => number36a row's size in px before it is measured (every row's with measure off): the typical row height
measurebooleantruemeasure the rendered rows; false: fixed sizes
overscannumber4the rows rendered beyond each end of the view
loadingbooleanfalsethe list is loading: data-loading, aria-busy="true"
onLoadMore() => voidthe last row came into view while not loading: load the next page (Vue @load-more, Angular (loadMore))

React's children and Vue's default slot render each matching entry in view, with its index (an Angular template renders rows()).

State and part attributes

Everything of the Command's List and Items, plus:

partattributes
each rendered optionaria-setsize (the number of matching entries), aria-posinset (its index + 1), data-index (its index); inline margin-block-start / margin-block-end when unrendered rows come before / after it, flex-shrink: 0, overflow-anchor: none

Keyboard

The Command's keys, over every matching entry: the highlighted Item is rendered and scrolled into view.

Exports

entryexports
@fragiola/primitives-react/command-virtualCommand, CommandEntry, CommandVirtual, CommandVirtualListProps, VirtualListProps
@fragiola/primitives-vue/command-virtualCommand, CommandEntry, CommandVirtual, CommandVirtualListProps, CommandVirtualListSlots, VirtualListEmits, VirtualListProps
@fragiola/primitives-angular/command-virtual* (every export of the Command entry), CommandVirtualList, CommandVirtualRow, VirtualItemSize, VirtualRowData