feat(collections): virtual row layout with variable heights, headings, loader and gap/padding
ListBox virtualized mode grows a full row stream (padding spacers, data-driven heading rows, item rows, #loader row) with px semantics mapped from the pinned ListLayout contract: rowHeight may be a per-index function falling back to estimatedRowHeight, gap sits between content rows only, padding is end spacers, and every input is re-read per layout pass. Scroll ownership resolves to the list root or the nearest scrolling ancestor so popovers scroll as a whole with a sticky search field (data-virtualized hook; the historical 320px self-scroll rule stays for non-virtualized lists). Table gains the public useVirtualRows/bindVirtualRows pure geometry helpers (prefix sums + binary search, no state kernel): variable heights, estimated fallback, gap/padding and a loader reservation that stays consistent with the rendered spacers. headingHeight and dropIndicatorThickness remain unavailable (no sectioned header model, no drag-and-drop) and are recorded as such. Pinned demo values stay explicit (table 42px, list-box/autocomplete 50px); the table demo scrolls an outer viewport div because a native table cannot be a scroll container (verified: 300px height blown out to 45036px).
This commit is contained in:
@@ -259,6 +259,10 @@
|
||||
"data-exiting"
|
||||
]
|
||||
},
|
||||
"virtual-rows": {
|
||||
"exports": ["useVirtualRows", "bindVirtualRows"],
|
||||
"css": ["data-virtualized", "[data-slot=list-box][data-virtualized]"]
|
||||
},
|
||||
"list-box": {
|
||||
"exports": [
|
||||
"ListBox",
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import {
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
bindVirtualRows,
|
||||
useVirtualRows,
|
||||
type ListBoxDataItem,
|
||||
type ListBoxProps,
|
||||
type UseVirtualRows,
|
||||
type UseVirtualRowsOptions,
|
||||
type VirtualRowHeight,
|
||||
type VirtualRowWindow,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
// ---- row geometry API (px units; see the ListLayout/TableLayout mapping) ----
|
||||
const fixed: VirtualRowHeight = 50;
|
||||
const variable: VirtualRowHeight = (index: number) =>
|
||||
index % 2 ? 44 : 72;
|
||||
const partial: VirtualRowHeight = (index: number) =>
|
||||
index % 2 ? undefined : 40;
|
||||
const options: UseVirtualRowsOptions = {
|
||||
count: 1000,
|
||||
rowHeight: variable,
|
||||
estimatedRowHeight: 48,
|
||||
loaderHeight: 48,
|
||||
gap: 8,
|
||||
padding: 12,
|
||||
overscan: 8,
|
||||
};
|
||||
const rows: UseVirtualRows = useVirtualRows(options);
|
||||
const window: VirtualRowWindow = rows.window.value;
|
||||
const total: number = rows.totalHeight.value;
|
||||
const offset: number = rows.rowOffsetOf(10);
|
||||
const extent: number = rows.rowExtentOf(10);
|
||||
rows.update(0, 300);
|
||||
declare const element: HTMLElement;
|
||||
const detach: () => void = bindVirtualRows(rows, element);
|
||||
rows.scrollToIndex(element, 10);
|
||||
|
||||
// @ts-expect-error Row heights are px numbers or index functions, not strings
|
||||
const badHeight: VirtualRowHeight = "50px";
|
||||
// @ts-expect-error count is required
|
||||
const missingCount: UseVirtualRowsOptions = { rowHeight: 50 };
|
||||
|
||||
// ---- ListBox virtual layout options (ListLayout mapping) ----
|
||||
const heading: ListBoxDataItem = {
|
||||
id: 1,
|
||||
textValue: "Item",
|
||||
heading: "Group 1",
|
||||
};
|
||||
const listProps: ListBoxProps = {
|
||||
items: [heading],
|
||||
virtualized: true,
|
||||
rowHeight: (index: number) => (index % 2 ? 64 : 40),
|
||||
estimatedRowHeight: 50,
|
||||
headingHeight: 32,
|
||||
loaderHeight: 40,
|
||||
gap: 8,
|
||||
padding: 12,
|
||||
};
|
||||
// @ts-expect-error Heights are px numbers, not strings
|
||||
const badHeading: ListBoxProps = { headingHeight: "32px" };
|
||||
// @ts-expect-error Variable row height functions return numbers or undefined
|
||||
const badRowFn: ListBoxProps = { rowHeight: () => "50" };
|
||||
|
||||
void [
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
fixed,
|
||||
variable,
|
||||
partial,
|
||||
options,
|
||||
rows,
|
||||
window,
|
||||
total,
|
||||
offset,
|
||||
extent,
|
||||
detach,
|
||||
badHeight,
|
||||
missingCount,
|
||||
heading,
|
||||
listProps,
|
||||
badHeading,
|
||||
badRowFn,
|
||||
];
|
||||
Reference in New Issue
Block a user