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

feat(ui5-switch): accessibleNameRef property implemented #4472

Merged
merged 4 commits into from
Jan 14, 2022
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
1 change: 1 addition & 0 deletions packages/main/src/Switch.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div
class="ui5-switch-root {{classes.main}}"
role="checkbox"
aria-label="{{ariaLabelText}}"
aria-checked="{{checked}}"
aria-disabled="{{ariaDisabled}}"
aria-labelledby="{{_id}}-hiddenText"
Expand Down
18 changes: 18 additions & 0 deletions packages/main/src/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
import "@ui5/webcomponents-icons/dist/accept.js";
import "@ui5/webcomponents-icons/dist/decline.js";
import "@ui5/webcomponents-icons/dist/less.js";
Expand Down Expand Up @@ -95,6 +96,19 @@ const metadata = {
textOff: {
type: String,
},

/**
* Receives id(or many ids) of the elements that label the component.
*
* @type {String}
* @defaultvalue ""
* @public
* @since 1.1.0
*/
accessibleNameRef: {
type: String,
defaultValue: "",
},
},
events: /** @lends sap.ui.webcomponents.main.Switch.prototype */ {

Expand Down Expand Up @@ -248,6 +262,10 @@ class Switch extends UI5Element {
return this.checked ? this.accessibilityOnText : this.accessibilityOffText;
}

get ariaLabelText() {
return getEffectiveAriaLabelText(this);
}

static get dependencies() {
return [Icon];
}
Expand Down
3 changes: 2 additions & 1 deletion packages/main/test/pages/Switch.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ <h3>Default Switch</h3>
</div>

<div class="switch2auto">
<ui5-switch class="switch3auto" text-on="Yes" text-off="No"></ui5-switch>
<ui5-label id="descriptionText">Use GPS location</ui5-label>
<ui5-switch id="switchAccNameRef" accessible-name-ref="descriptionText" class="switch3auto" text-on="Yes" text-off="No"></ui5-switch>
</div>

<h3>No Label</h3>
Expand Down
6 changes: 6 additions & 0 deletions packages/main/test/specs/Switch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ describe("Switch general interaction", async () => {

assert.strictEqual(await field.getProperty("value"), "3", "Change event should not be called any more");
});

it("setting accessible-name-ref on the host is reflected on the button tag", async () => {
const switchEl = await browser.$("#switchAccNameRef").shadow$("div");

assert.strictEqual(await switchEl.getAttribute("aria-label"), "Use GPS location", "Attribute is reflected");
});
});