@tanstack/virtual.All virtualizer (ACombobox, AListbox, and ATree) components offer the following props and customization:
estimateSize: Set estimate item heights for static or dynamic itemoverscan: Control the number of items rendered outside the visible areatextContent: Text content for each item to achieve type-ahead featureHere's a few important note to make sure virtualization works!
<Virtualizer />.estimateSize props appropriately.textContent props to make sure type-ahead acceessibility.<script setup>
import { AComboboxContent, AComboboxItem, AComboboxRoot, AComboboxViewport, AComboboxVirtualizer } from 'akar';
const items = [
// … large array of items
];
</script>
<template>
<AComboboxRoot>
…
<AComboboxContent>
<!-- Make sure to set a height for Virtualizer's parent element -->
<AComboboxViewport class="max-h-80 overflow-y-auto">
<AComboboxVirtualizer
v-slot="{ option }"
:options="items"
:estimate-size="25"
:text-content="(opt) => opt.label"
>
<AComboboxItem :value="option">
{{ option.label }}
</AComboboxItem>
</AComboboxVirtualizer>
</AComboboxViewport>
</AComboboxContent>
</AComboboxRoot>
</template>
Do ensure that <Virtualizer>'s parent element has a defined height!
<template>
<AComboboxRoot>
…
<AComboboxContent>
<!-- Height must be defined -->
<AComboboxViewport class="max-h-80 overflow-y-auto">
<AComboboxVirtualizer>
…
</AComboboxVirtualizer>
</AComboboxViewport>
</AComboboxContent>
</AComboboxRoot>
</template>