@@ -10,12 +10,20 @@ interface IProps {
1010
1111const ReactTableScroll = ( { children } : IProps ) => {
1212 const [ horizontalScrollStyle , setHorizontalScrollStyle ] = useState < object > ( { } ) ;
13+ const [ isMobileDevice , setIsMobileDevice ] = useState < boolean > ( false ) ;
14+
1315 const horizontalScrollRef = useRef < HTMLDivElement | null > ( null ) ;
1416 const targetRef = useRef < HTMLDivElement | null > ( null ) ;
1517 const tableContainerRef = useRef < HTMLDivElement | null > ( null ) ;
1618 const tableWrapperRef = useRef < HTMLDivElement | any > ( null ) ;
19+
1720 const { width, height } = useResizeDetector ( { targetRef : tableContainerRef } ) ;
1821
22+ const MobileDeviceDetector = ( ) => {
23+ const isMobile = / M o b i | A n d r o i d / i. test ( navigator . userAgent ) ;
24+ setIsMobileDevice ( isMobile ) ;
25+ } ;
26+
1927 const diffSizes = ( ) : boolean => {
2028 if ( tableContainerRef ?. current && targetRef ?. current ) {
2129 return tableContainerRef . current ?. clientWidth > targetRef . current ?. clientWidth ;
@@ -44,21 +52,28 @@ const ReactTableScroll = ({ children }: IProps) => {
4452
4553 useEffect ( ( ) => {
4654 handleResize ( ) ;
55+ MobileDeviceDetector ( ) ;
4756 } , [ width , height ] ) ;
4857
58+ useEffect ( ( ) => {
59+ MobileDeviceDetector ( ) ;
60+ } , [ ] ) ;
61+
4962 return (
50- < div ref = { targetRef } >
51- < div style = { rtsTableWrapper } ref = { tableWrapperRef } >
52- < div style = { rtsTableContainer } ref = { tableContainerRef } >
53- { children }
63+ < >
64+ < div ref = { targetRef } >
65+ < div style = { { ...rtsTableWrapper , overflowX : isMobileDevice ? 'scroll' : 'hidden' } } ref = { tableWrapperRef } >
66+ < div style = { rtsTableContainer } ref = { tableContainerRef } >
67+ { children }
68+ </ div >
5469 </ div >
70+ { diffSizes ( ) && ! isMobileDevice && (
71+ < div style = { rtsTableScrollWrapper } ref = { horizontalScrollRef } onScroll = { onTableHorizontalScroll } >
72+ < div style = { { ...rtsTableScrollContent , ...horizontalScrollStyle } } > </ div >
73+ </ div >
74+ ) }
5575 </ div >
56- { diffSizes ( ) && (
57- < div style = { rtsTableScrollWrapper } ref = { horizontalScrollRef } onScroll = { onTableHorizontalScroll } >
58- < div style = { { ...rtsTableScrollContent , ...horizontalScrollStyle } } > </ div >
59- </ div >
60- ) }
61- </ div >
76+ </ >
6277 ) ;
6378} ;
6479
0 commit comments