Skip to content

Commit 8e4eee1

Browse files
committed
use aria-labelledby instead of aria-label
1 parent 92cc562 commit 8e4eee1

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

packages/main/src/components/AnalyticalTable/defaults/Column/Cell.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const Cell = (props: CellInstance) => {
1414

1515
return (
1616
<span
17+
id={`${webComponentsReactProperties.uniqueId}${column.id}${row.id}`}
1718
title={cellContent}
1819
className={webComponentsReactProperties.classes.tableText}
1920
data-column-id-cell-text={column.id}

packages/main/src/components/AnalyticalTable/hooks/useA11y.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ interface UpdatedCellProptypes {
77
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
88
'aria-expanded'?: string;
99
'aria-label'?: string;
10-
'aria-colindex'?: number;
11-
'aria-describedby'?: string;
12-
role?: string;
10+
'aria-colindex': number;
11+
'aria-describedby': string;
12+
'aria-labelledby': string;
13+
role: string;
1314
}
1415

1516
const setCellProps = (cellProps, { cell, instance }: { cell: TableInstance['cell']; instance: TableInstance }) => {
@@ -22,8 +23,8 @@ const setCellProps = (cellProps, { cell, instance }: { cell: TableInstance['cell
2223
'aria-colindex': columnIndex + 1,
2324
role: 'gridcell',
2425
// header label
25-
'aria-describedby': `${uniqueId}${column.id}`,
26-
'aria-label': '',
26+
'aria-describedby': '',
27+
'aria-labelledby': `${uniqueId}${column.id} ${uniqueId}${column.id}${row.id}`,
2728
};
2829

2930
const RowSubComponent = typeof renderRowSubComponent === 'function' ? renderRowSubComponent(row) : undefined;
@@ -38,7 +39,6 @@ const setCellProps = (cellProps, { cell, instance }: { cell: TableInstance['cell
3839

3940
const isFirstUserCol = userCols[0]?.id === column.id || userCols[0]?.accessor === column.accessor;
4041
updatedCellProps['data-is-first-column'] = isFirstUserCol;
41-
updatedCellProps['aria-label'] += value || value === 0 ? `${value} ` : '';
4242

4343
if ((isFirstUserCol && rowIsExpandable) || (row.isGrouped && row.canExpand)) {
4444
updatedCellProps.onKeyDown = row.getToggleRowExpandedProps?.()?.onKeyDown;
@@ -65,11 +65,13 @@ const setCellProps = (cellProps, { cell, instance }: { cell: TableInstance['cell
6565
}
6666
const { cellLabel } = cell.column;
6767
if (typeof cellLabel === 'function') {
68-
cell.cellLabel = '';
68+
const cellHeaderLabel = column.headerLabel || (typeof column.Header === 'string' ? column.Header : '');
69+
const cellValueLabel = value || value === 0 ? `${value} ` : '';
70+
cell.cellLabel = `${cellHeaderLabel} ${cellValueLabel}`;
6971
updatedCellProps['aria-label'] = cellLabel({ cell, instance });
70-
} else {
71-
updatedCellProps['aria-label'] ||= undefined;
72+
updatedCellProps['aria-labelledby'] = undefined;
7273
}
74+
7375
return [cellProps, updatedCellProps];
7476
};
7577

0 commit comments

Comments
 (0)