@@ -6,7 +6,10 @@ import { resetWarned } from 'rc-util/lib/warning';
6
6
import React from 'react' ;
7
7
import { VirtualTable , type Reference , type VirtualTableProps } from '../src' ;
8
8
9
+ const identity = ( value : any ) => value ;
10
+
9
11
global . scrollToConfig = null ;
12
+ global . collectGetScrollInfoReturn = identity ;
10
13
11
14
vi . mock ( 'rc-virtual-list' , async ( ) => {
12
15
const RealVirtualList = ( ( await vi . importActual ( 'rc-virtual-list' ) ) as any ) . default ;
@@ -20,6 +23,10 @@ vi.mock('rc-virtual-list', async () => {
20
23
global . scrollToConfig = config ;
21
24
return myRef . current . scrollTo ( config ) ;
22
25
} ,
26
+ getScrollInfo : ( ) => {
27
+ const originResult = myRef . current . getScrollInfo ( ) ;
28
+ return global . collectGetScrollInfoReturn ( originResult ) ;
29
+ } ,
23
30
} ) ) ;
24
31
25
32
return < RealVirtualList ref = { myRef } { ...props } data-scroll-width = { props . scrollWidth } /> ;
@@ -59,7 +66,8 @@ describe('Table.Virtual', () => {
59
66
beforeEach ( ( ) => {
60
67
scrollLeftCalled = false ;
61
68
setScrollLeft . mockReset ( ) ;
62
- global . scrollToConfig = null ;
69
+ global . scrollToConfig = vi . fn ( identity ) ;
70
+ // global.collectGetScrollInfoReturn.mockReset();
63
71
vi . useFakeTimers ( ) ;
64
72
resetWarned ( ) ;
65
73
} ) ;
@@ -563,4 +571,26 @@ describe('Table.Virtual', () => {
563
571
) . toBeTruthy ( ) ;
564
572
} ) ;
565
573
} ) ;
574
+
575
+ /**
576
+ * In antd, we need to call the scrollTop method through ref to achieve scrolling.
577
+ * see: https://github.com/ant-design/ant-design/issues/54734
578
+ */
579
+ it ( 'should get and set scrollTop correctly' , async ( ) => {
580
+ const ref = React . createRef < any > ( ) ;
581
+
582
+ global . collectGetScrollInfoReturn = ( origin : any ) => ( {
583
+ ...origin ,
584
+ y : 50 ,
585
+ } ) ;
586
+
587
+ getTable ( { internalRefs : { body : ref } } ) ;
588
+
589
+ expect ( ref . current . scrollTop ) . toBe ( 50 ) ;
590
+
591
+ ref . current . scrollTop = 200 ;
592
+ expect ( global . scrollToConfig ) . toEqual ( {
593
+ top : 200 ,
594
+ } ) ;
595
+ } ) ;
566
596
} ) ;
0 commit comments