@@ -29,6 +29,8 @@ export interface DataViewThResizableProps {
2929 shiftIncrement ?: number ;
3030 /** Aria label for the resize button */
3131 resizeButtonAriaLabel ?: string ;
32+ /** Screenreader text for the column */
33+ screenreaderText ?: string ;
3234}
3335export interface DataViewThProps {
3436 /** Cell content */
@@ -50,14 +52,16 @@ export const DataViewTh: FC<DataViewThProps> = ({
5052} : DataViewThProps ) => {
5153 const thRef = useRef < HTMLTableCellElement > ( null ) ;
5254
55+ const [ width , setWidth ] = useState ( resizableProps ?. width ? resizableProps . width : 0 ) ;
56+
5357 const isResizable = resizableProps ?. isResizable || false ;
5458 const increment = resizableProps ?. increment || 5 ;
5559 const shiftIncrement = resizableProps ?. shiftIncrement || 25 ;
5660 const resizeButtonAriaLabel = resizableProps ?. resizeButtonAriaLabel || `Resize ${ content } ` ;
5761 const onResize = resizableProps ?. onResize || undefined ;
62+ const screenreaderText = resizableProps ?. screenreaderText || `Column ${ width } pixels` ;
5863
5964 const resizeButtonRef = useRef < HTMLButtonElement > ( null ) ;
60- const [ width , setWidth ] = useState ( resizableProps ?. width ? resizableProps . width : 0 ) ;
6165 const setInitialVals = useRef ( true ) ;
6266 const dragOffset = useRef ( 0 ) ;
6367 const isResizing = useRef ( false ) ;
@@ -214,18 +218,19 @@ export const DataViewTh: FC<DataViewThProps> = ({
214218 const handleKeys = ( e : ReactKeyboardEvent ) => {
215219 const key = e . key ;
216220
217- if ( key !== 'Enter' && key !== 'ArrowLeft' && key !== 'ArrowRight' && key !== 'Tab' && key !== 'Space' ) {
221+ if ( key === 'Tab' ) {
222+ isResizing . current = false ;
223+ }
224+
225+ if ( key !== 'ArrowLeft' && key !== 'ArrowRight' ) {
218226 if ( isResizing ) {
219227 e . preventDefault ( ) ;
220228 }
221229 return ;
222230 }
223231 e . preventDefault ( ) ;
224232
225- if ( key === 'Enter' || key === 'Tab' || key === 'Space' ) {
226- onResize && onResize ( e , currWidth ) ;
227- }
228-
233+ isResizing . current = true ;
229234 const isRTL = getLanguageDirection ( thRef . current as HTMLElement ) === 'rtl' ;
230235 const columnRect = thRef . current ?. getBoundingClientRect ( ) ;
231236
@@ -247,6 +252,7 @@ export const DataViewTh: FC<DataViewThProps> = ({
247252 }
248253 }
249254 newSize = newSize + delta ;
255+ onResize && onResize ( e , currWidth ) ;
250256
251257 thRef . current ?. style . setProperty ( 'min-width' , newSize + 'px' ) ;
252258 currWidth = newSize ;
@@ -268,6 +274,11 @@ export const DataViewTh: FC<DataViewThProps> = ({
268274 test
269275 </ Button >
270276 ) }
277+ { isResizable && (
278+ < div aria-live = "polite" className = "pf-v6-screen-reader" >
279+ { screenreaderText }
280+ </ div >
281+ ) }
271282 </ Th >
272283 ) ;
273284} ;
0 commit comments