fix(list-box): update conditional virtual loader reservations

This commit is contained in:
maoyingjie
2026-10-29 17:15:30 +08:00
parent 5a00e25a25
commit 6d9e3f31cf
2 changed files with 31 additions and 1 deletions
@@ -74,6 +74,7 @@ defineSlots<{
loader?: () => unknown; loader?: () => unknown;
}>(); }>();
const slots = useSlots(); const slots = useSlots();
const hasLoader = ref(Boolean(slots.loader));
const attrs = useAttrs(); const attrs = useAttrs();
const instance = getCurrentInstance()!; const instance = getCurrentInstance()!;
const modelPresence = () => const modelPresence = () =>
@@ -87,6 +88,7 @@ const selectedPresence = () =>
const controlled = ref(modelPresence() || selectedPresence()); const controlled = ref(modelPresence() || selectedPresence());
const hasModel = ref(modelPresence()); const hasModel = ref(modelPresence());
onBeforeUpdate(() => { onBeforeUpdate(() => {
hasLoader.value = Boolean(slots.loader);
hasModel.value = modelPresence(); hasModel.value = modelPresence();
controlled.value = hasModel.value || selectedPresence(); controlled.value = hasModel.value || selectedPresence();
}); });
@@ -312,7 +314,7 @@ const virtualRows = computed<VirtualRow[]>(() => {
gap: 0, gap: 0,
}); });
}); });
if (slots.loader && props.loaderHeight > 0) if (hasLoader.value && props.loaderHeight > 0)
push({ key: "loader", kind: "loader", height: props.loaderHeight, gap: 0 }); push({ key: "loader", kind: "loader", height: props.loaderHeight, gap: 0 });
if (props.padding > 0) if (props.padding > 0)
push({ key: "pad-bottom", kind: "pad", height: props.padding, gap: 0 }); push({ key: "pad-bottom", kind: "pad", height: props.padding, gap: 0 });
+28
View File
@@ -406,3 +406,31 @@ it("explicit TableRow height uses a content box without changing ordinary cells"
root.findAll('[data-slot="table-row"]')[1].attributes("style") ?? "", root.findAll('[data-slot="table-row"]')[1].attributes("style") ?? "",
).not.toContain("height"); ).not.toContain("height");
}); });
it("removes a conditional loader reservation without changing the items", async () => {
const show = ref(true);
const items = [{ id: 1, textValue: "One" }];
const w = mount(
defineComponent({
render: () =>
h(
ListBox,
{ items, virtualized: true, overscan: 20 },
{
default: ({ item }: { item: (typeof items)[number] }) =>
h(ListBoxItem, { id: item.id }, () => item.textValue),
...(show.value ? { loader: () => h("span", "Loading") } : {}),
},
),
}),
{ attachTo: document.body },
);
wrappers.push(w);
await nextTick();
await nextTick();
expect(rowWrappers()).toHaveLength(2);
show.value = false;
await nextTick();
await nextTick();
expect(rowWrappers()).toHaveLength(1);
});