@@ -38,10 +38,16 @@ describe('List.Scroll', () => {
3838 beforeAll ( ( ) => {
3939 mockElement = spyElementPrototypes ( HTMLElement , {
4040 offsetHeight : {
41- get : ( ) => 20 ,
41+ get ( ) {
42+ const height = this . getAttribute ( 'data-height' ) ;
43+ return Number ( height || 20 ) ;
44+ } ,
4245 } ,
4346 clientHeight : {
44- get : ( ) => 100 ,
47+ get ( ) {
48+ const height = this . getAttribute ( 'data-height' ) ;
49+ return Number ( height || 100 ) ;
50+ } ,
4551 } ,
4652 getBoundingClientRect : ( ) => boundingRect ,
4753 offsetParent : {
@@ -666,4 +672,63 @@ describe('List.Scroll', () => {
666672 expect ( getScrollTop ( container ) ) . toEqual ( 0 ) ;
667673 } ) ;
668674 } ) ;
675+
676+ it ( 'not scroll jump for item height change' , async ( ) => {
677+ jest . useFakeTimers ( ) ;
678+
679+ const onScroll = jest . fn ( ) ;
680+
681+ const listRef = React . createRef ( ) ;
682+ const { container } = genList (
683+ {
684+ itemHeight : 10 ,
685+ height : 100 ,
686+ data : genData ( 100 ) ,
687+ ref : listRef ,
688+ children : ( { id } ) => < li data-id = { id } > { id } </ li > ,
689+ onScroll,
690+ } ,
691+ render ,
692+ ) ;
693+
694+ // first render refresh
695+ await act ( async ( ) => {
696+ onLibResize ( [
697+ {
698+ target : container . querySelector ( '.rc-virtual-list-holder-inner' ) ,
699+ } ,
700+ ] ) ;
701+
702+ await Promise . resolve ( ) ;
703+ } ) ;
704+
705+ await act ( async ( ) => {
706+ jest . advanceTimersByTime ( 1000 ) ;
707+ await Promise . resolve ( ) ;
708+ } ) ;
709+
710+ container . querySelector ( 'li[data-id="0"]' ) . setAttribute ( 'data-height' , '30' ) ;
711+
712+ // Force change first row height
713+ await act ( async ( ) => {
714+ boundingRect . height = 110 ;
715+
716+ onLibResize ( [
717+ {
718+ target : container . querySelector ( '.rc-virtual-list-holder-inner' ) ,
719+ } ,
720+ ] ) ;
721+
722+ await Promise . resolve ( ) ;
723+ } ) ;
724+
725+ await act ( async ( ) => {
726+ jest . advanceTimersByTime ( 1000 ) ;
727+ await Promise . resolve ( ) ;
728+ } ) ;
729+
730+ expect ( onScroll ) . not . toHaveBeenCalled ( ) ;
731+
732+ jest . useRealTimers ( ) ;
733+ } ) ;
669734} ) ;
0 commit comments