diff --git a/packages/vue/src/components/list-box/ListBox.vue b/packages/vue/src/components/list-box/ListBox.vue index da05f78..a4f4031 100644 --- a/packages/vue/src/components/list-box/ListBox.vue +++ b/packages/vue/src/components/list-box/ListBox.vue @@ -74,6 +74,7 @@ defineSlots<{ loader?: () => unknown; }>(); const slots = useSlots(); +const hasLoader = ref(Boolean(slots.loader)); const attrs = useAttrs(); const instance = getCurrentInstance()!; const modelPresence = () => @@ -87,6 +88,7 @@ const selectedPresence = () => const controlled = ref(modelPresence() || selectedPresence()); const hasModel = ref(modelPresence()); onBeforeUpdate(() => { + hasLoader.value = Boolean(slots.loader); hasModel.value = modelPresence(); controlled.value = hasModel.value || selectedPresence(); }); @@ -312,7 +314,7 @@ const virtualRows = computed(() => { gap: 0, }); }); - if (slots.loader && props.loaderHeight > 0) + if (hasLoader.value && props.loaderHeight > 0) push({ key: "loader", kind: "loader", height: props.loaderHeight, gap: 0 }); if (props.padding > 0) push({ key: "pad-bottom", kind: "pad", height: props.padding, gap: 0 }); diff --git a/tests/virtual-rows.test.ts b/tests/virtual-rows.test.ts index 773929e..5a5e937 100644 --- a/tests/virtual-rows.test.ts +++ b/tests/virtual-rows.test.ts @@ -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") ?? "", ).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); +});