Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiTable][a11y] select row Checkbox elements must have correct labels #7672

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/upcoming/7672.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Accessibility**

- Improved `EuiBasicTable` and `EuiInMemoryTable`'s selection checkboxes to have unique aria-labels per row
20 changes: 10 additions & 10 deletions i18ntokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@
},
{
"token": "euiBasicTable.selectThisRow",
"defString": "Select this row",
"defString": "Select row {index}",
"highlighting": "string",
"loc": {
"start": {
"line": 1103,
"line": 1109,
"column": 8,
"index": 30673
"index": 30781
},
"end": {
"line": 1103,
"column": 79,
"index": 30744
"line": 1113,
"column": 9,
"index": 30936
}
},
"filepath": "src/components/basic_table/basic_table.tsx"
Expand All @@ -149,14 +149,14 @@
"highlighting": "string",
"loc": {
"start": {
"line": 1329,
"line": 1339,
"column": 8,
"index": 37489
"index": 37663
},
"end": {
"line": 1333,
"line": 1343,
"column": 9,
"index": 37648
"index": 37822
}
},
"filepath": "src/components/basic_table/basic_table.tsx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="Select this row"
aria-label="Select row 1"
class="euiCheckbox__input"
data-test-subj="checkboxSelectRow-1"
id="__table_generated-id_selection_column_1-checkbox"
title="Select this row"
title="Select row 1"
type="checkbox"
/>
<div
Expand Down Expand Up @@ -377,11 +377,11 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="Select this row"
aria-label="Select row 2"
class="euiCheckbox__input"
data-test-subj="checkboxSelectRow-2"
id="__table_generated-id_selection_column_2-checkbox"
title="Select this row"
title="Select row 2"
type="checkbox"
/>
<div
Expand Down Expand Up @@ -483,11 +483,11 @@ exports[`EuiBasicTable renders (kitchen sink) with pagination, selection, sortin
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="Select this row"
aria-label="Select row 3"
class="euiCheckbox__input"
data-test-subj="checkboxSelectRow-3"
id="__table_generated-id_selection_column_3-checkbox"
title="Select this row"
title="Select row 3"
type="checkbox"
/>
<div
Expand Down
20 changes: 15 additions & 5 deletions src/components/basic_table/basic_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ export class EuiBasicTable<T extends object = any> extends Component<
hasPagination(this.props) && this.pageSize > 0
? this.props.pagination.pageIndex * this.pageSize + index
: index;
return this.renderItemRow(item, tableItemIndex);
return this.renderItemRow(item, tableItemIndex, index);
});
}

Expand Down Expand Up @@ -950,7 +950,7 @@ export class EuiBasicTable<T extends object = any> extends Component<
);
}

renderItemRow(item: T, rowIndex: number) {
renderItemRow(item: T, rowIndex: number, displayedRowIndex: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice job with the variable naming here - I love how it clearly distinguishes the difference between the two passed index parameters!

const { columns, selection, rowHeader, itemIdToExpandedRowMap } =
this.props;

Expand All @@ -974,7 +974,8 @@ export class EuiBasicTable<T extends object = any> extends Component<
const [checkboxCell, isDisabled] = this.renderItemSelectionCell(
itemId,
item,
selected
selected,
displayedRowIndex
);
cells.push(checkboxCell);
rowSelectionDisabled = !!isDisabled;
Expand Down Expand Up @@ -1075,7 +1076,12 @@ export class EuiBasicTable<T extends object = any> extends Component<
);
}

renderItemSelectionCell(itemId: ItemId<T>, item: T, selected: boolean) {
renderItemSelectionCell(
itemId: ItemId<T>,
item: T,
selected: boolean,
displayedRowIndex: number
) {
const { selection } = this.props;
const key = `_selection_column_${itemId}`;
const checked = selected;
Expand All @@ -1100,7 +1106,11 @@ export class EuiBasicTable<T extends object = any> extends Component<
};
return [
<EuiTableRowCellCheckbox key={key}>
<EuiI18n token="euiBasicTable.selectThisRow" default="Select this row">
<EuiI18n
token="euiBasicTable.selectThisRow"
default="Select row {index}"
values={{ index: displayedRowIndex + 1 }}
>
{(selectThisRow: string) => (
<EuiCheckbox
id={`${this.tableId}${key}-checkbox`}
Expand Down
Loading