VirtualItems
The rows of a virtualized tree - only the visible items in view, flat, between spacers - from the virtualization feature's entry.
VirtualItems renders the rows of a virtualized tree: a Tree.Root whose model has the
virtualization feature (virtualization(options)). It comes with the feature, from
@fragiola/tree-react/virtualization (@fragiola/tree-vue/virtualization,
@fragiola/tree-angular/virtualization), with useTreeVirtualWindow: a tree that never imports
them does not ship them. It calls its children function with each visible item in view plus the
overscan, in order, and puts a spacer where the other rows would be. It renders no element of its
own and takes no common props. Without the feature, it renders nothing.
import { createTreeModel, Tree } from "@fragiola/tree-react";
import { VirtualItems, virtualization } from "@fragiola/tree-react/virtualization";
const features = [virtualization({ rowSize: 28 })] as const;
function Files() {
const [model] = useState(() => createTreeModel<Types, typeof features>(json, { features }));
return (
<Tree.Root model={model} aria-label="Files" style={{ height: 400, overflow: "auto" }}>
<VirtualItems<Types>>{(item) => <FileRow item={item} />}</VirtualItems>
</Tree.Root>
);
}A virtualized tree is flat: every rendered item is a sibling of the others in the root, and
carries its aria-level, aria-posinset and aria-setsize, so assistive technology reads the
whole structure. Render each row as a Tree.Item with its Tree.ItemContent, and no
Tree.Group: the indentation comes from --tree-depth on the item. The rows start at the top
of the root's content box, and the root (or the scrollElement you give virtualization()) is the
element that scrolls. The roving tab stop, the item being renamed and the item a pointer pressed
stay rendered wherever the scroll is. The guide is Virtualization.
Props
VirtualItemsProps<T>:
| prop | type | description |
|---|---|---|
children | (item: ItemOf<T>, row: VirtualRow) => ReactNode | renders a row: called with each rendered visible item, in order, and its VirtualRow (its level, index, offset and size) |
Attributes
The rows are your items. Each spacer is a div with data-tree-part="spacer", aria-hidden
and its height (and flex-shrink: 0) as its only inline style; its size is the space of the rows
it stands for (spaceBefore of the row after it, spaceAfter of the window for the last one).