@@ -5,18 +5,26 @@ import type { ReactTableHooks, TableInstance } from '../types/index.js';
55
66interface UpdatedCellProptypes {
77 onKeyDown ?: KeyboardEventHandler < HTMLDivElement > ;
8- 'aria-expanded' ?: string | boolean ;
8+ 'aria-expanded' ?: string ;
99 'aria-label' ?: string ;
1010 'aria-colindex' ?: number ;
11+ 'aria-describedby' ?: string ;
1112 role ?: string ;
1213}
1314
1415const setCellProps = ( cellProps , { cell, instance } : { cell : TableInstance [ 'cell' ] ; instance : TableInstance } ) => {
1516 const { column, row, value } = cell ;
1617 const columnIndex = instance . visibleColumns . findIndex ( ( { id } ) => id === column . id ) ;
17- const { alwaysShowSubComponent, renderRowSubComponent, translatableTexts , selectionMode, selectionBehavior } =
18+ const { alwaysShowSubComponent, renderRowSubComponent, selectionMode, selectionBehavior, a11yElementIds , uniqueId } =
1819 instance . webComponentsReactProperties ;
19- const updatedCellProps : UpdatedCellProptypes = { 'aria-colindex' : columnIndex + 1 , role : 'gridcell' } ; // aria index is 1 based, not 0
20+ const updatedCellProps : UpdatedCellProptypes = {
21+ // aria index is 1 based, not 0
22+ 'aria-colindex' : columnIndex + 1 ,
23+ role : 'gridcell' ,
24+ // header label
25+ 'aria-describedby' : `${ uniqueId } ${ column . id } ` ,
26+ 'aria-label' : '' ,
27+ } ;
2028
2129 const RowSubComponent = typeof renderRowSubComponent === 'function' ? renderRowSubComponent ( row ) : undefined ;
2230 const rowIsExpandable = row . canExpand || ( RowSubComponent && ! alwaysShowSubComponent ) ;
@@ -30,24 +38,17 @@ const setCellProps = (cellProps, { cell, instance }: { cell: TableInstance['cell
3038
3139 const isFirstUserCol = userCols [ 0 ] ?. id === column . id || userCols [ 0 ] ?. accessor === column . accessor ;
3240 updatedCellProps [ 'data-is-first-column' ] = isFirstUserCol ;
33- updatedCellProps [ 'aria-label' ] = column . headerLabel || ( typeof column . Header === 'string' ? column . Header : '' ) ;
34- updatedCellProps [ 'aria-label' ] &&= `${ updatedCellProps [ 'aria-label' ] } ` ;
3541 updatedCellProps [ 'aria-label' ] += value || value === 0 ? `${ value } ` : '' ;
3642
3743 if ( ( isFirstUserCol && rowIsExpandable ) || ( row . isGrouped && row . canExpand ) ) {
3844 updatedCellProps . onKeyDown = row . getToggleRowExpandedProps ?.( ) ?. onKeyDown ;
39- let ariaLabel = '' ;
40- if ( row . isGrouped ) {
41- ariaLabel += translatableTexts . groupedA11yText + ',' ;
42- }
4345 if ( row . isExpanded ) {
4446 updatedCellProps [ 'aria-expanded' ] = 'true' ;
45- ariaLabel += ` ${ translatableTexts . collapseA11yText } ` ;
47+ updatedCellProps [ 'aria-describedby' ] += ' ' + a11yElementIds . cellCollapseDescId ;
4648 } else {
4749 updatedCellProps [ 'aria-expanded' ] = 'false' ;
48- ariaLabel += ` ${ translatableTexts . expandA11yText } ` ;
50+ updatedCellProps [ 'aria-describedby' ] += ' ' + a11yElementIds . cellExpandDescId ;
4951 }
50- updatedCellProps [ 'aria-label' ] += ariaLabel ;
5152 } else if (
5253 ( selectionMode !== AnalyticalTableSelectionMode . None &&
5354 selectionBehavior !== AnalyticalTableSelectionBehavior . RowSelector &&
@@ -56,16 +57,18 @@ const setCellProps = (cellProps, { cell, instance }: { cell: TableInstance['cell
5657 ) {
5758 if ( row . isSelected ) {
5859 updatedCellProps [ 'aria-selected' ] = 'true' ;
59- updatedCellProps [ 'aria-label ' ] += ` ${ translatableTexts . unselectA11yText } ` ;
60+ updatedCellProps [ 'aria-describedby ' ] = ' ' + a11yElementIds . cellUnselectDescId ;
6061 } else {
6162 updatedCellProps [ 'aria-selected' ] = 'false' ;
62- updatedCellProps [ 'aria-label ' ] += ` ${ translatableTexts . selectA11yText } ` ;
63+ updatedCellProps [ 'aria-describedby ' ] = ' ' + a11yElementIds . cellSelectDescId ;
6364 }
6465 }
6566 const { cellLabel } = cell . column ;
6667 if ( typeof cellLabel === 'function' ) {
67- cell . cellLabel = updatedCellProps [ 'aria-label' ] ;
68+ cell . cellLabel = '' ;
6869 updatedCellProps [ 'aria-label' ] = cellLabel ( { cell, instance } ) ;
70+ } else {
71+ updatedCellProps [ 'aria-label' ] ||= undefined ;
6972 }
7073 return [ cellProps , updatedCellProps ] ;
7174} ;
@@ -108,6 +111,20 @@ const setHeaderProps = (
108111 : translatableTexts . selectAllA11yText ;
109112 }
110113
114+ if ( column . id === '__ui5wcr__internal_selection_column' ) {
115+ updatedProps [ 'aria-label' ] += translatableTexts . selectionHeaderCellText ;
116+ }
117+
118+ if ( column . id === '__ui5wcr__internal_highlight_column' ) {
119+ updatedProps [ 'aria-label' ] += translatableTexts . highlightHeaderCellText ;
120+ }
121+
122+ if ( column . id === '__ui5wcr__internal_navigation_column' ) {
123+ updatedProps [ 'aria-label' ] += translatableTexts . navigationHeaderCellText ;
124+ }
125+
126+ updatedProps [ 'aria-label' ] ||= undefined ;
127+
111128 return [ headerProps , { isFiltered, ...updatedProps } ] ;
112129} ;
113130
0 commit comments