Skip to content

Commit 5405e2a

Browse files
authored
Table: make checkbox aria-labels stay the same regardless of checkbox state (#2596)
1 parent 02fabb6 commit 5405e2a

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

.changeset/lovely-goats-work.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hashicorp/design-system-components": patch
3+
---
4+
5+
`Table` - fixed the aria-labels for select row and select all checkboxes so they do not change based on the state of the checkbox.

packages/components/src/components/hds/table/th-selectable.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ export default class HdsTableThSelectable extends Component<HdsTableThSelectable
5757
}
5858

5959
get ariaLabel(): string {
60-
const { selectionAriaLabelSuffix } = this.args;
61-
const prefix = this.isSelected ? 'Deselect' : 'Select';
62-
if (selectionAriaLabelSuffix) {
63-
return `${prefix} ${selectionAriaLabelSuffix}`;
64-
} else {
65-
return prefix;
66-
}
60+
const { selectionAriaLabelSuffix = 'row' } = this.args;
61+
return `Select ${selectionAriaLabelSuffix}`;
6762
}
6863

6964
get ariaSort(): HdsTableThSortOrderLabels | undefined {

showcase/tests/integration/components/hds/table/index-test.js

+34-25
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,36 @@ module('Integration | Component | hds/table/index', function (hooks) {
606606

607607
// aria-labels
608608

609-
test('it renders the expected `aria-label` values for "select all" and rows (based on provided suffix)', async function (assert) {
609+
test('it renders the expected `aria-label` values for "select all" and rows by default', async function (assert) {
610+
setSelectableTableData(this);
611+
await render(hbs`
612+
<Hds::Table
613+
@isSelectable={{true}}
614+
@model={{this.model}}
615+
@columns={{this.columns}}
616+
id="data-test-selectable-table"
617+
>
618+
<:body as |B|>
619+
<B.Tr @selectionKey={{B.data.id}}>
620+
<B.Td>{{B.data.artist}}</B.Td>
621+
<B.Td>{{B.data.album}}</B.Td>
622+
<B.Td>{{B.data.year}}</B.Td>
623+
</B.Tr>
624+
</:body>
625+
</Hds::Table>
626+
`);
627+
628+
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Select all rows');
629+
assert.dom(rowCheckboxesSelector).hasAria('label', 'Select row');
630+
631+
await click(selectAllCheckboxSelector);
632+
await click(rowCheckboxesSelector);
633+
634+
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Select all rows');
635+
assert.dom(rowCheckboxesSelector).hasAria('label', 'Select row');
636+
});
637+
638+
test('it renders the expected `aria-label` for rows with `@selectionAriaLabelSuffix`', async function (assert) {
610639
setSelectableTableData(this);
611640
await render(hbs`
612641
<Hds::Table
@@ -627,31 +656,11 @@ module('Integration | Component | hds/table/index', function (hooks) {
627656
</:body>
628657
</Hds::Table>
629658
`);
630-
const rowCheckboxes = this.element.querySelectorAll(rowCheckboxesSelector);
631-
const firstRowCheckbox = rowCheckboxes[0];
632-
const secondRowCheckbox = rowCheckboxes[1];
633659

634-
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Select all rows');
635660
assert.dom(rowCheckboxesSelector).hasAria('label', 'Select custom suffix');
636-
await click(firstRowCheckbox);
637-
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Select all rows');
638-
assert.dom(firstRowCheckbox).hasAria('label', 'Deselect custom suffix');
639-
assert.dom(secondRowCheckbox).hasAria('label', 'Select custom suffix');
640-
await click(selectAllCheckboxSelector);
641-
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Deselect all rows');
642-
assert.dom(firstRowCheckbox).hasAria('label', 'Deselect custom suffix');
643-
assert.dom(secondRowCheckbox).hasAria('label', 'Deselect custom suffix');
644-
await click(secondRowCheckbox);
645-
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Select all rows');
646-
assert.dom(firstRowCheckbox).hasAria('label', 'Deselect custom suffix');
647-
assert.dom(secondRowCheckbox).hasAria('label', 'Select custom suffix');
648-
await click(secondRowCheckbox);
649-
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Deselect all rows');
650-
assert.dom(firstRowCheckbox).hasAria('label', 'Deselect custom suffix');
651-
assert.dom(secondRowCheckbox).hasAria('label', 'Deselect custom suffix');
652-
await click(selectAllCheckboxSelector);
653-
assert.dom(selectAllCheckboxSelector).hasAria('label', 'Select all rows');
654-
assert.dom(firstRowCheckbox).hasAria('label', 'Select custom suffix');
655-
assert.dom(secondRowCheckbox).hasAria('label', 'Select custom suffix');
661+
662+
await click(rowCheckboxesSelector);
663+
664+
assert.dom(rowCheckboxesSelector).hasAria('label', 'Select custom suffix');
656665
});
657666
});

showcase/tests/integration/components/hds/table/tr-test.js

-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ module('Integration | Component | hds/table/tr', function (hooks) {
4949
hbs`<Hds::Table::Tr id="data-test-table-tr" @isSelectable={{true}} @selectionAriaLabelSuffix="row 123" />`
5050
);
5151
assert.dom(checkboxSelector).hasAria('label', 'Select row 123');
52-
await render(
53-
hbs`<Hds::Table::Tr id="data-test-table-tr" @isSelectable={{true}} @isSelected={{true}} @selectionAriaLabelSuffix="row 123" />`
54-
);
55-
assert.dom(checkboxSelector).hasAria('label', 'Deselect row 123');
5652
});
5753

5854
test('the `th` element has the correct `scope` attribute value provided via `@selectionScope`', async function (assert) {

0 commit comments

Comments
 (0)