@@ -31,11 +31,12 @@ export default class ScrollTo extends React.Component {
3131 }
3232
3333 componentDidMount ( ) {
34- const { current } = this . props . target ;
34+ const { name, target } = this . props ;
35+ const { current } = target || { } ;
3536
3637 if ( current ) {
3738 this . addEventListeners ( current ) ;
38- this . animate ( 'scrollTop' , current . scrollTop , this . props . scrollTop , 1 ) ;
39+ this . animate ( name , current [ name ] , this . props . value , 1 ) ;
3940 }
4041 }
4142
@@ -44,7 +45,7 @@ export default class ScrollTo extends React.Component {
4445 const { target } = this . props ;
4546 const { current : prevCurrent } = prevTarget || { } ;
4647 const { current } = target || { } ;
47- const scrollChanged = prevProps . scrollTop !== this . props . scrollTop ;
48+ const scrollChanged = prevProps . value !== this . props . value ;
4849 const targetChanged = prevCurrent !== current ;
4950
5051 if ( targetChanged ) {
@@ -53,7 +54,9 @@ export default class ScrollTo extends React.Component {
5354 }
5455
5556 if ( ( scrollChanged || targetChanged ) && current ) {
56- this . animate ( 'scrollTop' , current . scrollTop , this . props . scrollTop , 1 ) ;
57+ const { name } = this . props ;
58+
59+ this . animate ( name , current [ name ] , this . props . value , 1 ) ;
5760 }
5861 }
5962
@@ -107,7 +110,8 @@ export default class ScrollTo extends React.Component {
107110}
108111
109112ScrollTo . propTypes = {
113+ name : PropTypes . string . isRequired ,
110114 onEnd : PropTypes . func ,
111- scrollTop : PropTypes . number ,
112- target : PropTypes . any
115+ target : PropTypes . any . isRequired ,
116+ value : PropTypes . number . isRequired
113117} ;
0 commit comments