List
Headless collection renderer with polymorphic roots and caller-controlled virtualization.
Import#
List owns collection traversal and the scroll-element bridge used by virtual renderers. Item markup, semantics, styling, filtering, focus, and selection remain under caller control.
Examples#
Object List#
Render arbitrary objects with a semantic ul root, role="list", and data-slot="root" by default. Use as and native root attributes when another element or role is required; explicit attributes override the defaults.
Virtualization#
Import useListVirtualizer from moraine/utils. It provides a ready-to-use virtualRender, automatically connects the scroll element, positions rows, and forwards dynamic measurement refs. Configure estimateSize, a stable getItemKey, and optional TanStack Virtual settings such as gap and overscan.
The built-in adapter requires @tanstack/virtual-core as an optional peer dependency. Install a compatible version in your application before using it.
Provide a custom virtualRender component when the built-in absolute row layout is not suitable.
Dynamic Heights#
For variable-height rows, provide a reasonable estimate and let the built-in renderer measure connected rows. TanStack Virtual observes later content size changes and recalculates positions; gap remains consistent between measured rows.
API Reference#
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
| as | T | undefined | ul | Root element or component. |
| class | ClassValue | — | Class applied to the component root or trigger element. |
| classes | ListT.Classes | undefined | — | — |
| itemRender* | ComponentOrElement<ListT.ItemRenderProps<TItem, TItemElement>> | — | Renders one collection item. |
| items | readonly TItem[] | undefined | — | Reactive collection rendered by the list. |
| ref | JSX.HTMLElementTags[T] extends { ref?: infer Ref; } ? Ref : never | undefined | — | — |
| style | JSX.CSSProperties | undefined | — | — |
| styles | ListT.Styles | undefined | — | — |
| virtualRender | Component<ListT.VirtualRenderProps<TItem, HTMLElement, TItemElement>> | undefined | — | Replaces normal iteration with caller-controlled virtual rendering. |
ARIA#
| Attribute | Type | Default | Description |
|---|---|---|---|
| role | string | — | Defines the semantic role exposed to assistive technology. |
Data Attributes#
| Attribute | Type | Default | Description |
|---|---|---|---|
| data-slot | string | — | Identifies the rendered slot for styling hooks and selectors. |