Skip to content

Commit 7665cbe

Browse files
committed
fix: select can not scroll #4396
close #4396
1 parent f35bafb commit 7665cbe

File tree

1 file changed

+63
-61
lines changed

1 file changed

+63
-61
lines changed

components/vc-virtual-list/List.tsx

+63-61
Original file line numberDiff line numberDiff line change
@@ -145,74 +145,76 @@ const List = defineComponent({
145145
watch(
146146
[inVirtual, useVirtual, () => state.scrollTop, mergedData, heights, () => props.height],
147147
() => {
148-
if (!useVirtual.value) {
149-
calRes.value = {
150-
scrollHeight: undefined,
151-
start: 0,
152-
end: mergedData.value.length - 1,
153-
offset: undefined,
154-
};
155-
return;
156-
}
157-
158-
// Always use virtual scroll bar in avoid shaking
159-
if (!inVirtual.value) {
160-
calRes.value = {
161-
scrollHeight: fillerInnerRef.value?.offsetHeight || 0,
162-
start: 0,
163-
end: mergedData.value.length - 1,
164-
offset: undefined,
165-
};
166-
return;
167-
}
168-
169-
let itemTop = 0;
170-
let startIndex: number | undefined;
171-
let startOffset: number | undefined;
172-
let endIndex: number | undefined;
173-
const dataLen = mergedData.value.length;
174-
const data = mergedData.value;
175-
for (let i = 0; i < dataLen; i += 1) {
176-
const item = data[i];
177-
const key = getKey(item);
178-
179-
const cacheHeight = heights[key];
180-
const currentItemBottom =
181-
itemTop + (cacheHeight === undefined ? props.itemHeight! : cacheHeight);
182-
183-
if (currentItemBottom >= state.scrollTop && startIndex === undefined) {
184-
startIndex = i;
185-
startOffset = itemTop;
148+
nextTick(() => {
149+
if (!useVirtual.value) {
150+
calRes.value = {
151+
scrollHeight: undefined,
152+
start: 0,
153+
end: mergedData.value.length - 1,
154+
offset: undefined,
155+
};
156+
return;
186157
}
187158

188-
// Check item bottom in the range. We will render additional one item for motion usage
189-
if (currentItemBottom > state.scrollTop + props.height! && endIndex === undefined) {
190-
endIndex = i;
159+
// Always use virtual scroll bar in avoid shaking
160+
if (!inVirtual.value) {
161+
calRes.value = {
162+
scrollHeight: fillerInnerRef.value?.offsetHeight || 0,
163+
start: 0,
164+
end: mergedData.value.length - 1,
165+
offset: undefined,
166+
};
167+
return;
191168
}
192169

193-
itemTop = currentItemBottom;
194-
}
170+
let itemTop = 0;
171+
let startIndex: number | undefined;
172+
let startOffset: number | undefined;
173+
let endIndex: number | undefined;
174+
const dataLen = mergedData.value.length;
175+
const data = mergedData.value;
176+
for (let i = 0; i < dataLen; i += 1) {
177+
const item = data[i];
178+
const key = getKey(item);
179+
180+
const cacheHeight = heights[key];
181+
const currentItemBottom =
182+
itemTop + (cacheHeight === undefined ? props.itemHeight! : cacheHeight);
183+
184+
if (currentItemBottom >= state.scrollTop && startIndex === undefined) {
185+
startIndex = i;
186+
startOffset = itemTop;
187+
}
188+
189+
// Check item bottom in the range. We will render additional one item for motion usage
190+
if (currentItemBottom > state.scrollTop + props.height! && endIndex === undefined) {
191+
endIndex = i;
192+
}
193+
194+
itemTop = currentItemBottom;
195+
}
195196

196-
// Fallback to normal if not match. This code should never reach
197-
/* istanbul ignore next */
198-
if (startIndex === undefined) {
199-
startIndex = 0;
200-
startOffset = 0;
201-
}
202-
if (endIndex === undefined) {
203-
endIndex = dataLen - 1;
204-
}
197+
// Fallback to normal if not match. This code should never reach
198+
/* istanbul ignore next */
199+
if (startIndex === undefined) {
200+
startIndex = 0;
201+
startOffset = 0;
202+
}
203+
if (endIndex === undefined) {
204+
endIndex = dataLen - 1;
205+
}
205206

206-
// Give cache to improve scroll experience
207-
endIndex = Math.min(endIndex + 1, dataLen);
208-
calRes.value = {
209-
scrollHeight: itemTop,
210-
start: startIndex,
211-
end: endIndex,
212-
offset: startOffset,
213-
};
207+
// Give cache to improve scroll experience
208+
endIndex = Math.min(endIndex + 1, dataLen);
209+
calRes.value = {
210+
scrollHeight: itemTop,
211+
start: startIndex,
212+
end: endIndex,
213+
offset: startOffset,
214+
};
215+
});
214216
},
215-
{ immediate: true },
217+
{ immediate: true, flush: 'post' },
216218
);
217219

218220
// =============================== In Range ===============================

0 commit comments

Comments
 (0)