@@ -33,6 +33,8 @@ vi.mock('rc-virtual-list', async () => {
3333describe ( 'Table.Virtual' , ( ) => {
3434 let scrollLeftCalled = false ;
3535
36+ const setScrollLeft = vi . fn ( ) ;
37+
3638 beforeAll ( ( ) => {
3739 spyElementPrototypes ( HTMLElement , {
3840 getBoundingClientRect : ( ) => ( {
@@ -43,7 +45,7 @@ describe('Table.Virtual', () => {
4345 scrollLeftCalled = true ;
4446 return 100 ;
4547 } ,
46- set : ( ) => { } ,
48+ set : setScrollLeft as any ,
4749 } ,
4850 clientWidth : {
4951 get : ( ) => 80 ,
@@ -56,6 +58,7 @@ describe('Table.Virtual', () => {
5658
5759 beforeEach ( ( ) => {
5860 scrollLeftCalled = false ;
61+ setScrollLeft . mockReset ( ) ;
5962 global . scrollToConfig = null ;
6063 vi . useFakeTimers ( ) ;
6164 resetWarned ( ) ;
@@ -210,6 +213,35 @@ describe('Table.Virtual', () => {
210213 expect ( scrollLeftCalled ) . toBeTruthy ( ) ;
211214 } ) ;
212215
216+ it ( 'should not reset scroll when data changed' , async ( ) => {
217+ const { container, rerender } = getTable ( ) ;
218+
219+ resize ( container . querySelector ( '.rc-table' ) ! ) ;
220+
221+ rerender (
222+ < VirtualTable
223+ columns = { [
224+ {
225+ dataIndex : 'name' ,
226+ } ,
227+ {
228+ dataIndex : 'age' ,
229+ } ,
230+ {
231+ dataIndex : 'address' ,
232+ } ,
233+ ] }
234+ rowKey = "name"
235+ scroll = { { x : 100 , y : 100 } }
236+ data = { [ { } ] }
237+ /> ,
238+ ) ;
239+ vi . runAllTimers ( ) ;
240+
241+ // mock scrollLeft is 100, but virtual offsetX is 0
242+ expect ( setScrollLeft ) . toHaveBeenCalledWith ( undefined , 0 ) ;
243+ } ) ;
244+
213245 it ( 'should follow correct width' , ( ) => {
214246 const { container } = getTable ( {
215247 columns : [
0 commit comments