@@ -6,7 +6,10 @@ import { resetWarned } from 'rc-util/lib/warning';
66import React from 'react' ;
77import { VirtualTable , type Reference , type VirtualTableProps } from '../src' ;
88
9+ const identity = ( value : any ) => value ;
10+
911global . scrollToConfig = null ;
12+ global . collectGetScrollInfoReturn = identity ;
1013
1114vi . mock ( 'rc-virtual-list' , async ( ) => {
1215 const RealVirtualList = ( ( await vi . importActual ( 'rc-virtual-list' ) ) as any ) . default ;
@@ -20,6 +23,10 @@ vi.mock('rc-virtual-list', async () => {
2023 global . scrollToConfig = config ;
2124 return myRef . current . scrollTo ( config ) ;
2225 } ,
26+ getScrollInfo : ( ) => {
27+ const originResult = myRef . current . getScrollInfo ( ) ;
28+ return global . collectGetScrollInfoReturn ( originResult ) ;
29+ } ,
2330 } ) ) ;
2431
2532 return < RealVirtualList ref = { myRef } { ...props } data-scroll-width = { props . scrollWidth } /> ;
@@ -59,7 +66,8 @@ describe('Table.Virtual', () => {
5966 beforeEach ( ( ) => {
6067 scrollLeftCalled = false ;
6168 setScrollLeft . mockReset ( ) ;
62- global . scrollToConfig = null ;
69+ global . scrollToConfig = vi . fn ( identity ) ;
70+ // global.collectGetScrollInfoReturn.mockReset();
6371 vi . useFakeTimers ( ) ;
6472 resetWarned ( ) ;
6573 } ) ;
@@ -563,4 +571,26 @@ describe('Table.Virtual', () => {
563571 ) . toBeTruthy ( ) ;
564572 } ) ;
565573 } ) ;
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+ } ) ;
566596} ) ;
0 commit comments