Virtual List
Windowed list with built-in search, sorting, selection and an async data source.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
items | unknown[] | [] | The items to display. An array in the property, JSON in the attribute. |
item-key | string | — | Field used as the identity of an item, for selection and typeahead. Falls back to the item index. |
label-field | string | — | Field read for a row's primary text. Defaults to label, name, title or value, then the item itself. |
description-field | string | — | Field read for a row's second, muted line. |
disabled-field | string | — | Field whose truthy value makes a row unselectable. |
searchable | boolean | false | Shows the built-in search field above the list. |
search | string | — | The query the list is filtered by. Set by the built-in field, or from outside. |
search-fields | string[] | [] | Fields the query is matched against: an array in the property, ;-separated in the attribute. |
min-search-length | number | 1 | Queries shorter than this are ignored, so the list is not filtered on the first keystroke. |
search-debounce | number | 200 | Milliseconds the built-in field waits after the last keystroke before the query is applied. |
search-placeholder | string | Search | Placeholder of the built-in search field. |
highlight | boolean | false | Wraps the matched part of a row's text in <mark part="highlight">. |
sort | SortEntry | undefined | — | The sort: SortEntry in the property, field:asc in the sort attribute. |
selection | VirtualListSelectionMode | none | single selects one row at a time, multiple supports ⌘/ctrl-click and shift-click ranges. |
value | string[] | [] | Keys of the selected items: an array in the property, ;-separated in the attribute. |
virtual | VirtualListVirtualMode | auto | auto windows past virtual-threshold items; always and never force it. |
item-height | number | 36 | Item height in pixels used before the first row has been measured. |
overscan | number | 6 | Rows rendered above and below the viewport while windowing. |
virtual-threshold | number | 100 | Item count past which virtual="auto" starts windowing. |
block-size | number | 100 | Number of items the list asks a dataSource for at a time. |
loading | boolean | false | Shows the loading state; implied while a dataSource resolves its first block. |
error | string | — | Shows the error state with this message. |
empty-message | string | No items | Message shown when there are no items at all. |
no-results-message | string | No matches | Message shown when a search is active and nothing matches. |
Slots
| Name | Description |
|---|---|
search | Replaces the built-in search field. Set search yourself from its events. |
toolbar | Extra controls beside the search field, for a filter chip or a count. Hidden when empty. |
footer | Bar below the list, for a total or a pager. Hidden when empty. |
empty | Replaces the built-in "no items" message. |
no-results | Replaces the built-in "no matches" message shown while a search is active. |
loading | Replaces the built-in spinner shown while the first items load. |
error | Replaces the built-in message shown when error is set. |
Events
| Name | Type | Description |
|---|---|---|
search-change | CustomEvent<VirtualListSearchChangeEventDetail> | Fired after the query settles, with the number of items that match. |
item-click | CustomEvent<VirtualListItemEventDetail> | Fired when a row is clicked, before the selection is applied. |
selection-change | CustomEvent<VirtualListSelectionChangeEventDetail> | Fired after the user changes the selection. detail.value is the array of selected keys, detail.items the matching items. Does not bubble: several components fire selection-change, so a listener belongs on the element itself rather than on an ancestor. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
search | Header row containing the built-in search field and the search and toolbar slots. |
viewport | Scroll container that holds the listbox and its empty, loading or error state. |
items | Inner listbox containing the rendered rows and virtual-scroll spacers. |
item | Every rendered c2-list-item, including loading placeholders. |
item-selected | A rendered item while it is selected; exposed in addition to item. |
skeleton | Placeholder shown inside an item while its remote data block is loading. |
state | Shared container for the empty, loading, or error slot and its fallback message. |
highlight | A <mark> around text that matches the active search query. |
footer | Footer row containing the footer slot. |
CSS custom properties
Grouped by semantic target and state from --c2-component__target__state--property. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-virtual-list--background | color | #ffffff | |
--c2-virtual-list--color | color | #18181b | |
--c2-virtual-list--font-size | font-size | 14px | |
--c2-virtual-list--max-height | pixel | none | Caps the height when the host is not sized itself; the list scrolls. |
--c2-virtual-list--border-top | border | — | |
--c2-virtual-list--border-right | border | — | |
--c2-virtual-list--border-bottom | border | — | |
--c2-virtual-list--border-left | border | — | |
--c2-virtual-list--border-top-left-radius | border-radius | 8px | |
--c2-virtual-list--border-top-right-radius | border-radius | 8px | |
--c2-virtual-list--border-bottom-left-radius | border-radius | 8px | |
--c2-virtual-list--border-bottom-right-radius | border-radius | 8px | |
--c2-virtual-list--box-shadow | box-shadow | — | |
--c2-virtual-list__search--background | color | transparent | |
--c2-virtual-list__search--padding | padding | 8px | |
--c2-virtual-list__search--gap | pixel | 8px | |
--c2-virtual-list__search--border-bottom | border | 1px solid #e4e4e7 | |
--c2-virtual-list__search-field--background | color | #ffffff | Themes the built-in c2-text-field. |
--c2-virtual-list__search-field--border | border | 1px solid #e4e4e7 | |
--c2-virtual-list__search-field--border-radius | border-radius | 6px | |
--c2-virtual-list__search-field--min-height | pixel | 32px | |
--c2-virtual-list__viewport--padding | pixel | 4px | |
--c2-virtual-list__item--height | pixel | 36px | Row height; windowing needs it uniform. |
--c2-virtual-list__highlight--background | color | #fef08a | |
--c2-virtual-list__highlight--color | color | inherit | |
--c2-virtual-list__highlight--font-weight | font-weight | 600 | |
--c2-virtual-list__highlight--border-radius | border-radius | 4px | |
--c2-virtual-list__skeleton--background | color | #f4f4f5 | Placeholder shown in rows whose dataSource block is still loading. |
--c2-virtual-list__skeleton--border-radius | border-radius | 4px | |
--c2-virtual-list__state--color | color | #71717a | Colour of the empty, no-results and loading messages. |
--c2-virtual-list__state--padding | padding | 32px 12px | |
--c2-virtual-list__state--font-size | font-size | 14px | |
--c2-virtual-list__state__error--color | color | rgb(211, 21, 16) | |
--c2-virtual-list__footer--background | color | transparent | |
--c2-virtual-list__footer--padding | padding | 8px 12px | |
--c2-virtual-list__footer--border-top | border | 1px solid #e4e4e7 | |