@@ -42,13 +42,14 @@ export const DataViewTh: FC<DataViewThProps> = ({
4242 increment : 10
4343 } ,
4444 content,
45- ...props
45+ props : thProps ,
46+ ...restProps
4647} : DataViewThProps ) => {
4748 const thRef = useRef < HTMLTableCellElement > ( null ) ;
4849
4950 const isResizable = resizableProps . isResizable ;
5051 const resizeButtonRef = useRef < HTMLButtonElement > ( null ) ;
51- const [ width , setWidth ] = useState ( resizableProps . width ? resizableProps . width : 0 ) ;
52+ const [ width , setWidth ] = useState ( resizableProps . width ? resizableProps . width : 0 ) ;
5253 const increment = resizableProps . increment || 5 ;
5354 const onResize = resizableProps . onResize ;
5455 const setInitialVals = useRef ( true ) ;
@@ -58,9 +59,13 @@ export const DataViewTh: FC<DataViewThProps> = ({
5859 let currWidth = 0 ;
5960
6061 useEffect ( ( ) => {
62+ if ( ! isResizable ) {
63+ return ;
64+ }
65+
6166 const observed = resizeButtonRef . current ;
6267 const observer = new IntersectionObserver (
63- ( [ entry ] ) => {
68+ ( [ entry ] ) => {
6469 isInView . current = entry . isIntersecting ;
6570 } ,
6671 { threshold : 0.3 }
@@ -78,11 +83,11 @@ export const DataViewTh: FC<DataViewThProps> = ({
7883 } , [ ] ) ;
7984
8085 useEffect ( ( ) => {
81- if ( setInitialVals . current && width === 0 ) {
86+ if ( isResizable && setInitialVals . current && width === 0 ) {
8287 setWidth ( thRef . current ?. getBoundingClientRect ( ) . width || 0 ) ;
8388 setInitialVals . current = false ;
8489 }
85- } , [ setInitialVals ] ) ;
90+ } , [ isResizable , setInitialVals ] ) ;
8691
8792 const setDragOffset = ( e : ReactMouseEvent | ReactTouchEvent ) => {
8893 const isRTL = getLanguageDirection ( thRef . current as HTMLElement ) === 'rtl' ;
@@ -190,7 +195,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
190195
191196 // Call the onResize callback with the new width
192197 onResize && onResize ( e , currWidth ) ;
193-
198+
194199 document . removeEventListener ( 'touchmove' , callbackTouchMove ) ;
195200 document . removeEventListener ( 'touchend' , callbackTouchEnd ) ;
196201 } ;
@@ -202,7 +207,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
202207
203208 const handleKeys = ( e : React . KeyboardEvent ) => {
204209 const key = e . key ;
205-
210+
206211 if ( key !== 'Escape' && key !== 'Enter' && key !== 'ArrowLeft' && key !== 'ArrowRight' ) {
207212 if ( isResizing ) {
208213 e . preventDefault ( ) ;
@@ -217,7 +222,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
217222
218223 const isRTL = getLanguageDirection ( thRef . current as HTMLElement ) === 'rtl' ;
219224 const columnRect = thRef . current ?. getBoundingClientRect ( ) ;
220-
225+
221226 let newSize = columnRect ?. width || 0 ;
222227 let delta = 0 ;
223228 if ( key === 'ArrowRight' ) {
@@ -240,7 +245,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
240245 } ;
241246
242247 return (
243- < Th { ...props } style = { { minWidth : width } } ref = { thRef } >
248+ < Th { ...thProps } { ... restProps } style = { width > 0 ? { minWidth : width } : undefined } ref = { thRef } >
244249 { content }
245250 { isResizable && (
246251 < Button
0 commit comments