@@ -149,12 +149,14 @@ export function Table<T extends Record<string, unknown> = Record<string, unknown
149149 onRowClick,
150150 className,
151151 ref,
152- onKeyDown,
153152 labels,
154153 ...rest
155154} : TableProps < T > ) {
156155 const ctx = useComponentLibraryStrings ( ) ;
157- const l = { ...DEFAULT_TABLE_LABELS , ...ctx . table , ...labels } ;
156+ const l = useMemo (
157+ ( ) => ( { ...DEFAULT_TABLE_LABELS , ...ctx . table , ...labels } ) ,
158+ [ ctx . table , labels ] ,
159+ ) ;
158160
159161 const [ sortKey , setSortKey ] = useState < string | null > ( null ) ;
160162 const [ sortDir , setSortDir ] = useState < SortDirection > ( 'none' ) ;
@@ -220,7 +222,7 @@ export function Table<T extends Record<string, unknown> = Record<string, unknown
220222 setAnnouncement ( '' ) ;
221223 }
222224 } ,
223- [ data , columns ] ,
225+ [ data , columns , l ] ,
224226 ) ;
225227
226228 /* Row interaction — selection toggle + optional onRowClick callback */
@@ -235,7 +237,7 @@ export function Table<T extends Record<string, unknown> = Record<string, unknown
235237 }
236238 onRowClick ?.( row , globalIdx ) ;
237239 } ,
238- [ selectable , onRowClick ] ,
240+ [ selectable , onRowClick , l . rowSelected , l . selectionCleared ] ,
239241 ) ;
240242
241243 const handleRowKeyDown = useCallback (
@@ -248,16 +250,15 @@ export function Table<T extends Record<string, unknown> = Record<string, unknown
248250 [ handleRowInteraction ] ,
249251 ) ;
250252
251- /* Escape on the wrapper clears row selection */
252- const handleWrapperKeyDown = useCallback (
253- ( e : KeyboardEvent < HTMLDivElement > ) => {
253+ /* Escape on the table clears row selection */
254+ const handleTableKeyDown = useCallback (
255+ ( e : KeyboardEvent < HTMLTableElement > ) => {
254256 if ( e . key === 'Escape' && selectedRow !== null ) {
255257 setSelectedRow ( null ) ;
256258 setAnnouncement ( l . selectionCleared ) ;
257259 }
258- onKeyDown ?.( e ) ;
259260 } ,
260- [ selectedRow , onKeyDown ] ,
261+ [ selectedRow , l . selectionCleared ] ,
261262 ) ;
262263
263264 /* Resize handler */
@@ -298,8 +299,12 @@ export function Table<T extends Record<string, unknown> = Record<string, unknown
298299 ...( headerTextColor ? { '--table-header-color' : headerTextColor } : { } ) ,
299300 } as CSSProperties ;
300301
302+ const tableInteractionProps = selectable
303+ ? { role : 'grid' as const , onKeyDown : handleTableKeyDown }
304+ : { } ;
305+
301306 return (
302- < div ref = { ref } className = { classNames } onKeyDown = { handleWrapperKeyDown } { ...rest } >
307+ < div ref = { ref } className = { classNames } { ...rest } >
303308 { /* Screen reader live region for search results and selection state */ }
304309 < div
305310 id = { liveRegionId }
@@ -340,7 +345,7 @@ export function Table<T extends Record<string, unknown> = Record<string, unknown
340345 . join ( ' ' ) }
341346 style = { tableStyle }
342347 aria-busy = { loading || undefined }
343- role = { selectable ? 'grid' : undefined }
348+ { ... tableInteractionProps }
344349 >
345350 { caption && < caption className = { styles . caption } > { caption } </ caption > }
346351 < thead className = { styles . thead } >
0 commit comments