@@ -53,27 +53,20 @@ export const DataViewTh: FC<DataViewThProps> = ({
5353 const thRef = useRef < HTMLTableCellElement > ( null ) ;
5454
5555 const [ width , setWidth ] = useState ( resizableProps ?. width ? resizableProps . width : 0 ) ;
56- const [ screenreaderText , setScreenreaderText ] = useState ( resizableProps ?. screenreaderText || `Column ${ width . toFixed ( 0 ) } pixels` ) ;
57- let currWidth = 0 ;
5856
5957 const isResizable = resizableProps ?. isResizable || false ;
6058 const increment = resizableProps ?. increment || 5 ;
6159 const shiftIncrement = resizableProps ?. shiftIncrement || 25 ;
6260 const resizeButtonAriaLabel = resizableProps ?. resizeButtonAriaLabel || `Resize ${ content } ` ;
6361 const onResize = resizableProps ?. onResize || undefined ;
62+ const screenreaderText = resizableProps ?. screenreaderText || `Column ${ width . toFixed ( 0 ) } pixels` ;
6463
6564 const resizeButtonRef = useRef < HTMLButtonElement > ( null ) ;
6665 const setInitialVals = useRef ( true ) ;
6766 const dragOffset = useRef ( 0 ) ;
6867 const isResizing = useRef ( false ) ;
6968 const isInView = useRef ( true ) ;
7069
71- useEffect ( ( ) => {
72- if ( ! resizableProps ?. screenreaderText && currWidth > 0 ) {
73- setScreenreaderText ( `Column ${ currWidth . toFixed ( 0 ) } pixels` ) ;
74- }
75- } , [ currWidth ] ) ;
76-
7770 useEffect ( ( ) => {
7871 if ( ! isResizable ) {
7972 return ;
@@ -177,7 +170,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
177170 }
178171
179172 thRef . current ?. style . setProperty ( 'min-width' , newSize + 'px' ) ;
180- currWidth = newSize ;
173+ setWidth ( newSize ) ;
181174 } ;
182175
183176 const handleMouseup = ( e : MouseEvent ) => {
@@ -189,7 +182,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
189182 dragOffset . current = 0 ;
190183
191184 // Call the onResize callback with the new width
192- onResize && onResize ( e , currWidth ) ;
185+ onResize && onResize ( e , width ) ;
193186
194187 // Handle scroll into view when column drag button is moved off screen
195188 if ( resizeButtonRef . current && ! isInView . current ) {
@@ -210,7 +203,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
210203 dragOffset . current = 0 ;
211204
212205 // Call the onResize callback with the new width
213- onResize && onResize ( e , currWidth ) ;
206+ onResize && onResize ( e , width ) ;
214207
215208 document . removeEventListener ( 'touchmove' , callbackTouchMove ) ;
216209 document . removeEventListener ( 'touchend' , callbackTouchEnd ) ;
@@ -257,8 +250,8 @@ export const DataViewTh: FC<DataViewThProps> = ({
257250 newSize = newSize + delta ;
258251
259252 thRef . current ?. style . setProperty ( 'min-width' , newSize + 'px' ) ;
260- currWidth = newSize ;
261- onResize && onResize ( e , currWidth ) ;
253+ setWidth ( newSize ) ;
254+ onResize && onResize ( e , newSize ) ;
262255 } ;
263256
264257 return (
0 commit comments