Skip to content

Commit aea2510

Browse files
committed
fix: select scroll height not correct #3419
1 parent 4f9555c commit aea2510

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

antdv-demo

components/vc-virtual-list/List.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const List = defineComponent({
133133
}
134134

135135
// ================================ Height ================================
136-
const [setInstance, collectHeight, heights, heightUpdatedMark] = useHeights(getKey, null, null);
136+
const [setInstance, collectHeight, heights] = useHeights(getKey, null, null);
137137
// ========================== Visible Calculation =========================
138138
const calRes = computed(() => {
139139
if (!useVirtual.value) {
@@ -194,7 +194,6 @@ const List = defineComponent({
194194
// Give cache to improve scroll experience
195195
endIndex = Math.min(endIndex + 1, state.mergedData.length);
196196
return {
197-
heightUpdatedMark,
198197
scrollHeight: itemTop,
199198
start: startIndex,
200199
end: endIndex,

components/vc-virtual-list/hooks/useHeights.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Ref, ref, VNodeProps } from 'vue';
1+
import { reactive, VNodeProps } from 'vue';
22
import { GetKey } from '../interface';
33

44
type CacheMap = Record<string, number>;
@@ -7,10 +7,9 @@ export default function useHeights<T>(
77
getKey: GetKey<T>,
88
onItemAdd?: ((item: T) => void) | null,
99
onItemRemove?: ((item: T) => void) | null,
10-
): [(item: T, instance: HTMLElement) => void, () => void, CacheMap, Ref<number>] {
10+
): [(item: T, instance: HTMLElement) => void, () => void, CacheMap] {
1111
const instance = new Map<VNodeProps['key'], HTMLElement>();
12-
const heights = {};
13-
const updatedMark = ref(0);
12+
const heights = reactive({});
1413
let heightUpdateId = 0;
1514
function collectHeight() {
1615
heightUpdateId += 1;
@@ -28,7 +27,6 @@ export default function useHeights<T>(
2827
}
2928
}
3029
});
31-
updatedMark.value++;
3230
});
3331
}
3432

@@ -53,5 +51,5 @@ export default function useHeights<T>(
5351
}
5452
}
5553

56-
return [setInstance, collectHeight, heights, updatedMark];
54+
return [setInstance, collectHeight, heights];
5755
}

0 commit comments

Comments
 (0)