VirtualList
Frames long scrollable collections for virtualization adapters.
See it and copy it
Framework example
Choose Astro, React, or Elements to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View VirtualList code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.---
import { VirtualList } from '@santi020k/lumen-astro'
const rows = Array.from({ length: 200 }, (_, index) => `Deployment #${200 - index}`)
---
{/* 200 rows remain mounted; only the fixed-height visible window is displayed. */}
<VirtualList aria-label="Deployments" itemSize={44} style="--ui-list-height: 12rem">
{rows.map(row => <div>{row}</div>)}
</VirtualList>
{/* Data mode mounts a bounded window from a synthetic 10,000-record collection. */}
<VirtualList id="data-virtual-list" mode="data" role="list" aria-label="Large deployment collection" style="--ui-list-height: 12rem" />
<noscript><p>Enable JavaScript to browse the large deployment collection.</p></noscript>
<script>
import { createLumenVirtualCollectionController } from '@santi020k/lumen-core'
const root = document.getElementById('data-virtual-list')
if (root && !root.dataset.collectionReady) {
root.dataset.collectionReady = 'true'
const controller = createLumenVirtualCollectionController(root, {
items: Array.from({ length: 10000 }, (_, id) => ({ id })),
getKey: record => record.id,
itemSize: 44,
renderItem: record => {
const row = document.createElement('div')
row.textContent = `Deployment #${record.id + 1}`
return row
}
})
document.addEventListener('astro:before-swap', () => controller.destroy(), { once: true })
}
</script>'use client'
import { Button, VirtualList } from '@santi020k/lumen-react'
const records = Array.from({ length: 10000 }, (_, id) => ({ id, label: `Record ${id + 1}` }))
export function Example() {
return (
<VirtualList aria-label="Records" items={records} getKey={record => record.id}
renderItem={record => <Button variant="ghost">{record.label}</Button>}
itemSize={44} overscan={4} style={{ height: '12rem' }} />
)
}<lumen-virtual-list id="records" mode="data" role="list" aria-label="Records"></lumen-virtual-list>
<script type="module">
import { createLumenVirtualCollectionController } from '@santi020k/lumen-core'
const root = document.getElementById('records')
if (root) {
const controller = createLumenVirtualCollectionController(root, {
items: Array.from({ length: 10000 }, (_, id) => ({ id })),
getKey: record => record.id,
itemSize: 44,
renderItem: record => {
const row = document.createElement('div')
row.textContent = `Record ${record.id + 1}`
return row
}
})
// Call controller.destroy() when removing this view.
}
</script>Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astropnpm add @santi020k/lumen-astrolumen add VirtualListlumen add VirtualListpnpm add @santi020k/lumen-reactpnpm add @santi020k/lumen-reactlumen add VirtualList --target reactlumen add VirtualList --target reactpnpm add @santi020k/lumen-elementspnpm add @santi020k/lumen-elementslumen add VirtualList --target elementslumen add VirtualList --target elementsGlass
Add the glass prop to apply the shared blur, saturation, border, and highlight tokens. Glass reads best over vivid content, so place the surface above imagery or color.
View VirtualList code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.---
import { VirtualList } from '@santi020k/lumen-astro'
---
<div class="docs-glass-demo">
<VirtualList glass style="--ui-list-height: 12rem;">
<div>Frosted row 1</div>
<div>Frosted row 2</div>
<div>Frosted row 3</div>
<div>Frosted row 4</div>
</VirtualList>
</div>'use client'
import { Button, VirtualList } from '@santi020k/lumen-react'
const records = Array.from({ length: 10000 }, (_, id) => ({ id, label: `Record ${id + 1}` }))
export function Example() {
return (
<VirtualList aria-label="Records" items={records} getKey={record => record.id}
renderItem={record => <Button variant="ghost">{record.label}</Button>}
itemSize={44} overscan={4} style={{ height: '12rem' }} />
)
}<lumen-virtual-list id="records" mode="data" role="list" aria-label="Records"></lumen-virtual-list>
<script type="module">
import { createLumenVirtualCollectionController } from '@santi020k/lumen-core'
const root = document.getElementById('records')
if (root) {
const controller = createLumenVirtualCollectionController(root, {
items: Array.from({ length: 10000 }, (_, id) => ({ id })),
getKey: record => record.id,
itemSize: 44,
renderItem: record => {
const row = document.createElement('div')
row.textContent = `Record ${record.id + 1}`
return row
}
})
// Call controller.destroy() when removing this view.
}
</script>API reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| glass | boolean | "subtle" | "strong" | false | Applies the tokenized liquid-glass surface treatment with backdrop-filter fallbacks; "subtle" and "strong" adjust the fill intensity. |
| mode | "mounted" | "data" | "mounted" | Astro/Elements: initialize an empty data-mode root for the Core collection controller. |
| items | readonly T[] | - | React: enable data rendering with immutable records; do not supply children. |
| getKey | (item: T, index: number) => string | number | - | React data mode: stable unique item identity. |
| renderItem | (item: T, index: number) => ReactNode | - | React data mode: render only the visible window and focused neighbors. |
| itemSize | number | string | - | Fixed row height in pixels (default 44). Default mode retains mounted rows; data mode mounts a bounded window. |
| overscan | number | string | - | Extra rows displayed on each side (default 4). Focused rows and neighbors remain available. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:virtual-list-range | VirtualList root ([data-ui-virtual-list]) | { startIndex: number, endIndex: number } | Fires when the virtual list calculates its visible range on initialization or scroll. |