WlVirtualList
Size and density
Render 10,000 records with only the items near the viewport in the DOM.
Full example
<script setup lang="ts">
import { WlButton, WlVirtualList } from "legato-ui";
import { computed, ref } from "vue";
const props = { preview: {} as Record<string, unknown> };
const records = Array.from({ length: 10000 }, (_, index) => ({ id: index + 1 }));
const items = computed(() => Array.isArray(props.preview?.items) ? props.preview.items as typeof records : records);
const list = ref<{ scrollToIndex(index: number, options?: { align: "start" | "end" }): void }>();
</script>
<template>
<div class="wl-stack" data-space="sm">
<div class="wl-inline" data-space="sm">
<WlButton size="sm" :disabled="!items.length" @click="list?.scrollToIndex(0, { align: 'start' })">
{{ "First record" }}
</WlButton>
<WlButton size="sm" :disabled="!items.length" @click="list?.scrollToIndex(items.length - 1, { align: 'end' })">
{{ "Last record" }}
</WlButton>
</div>
<WlVirtualList
ref="list"
:items="items"
item-key="id"
:item-height="36"
:height="252"
aria-label="Render 10,000 records with only the items near the viewport in the DOM."
>
<template #default="{ item }">
<div class="virtual-record">{{ "Record" }} {{ item.id }}</div>
</template>
</WlVirtualList>
</div>
</template>
<style scoped>
.virtual-record {
display: flex;
align-items: center;
height: 100%;
padding-inline: var(--wl-space-sm);
border-bottom: 1px solid var(--wl-border);
}
</style>Behavior
Full example
<script setup lang="ts">
import { WlButton, WlVirtualList } from "legato-ui";
import { computed, ref } from "vue";
const props = { preview: {} as Record<string, unknown> };
const records = Array.from({ length: 10000 }, (_, index) => ({ id: index + 1 }));
const items = computed(() => Array.isArray(props.preview?.items) ? props.preview.items as typeof records : records);
const list = ref<{ scrollToIndex(index: number, options?: { align: "start" | "end" }): void }>();
</script>
<template>
<div class="wl-stack" data-space="sm">
<div class="wl-inline" data-space="sm">
<WlButton size="sm" :disabled="!items.length" @click="list?.scrollToIndex(0, { align: 'start' })">
{{ "First record" }}
</WlButton>
<WlButton size="sm" :disabled="!items.length" @click="list?.scrollToIndex(items.length - 1, { align: 'end' })">
{{ "Last record" }}
</WlButton>
</div>
<WlVirtualList
ref="list"
:items="items"
item-key="id"
:item-height="36"
:height="252"
aria-label="Render 10,000 records with only the items near the viewport in the DOM."
>
<template #default="{ item }">
<div class="virtual-record">{{ "Record" }} {{ item.id }}</div>
</template>
</WlVirtualList>
</div>
</template>
<style scoped>
.virtual-record {
display: flex;
align-items: center;
height: 100%;
padding-inline: var(--wl-space-sm);
border-bottom: 1px solid var(--wl-border);
}
</style>Example data
Full example
<script setup lang="ts">
import { WlButton, WlVirtualList } from "legato-ui";
import { computed, ref } from "vue";
const props = { preview: {} as Record<string, unknown> };
const records = Array.from({ length: 10000 }, (_, index) => ({ id: index + 1 }));
const items = computed(() => Array.isArray(props.preview?.items) ? props.preview.items as typeof records : records);
const list = ref<{ scrollToIndex(index: number, options?: { align: "start" | "end" }): void }>();
</script>
<template>
<div class="wl-stack" data-space="sm">
<div class="wl-inline" data-space="sm">
<WlButton size="sm" :disabled="!items.length" @click="list?.scrollToIndex(0, { align: 'start' })">
{{ "First record" }}
</WlButton>
<WlButton size="sm" :disabled="!items.length" @click="list?.scrollToIndex(items.length - 1, { align: 'end' })">
{{ "Last record" }}
</WlButton>
</div>
<WlVirtualList
ref="list"
:items="items"
item-key="id"
:item-height="36"
:height="252"
aria-label="Render 10,000 records with only the items near the viewport in the DOM."
>
<template #default="{ item }">
<div class="virtual-record">{{ "Record" }} {{ item.id }}</div>
</template>
</WlVirtualList>
</div>
</template>
<style scoped>
.virtual-record {
display: flex;
align-items: center;
height: 100%;
padding-inline: var(--wl-space-sm);
border-bottom: 1px solid var(--wl-border);
}
</style>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
items * | readonly Item[] | Required | Items available in the list. |
itemHeight * | number | Required | Height of every item in pixels. |
height | string | | 320 | Scrolling viewport height in pixels or as a CSS length. |
itemKey | keyof Item | | Not set | Field or function resolving the stable key of an item. |
overscan | number | 4 | Additional items rendered on either side of the viewport. |
role | string | "list" | ARIA role of the scroll container. Interactive roles require application keyboard handling. |
ariaLabel | string | Not set | Accessible name for the scroll container. |
emptyMessage | string | Not set | Empty state text. |
pt | WlPt< | Not set | Attributes of internal Legato UI elements. |
Events
No public events.
Slots
| Slot | Type / values | Content |
|---|---|---|
default | default?(props: { item: Item; index: number; start: number; size: number }): unknown; | Visible record and its position within the full list. |
empty | empty?(props: Record< | Custom empty state. |
Pass-through: pt
Sections WlVirtualList are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-virtual-list | Main element of the component. |
content | div.wl-virtual-list__content | Main content area. |
item | div.wl-virtual-list__item | One repeated item. |
emptyMessage | div.wl-virtual-list__empty | The emptyMessage section in WlConfig.pt.table configuration. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- The focusable list viewport supports native scrolling. Visible items announce their position in the full list. The application provides selection and keyboard handling if it chooses the listbox role.
- Set itemHeight to the rendered height of each item. Pass a stable itemKey when records can move.
- Name the scrolling list so users can identify it when it receives focus.
Keyboard and application responsibilities
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesIn your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.