@@ -6,7 +6,10 @@ import { resetWarned } from '@rc-component/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 } ) ;
@@ -606,4 +614,26 @@ describe('Table.Virtual', () => {
606614 expect ( container . querySelector ( '.rc-table' ) ) . toHaveClass ( 'rc-table-fix-end-shadow-show' ) ;
607615 } ) ;
608616 } ) ;
617+
618+ /**
619+ * In antd, we need to call the scrollTop method through ref to achieve scrolling.
620+ * see: https://github.com/ant-design/ant-design/issues/54734
621+ */
622+ it ( 'should get and set scrollTop correctly' , async ( ) => {
623+ const ref = React . createRef < any > ( ) ;
624+
625+ global . collectGetScrollInfoReturn = ( origin : any ) => ( {
626+ ...origin ,
627+ y : 50 ,
628+ } ) ;
629+
630+ getTable ( { internalRefs : { body : ref } } ) ;
631+
632+ expect ( ref . current . scrollTop ) . toBe ( 50 ) ;
633+
634+ ref . current . scrollTop = 200 ;
635+ expect ( global . scrollToConfig ) . toEqual ( {
636+ top : 200 ,
637+ } ) ;
638+ } ) ;
609639} ) ;
0 commit comments