fix(list-box): update conditional virtual loader reservations
This commit is contained in:
@@ -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<VirtualRow[]>(() => {
|
||||
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 });
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user