Skip to content

Commit ee6819f

Browse files
authored
feat(ui5-switch): provide accessible-name attribute support (#4735)
Application developers could now provide additional label text for the aria-label attribute of the ui5-switch root element trough the "accessibleName" property. Fixes: #4147
1 parent 1a33694 commit ee6819f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

packages/main/src/Switch.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ const metadata = {
9797
type: String,
9898
},
9999

100+
/**
101+
* Sets the accessible aria name of the component.
102+
*
103+
* @type {String}
104+
* @defaultvalue: ""
105+
* @public
106+
* @since 1.2.0
107+
*/
108+
accessibleName: {
109+
type: String,
110+
},
111+
100112
/**
101113
* Receives id(or many ids) of the elements that label the component.
102114
*

packages/main/test/pages/Switch.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ <h3>Default Switch</h3>
2222
</div>
2323

2424
<div class="switch2auto">
25+
<ui5-switch id="switchAccName" accessible-name="Geographical location" class="switch3auto" text-on="Yes" text-off="No"></ui5-switch>
2526
<ui5-label id="descriptionText">Use GPS location</ui5-label>
2627
<ui5-switch id="switchAccNameRef" accessible-name-ref="descriptionText" class="switch3auto" text-on="Yes" text-off="No"></ui5-switch>
2728
</div>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ describe("Switch general interaction", async () => {
2828
assert.strictEqual(await field.getProperty("value"), "3", "Change event should not be called any more");
2929
});
3030

31+
it("setting accessible-name on the host is reflected on the button tag", async () => {
32+
const switchEl = await browser.$("#switchAccName").shadow$("div");
33+
34+
assert.strictEqual(await switchEl.getAttribute("role"), "switch", "Proper role attribute is set");
35+
assert.strictEqual(await switchEl.getAttribute("aria-label"), "Geographical location", "Attribute is reflected");
36+
});
37+
3138
it("setting accessible-name-ref on the host is reflected on the button tag", async () => {
3239
const switchEl = await browser.$("#switchAccNameRef").shadow$("div");
3340

0 commit comments

Comments
 (0)