Skip to content

Commit a4ef3cb

Browse files
authored
feat(ui5-table): Add 'accessibleName' and 'accessibleNameRef' properties (#4994)
* Add accessibleName and accessibleNameRef properties * Fix version * Retrigger build
1 parent 3c45c96 commit a4ef3cb

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

packages/main/src/Table.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{{> busyRow}}
66
{{/if}}
77

8-
<table border="0" cellspacing="0" cellpadding="0" @keydown="{{_onkeydown}}" role="table">
8+
<table border="0" cellspacing="0" cellpadding="0" @keydown="{{_onkeydown}}" role="table" aria-label="{{tableAriaLabelText}}">
99
<thead>
1010
<tr
1111
id="{{_columnHeader.id}}"

packages/main/src/Table.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import getNormalizedTarget from "@ui5/webcomponents-base/dist/util/getNormalizedTarget.js";
2424
import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js";
2525
import { getLastTabbableElement, getTabbableElements } from "@ui5/webcomponents-base/dist/util/TabbableElements.js";
26+
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
2627
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
2728
import debounce from "@ui5/webcomponents-base/dist/util/debounce.js";
2829
import isElementInView from "@ui5/webcomponents-base/dist/util/isElementInView.js";
@@ -252,6 +253,32 @@ const metadata = {
252253
defaultValue: TableMode.None,
253254
},
254255

256+
/**
257+
* Defines the accessible aria name of the component.
258+
*
259+
* @type {string}
260+
* @defaultvalue: ""
261+
* @public
262+
* @since 1.3.0
263+
*/
264+
accessibleName: {
265+
type: String,
266+
defaultValue: undefined,
267+
},
268+
269+
/**
270+
* Receives id(or many ids) of the elements that label the component.
271+
*
272+
* @type {string}
273+
* @defaultvalue ""
274+
* @public
275+
* @since 1.3.0
276+
*/
277+
accessibleNameRef: {
278+
type: String,
279+
defaultValue: "",
280+
},
281+
255282
_hiddenColumns: {
256283
type: Object,
257284
multiple: true,
@@ -1117,6 +1144,10 @@ class Table extends UI5Element {
11171144
return `${headerRowText} ${columnsTitle}`;
11181145
}
11191146

1147+
get tableAriaLabelText() {
1148+
return getEffectiveAriaLabelText(this);
1149+
}
1150+
11201151
get ariaLabelSelectAllText() {
11211152
return Table.i18nBundle.getText(ARIA_LABEL_SELECT_ALL_CHECKBOX);
11221153
}

packages/main/test/pages/Table.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<button id="toggleSticky" class="table3auto">Toggle Sticky Column Header</button>
3535
</div>
3636

37-
<ui5-table class="demo-table" id="tbl">
37+
<ui5-table class="demo-table" accessible-name-ref="tableLabel" id="tbl">
3838
<!-- Columns -->
3939
<ui5-table-column id="column-1" slot="columns" width="350px">
4040
<ui5-label>Product</ui5-label>
@@ -133,7 +133,7 @@
133133

134134
<!-- 1 column, but 3 cells -->
135135
<ui5-title>1 column, but 3 cells</ui5-title>
136-
<ui5-table class="demo-table" id="tblLessColumns">
136+
<ui5-table class="demo-table" id="tblLessColumns" accessible-name="Table label">
137137
<ui5-table-column id="column-1" slot="columns">
138138
<ui5-label>City</ui5-label>
139139
</ui5-table-column>

packages/main/test/specs/Table.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ describe("Table general interaction", () => {
7979
"The aria-label value is correct.");
8080
});
8181

82+
describe("Accessibility", () => {
83+
before(async () => {
84+
await browser.url(`http://localhost:${PORT}/test-resources/pages/Table.html`);
85+
});
86+
87+
it("Should apply aria-label from the accessibleName property", async () => {
88+
const table = await browser.$("#tblLessColumns");
89+
const innerTable = await table.shadow$("table");
90+
91+
assert.strictEqual(await innerTable.getAttribute("aria-label"), "Table label", "Table aria-label attribute is correct.");
92+
});
93+
94+
it("Should apply aria-label from the accessibleNameRef property", async () => {
95+
const table = await browser.$("#tbl");
96+
const innerTable = await table.shadow$("table");
97+
const tableLabel = await browser.$("#tableLabel");
98+
99+
assert.strictEqual(await innerTable.getAttribute("aria-label"), await tableLabel.getHTML(false), "Table aria-label attribute is correct.");
100+
});
101+
});
102+
82103
describe("Growing Table on 'More' button press", () => {
83104
it("tests the 'load-more' event", async () => {
84105
await browser.url(`http://localhost:${PORT}/test-resources/pages/TableGrowingWithButton.html`);

0 commit comments

Comments
 (0)