@@ -12,27 +12,28 @@ const ReactTableScroll = ({ children }: IProps) => {
1212 const horizontalScrollRef = useRef < HTMLDivElement | any > ( null ) ;
1313 const targetRef = useRef < HTMLDivElement | any > ( null ) ;
1414 const { width, height } = useResizeDetector ( { targetRef } ) ;
15+ const tableContainerRef = useRef < HTMLDivElement | any > ( null ) ;
1516 const tableWrapperRef = useRef < HTMLDivElement | any > ( null ) ;
16- const [ tableLeftPos , setTableLeftPos ] = useState < number > ( 0 ) ;
1717
1818 const diffSizes = ( ) : boolean => {
19- return tableWrapperRef . current ?. clientWidth > targetRef . current ?. clientWidth ;
19+ return tableContainerRef . current ?. clientWidth > targetRef . current ?. clientWidth ;
2020 } ;
2121
2222 const handleResize = ( ) => {
2323 const setValue = ( value : number ) => {
2424 setHorizontalScrollStyle ( { width : value } ) ;
2525 } ;
2626 if ( diffSizes ( ) ) {
27- setValue ( tableWrapperRef . current ?. clientWidth ) ;
27+ setValue ( tableContainerRef . current ?. clientWidth ) ;
2828 } else {
2929 setValue ( 0 ) ;
3030 }
3131 } ;
3232
3333 const onTableHorizontalScroll = ( ) => {
3434 const posX : number = horizontalScrollRef . current ?. scrollLeft ?? 0 ;
35- setTableLeftPos ( posX ) ;
35+ const posY : number = horizontalScrollRef . current ?. scrollTop ?? 0 ;
36+ tableWrapperRef . current . scrollTo ( posX , posY ) ;
3637 } ;
3738
3839 useEffect ( ( ) => {
@@ -41,8 +42,8 @@ const ReactTableScroll = ({ children }: IProps) => {
4142
4243 return (
4344 < div className = "rts__wrapper" ref = { targetRef } >
44- < div className = "rts-table__wrapper" >
45- < div className = "rts-table__container" ref = { tableWrapperRef } style = { { left : - tableLeftPos } } >
45+ < div className = "rts-table__wrapper" ref = { tableWrapperRef } >
46+ < div className = "rts-table__container" ref = { tableContainerRef } >
4647 { children }
4748 </ div >
4849 </ div >
0 commit comments