@@ -84,16 +84,13 @@ const List = defineComponent({
84
84
} ,
85
85
setup ( props ) {
86
86
// ================================= MISC =================================
87
-
87
+ const useVirtual = computed ( ( ) => {
88
+ const { height, itemHeight, virtual } = props ;
89
+ return ! ! ( virtual !== false && height && itemHeight ) ;
90
+ } )
88
91
const inVirtual = computed ( ( ) => {
89
- const { height, itemHeight, data, virtual } = props ;
90
- return ! ! (
91
- virtual !== false &&
92
- height &&
93
- itemHeight &&
94
- data &&
95
- itemHeight * data . length > height
96
- ) ;
92
+ const { height, itemHeight, data } = props ;
93
+ return useVirtual . value && data && itemHeight * data . length > height ;
97
94
} ) ;
98
95
99
96
const state = reactive < ListState > ( {
@@ -103,7 +100,8 @@ const List = defineComponent({
103
100
} ) ;
104
101
105
102
const componentRef = ref < HTMLDivElement > ( ) ;
106
-
103
+ const fillerInnerRef = ref < HTMLDivElement > ( ) ;
104
+ const scrollBarRef = ref < any > ( ) ; // Hack on scrollbar to enable flash call
107
105
// =============================== Item Key ===============================
108
106
const getKey = ( item : Record < string , any > ) => {
109
107
if ( typeof props . itemKey === 'function' ) {
@@ -135,17 +133,27 @@ const List = defineComponent({
135
133
136
134
// ================================ Height ================================
137
135
const [ setInstance , collectHeight , heights , heightUpdatedMark ] = useHeights ( getKey , null , null ) ;
138
-
139
136
// ========================== Visible Calculation =========================
140
137
const calRes = computed ( ( ) => {
141
- if ( ! inVirtual . value ) {
138
+ if ( ! useVirtual . value ) {
142
139
return {
143
140
scrollHeight : undefined ,
144
141
start : 0 ,
145
142
end : state . mergedData . length - 1 ,
146
143
offset : undefined ,
147
144
} ;
148
145
}
146
+
147
+ // Always use virtual scroll bar in avoid shaking
148
+ if ( ! inVirtual . value ) {
149
+ return {
150
+ scrollHeight : fillerInnerRef . value ?. offsetHeight || 0 ,
151
+ start : 0 ,
152
+ end : state . mergedData . length - 1 ,
153
+ offset : undefined ,
154
+ } ;
155
+ }
156
+
149
157
let itemTop = 0 ;
150
158
let startIndex : number | undefined ;
151
159
let startOffset : number | undefined ;
@@ -228,7 +236,7 @@ const List = defineComponent({
228
236
229
237
// Since this added in global,should use ref to keep update
230
238
const [ onRawWheel , onFireFoxScroll ] = useFrameWheel (
231
- inVirtual ,
239
+ useVirtual ,
232
240
isScrollAtTop ,
233
241
isScrollAtBottom ,
234
242
offsetY => {
@@ -240,7 +248,7 @@ const List = defineComponent({
240
248
) ;
241
249
242
250
// Mobile touch move
243
- useMobileTouchMove ( inVirtual , componentRef , ( deltaY , smoothOffset ) => {
251
+ useMobileTouchMove ( useVirtual , componentRef , ( deltaY , smoothOffset ) => {
244
252
if ( originScroll ( deltaY , smoothOffset ) ) {
245
253
return false ;
246
254
}
@@ -250,7 +258,7 @@ const List = defineComponent({
250
258
} ) ;
251
259
// Firefox only
252
260
function onMozMousePixelScroll ( e : MouseEvent ) {
253
- if ( inVirtual . value ) {
261
+ if ( useVirtual . value ) {
254
262
e . preventDefault ( ) ;
255
263
}
256
264
}
@@ -285,14 +293,17 @@ const List = defineComponent({
285
293
getKey ,
286
294
collectHeight ,
287
295
syncScrollTop ,
296
+ ( ) => {
297
+ scrollBarRef . value ?. delayHidden ( ) ;
298
+ } ,
288
299
) ;
289
300
290
301
const componentStyle = computed ( ( ) => {
291
302
let cs : CSSProperties | null = null ;
292
303
if ( props . height ) {
293
304
cs = { [ props . fullHeight ? 'height' : 'maxHeight' ] : props . height + 'px' , ...ScrollStyle } ;
294
305
295
- if ( inVirtual . value ) {
306
+ if ( useVirtual . value ) {
296
307
cs ! . overflowY = 'hidden' ;
297
308
298
309
if ( state . scrollMoving ) {
@@ -310,11 +321,13 @@ const List = defineComponent({
310
321
onFallbackScroll,
311
322
onScrollBar,
312
323
componentRef,
313
- inVirtual ,
324
+ useVirtual ,
314
325
calRes,
315
326
collectHeight,
316
327
setInstance,
317
328
sharedConfig,
329
+ scrollBarRef,
330
+ fillerInnerRef
318
331
} ;
319
332
} ,
320
333
render ( ) {
@@ -341,7 +354,7 @@ const List = defineComponent({
341
354
componentStyle,
342
355
onFallbackScroll,
343
356
onScrollBar,
344
- inVirtual ,
357
+ useVirtual ,
345
358
collectHeight,
346
359
sharedConfig,
347
360
setInstance,
@@ -375,13 +388,15 @@ const List = defineComponent({
375
388
height = { scrollHeight }
376
389
offset = { offset }
377
390
onInnerResize = { collectHeight }
391
+ ref = "fillerInnerRef"
378
392
>
379
393
{ listChildren }
380
394
</ Filler >
381
395
</ Component >
382
396
383
- { inVirtual && (
397
+ { useVirtual && (
384
398
< ScrollBar
399
+ ref = "scrollBarRef"
385
400
prefixCls = { prefixCls }
386
401
scrollTop = { scrollTop }
387
402
height = { height }
0 commit comments