fix(virtualization): measure natural rows and align viewport geometry

This commit is contained in:
maoyingjie
2026-10-29 17:13:12 +08:00
parent 9f7eb1fa8d
commit 5a00e25a25
18 changed files with 770 additions and 257 deletions
+2 -2
View File
@@ -260,8 +260,8 @@
]
},
"virtual-rows": {
"exports": ["useVirtualRows", "bindVirtualRows"],
"css": ["data-virtualized", "[data-slot=list-box][data-virtualized]"]
"exports": ["useVirtualRows", "bindVirtualRows", "TableRow"],
"css": ["data-virtualized", "[data-slot=list-box][data-virtualized]", "hv-table__fixed-cell-content"]
},
"list-box": {
"exports": [
+18 -4
View File
@@ -9,12 +9,13 @@ import {
type UseVirtualRowsOptions,
type VirtualRowHeight,
type VirtualRowWindow,
type VirtualRowsBindingOptions,
type TableRowProps,
} 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 variable: VirtualRowHeight = (index: number) => (index % 2 ? 44 : 72);
const partial: VirtualRowHeight = (index: number) =>
index % 2 ? undefined : 40;
const options: UseVirtualRowsOptions = {
@@ -33,7 +34,15 @@ 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);
const binding: VirtualRowsBindingOptions = {
content: element,
scrollPaddingStart: () => 48,
};
const detach: () => void = bindVirtualRows(rows, element, binding);
rows.measureRow(0, element);
rows.resetMeasurements();
const fixedRow: TableRowProps = { rowKey: 0, height: 42 };
void fixedRow;
rows.scrollToIndex(element, 10);
// @ts-expect-error Row heights are px numbers or index functions, not strings
@@ -52,7 +61,8 @@ const listProps: ListBoxProps = {
virtualized: true,
rowHeight: (index: number) => (index % 2 ? 64 : 40),
estimatedRowHeight: 50,
headingHeight: 32,
headingHeight: () => undefined,
estimatedHeadingHeight: 32,
loaderHeight: 40,
gap: 8,
padding: 12,
@@ -82,3 +92,7 @@ void [
badHeading,
badRowFn,
];
// @ts-expect-error Native row height uses px numbers
const badTableRow: TableRowProps = { rowKey: 1, height: "42px" };
void badTableRow;