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-link): provide accessible-name support #4711

Merged
merged 9 commits into from
Feb 10, 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
17 changes: 14 additions & 3 deletions packages/main/src/Link.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
import { getAriaLabelledByTexts } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import LinkDesign from "./types/LinkDesign.js";
import WrappingType from "./types/WrappingType.js";
Expand Down Expand Up @@ -102,6 +102,18 @@ const metadata = {
defaultValue: WrappingType.None,
},

/**
* Defines the accessible aria name of the component.
*
* @type {string}
* @defaultvalue ""
* @public
* @since 1.2.0
*/
accessibleName: {
type: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

There is default value in the documentation, but not in here.

},

/**
* Receives id(or many ids) of the elements that label the input
*
Expand All @@ -112,7 +124,6 @@ const metadata = {
*/
accessibleNameRef: {
type: String,
defaultValue: "",
},

/**
Expand Down Expand Up @@ -289,7 +300,7 @@ class Link extends UI5Element {
}

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

get hasLinkType() {
Expand Down
5 changes: 3 additions & 2 deletions packages/main/test/pages/Link.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<section class="group">
<h2>cross-origin</h2>
<ui5-link href="https://www.google.com" target="_blank" id="link">link</ui5-link><span>native span</span>
<ui5-link href="https://www.google.com" target="_blank" id="linkAccName" accessible-name="more info">link with accessible-name</ui5-link><span>native span</span>
</section>

<section class="group">
Expand Down Expand Up @@ -101,13 +102,13 @@ <h2>Link opens a dialog</h2>
<ui5-label for="email" type="Email" required>Email: </ui5-label>
<ui5-input id="email"></ui5-input>
</div>

<div>
<ui5-label for="password" required>Password: </ui5-label>
<ui5-input id="password" type="Password"></ui5-input>
</div>
</section>

<div slot="footer" class="dialog-footer">
<div style="flex: 1;"></div>
<ui5-button id="closeDialogButton" design="Emphasized">Sign in</ui5-button>
Expand Down
6 changes: 6 additions & 0 deletions packages/main/test/specs/Link.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ describe("General API", () => {
assert.strictEqual(await link.shadow$("a").getAttribute("aria-haspopup"), "Dialog", "Proper aria-haspopup attribute is set");
});

it("setting accessible-name applied on the host element is reflected on the anchor tag", async () => {
const link = await browser.$("#linkAccName");

assert.strictEqual(await link.shadow$("a").getAttribute("aria-label"), "more info", "Attribute is reflected");
});

});