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
+10 -16
View File
@@ -118,7 +118,10 @@ function focusRow(_key: string | number, index: number) {
let detach: (() => void) | undefined;
onMounted(() => {
const element = scrollElement();
if (element) detach = bindVirtualRows(rows, element);
if (element)
detach = bindVirtualRows(rows, element, {
content: element.querySelector("tbody") ?? undefined,
});
});
onUnmounted(() => detach?.());
</script>
@@ -133,12 +136,12 @@ onUnmounted(() => detach?.());
>
<TableContent
aria-label="1000 行虚拟化表格"
class="min-w-[700px] table-fixed"
class="min-w-[700px]"
:row-keys="rowKeys"
:aria-rowcount="users.length + 1"
@focus-row="focusRow"
>
<TableHeader aria-rowindex="1" class="h-full w-full">
<TableHeader aria-rowindex="1" style="height: 42px" class="w-full">
<TableColumn id="name" is-row-header :min-width="160">
姓名
</TableColumn>
@@ -155,24 +158,15 @@ onUnmounted(() => detach?.());
:key="user.id"
:row-key="user.id"
:aria-rowindex="user.id + 1"
:style="{ height: ITEM_HEIGHT + 'px' }"
:height="ITEM_HEIGHT"
>
<TableCell
class="whitespace-nowrap overflow-hidden text-ellipsis"
:style="{ height: ITEM_HEIGHT + 'px' }"
>
<TableCell>
{{ user.name }}
</TableCell>
<TableCell
class="whitespace-nowrap overflow-hidden text-ellipsis"
:style="{ height: ITEM_HEIGHT + 'px' }"
>
<TableCell>
{{ user.role }}
</TableCell>
<TableCell
class="whitespace-nowrap overflow-hidden text-ellipsis"
:style="{ height: ITEM_HEIGHT + 'px' }"
>
<TableCell>
{{ user.email }}
</TableCell>
</TableRow>