Skip to content

Commit 54fdb3a

Browse files
author
GerganaKremenska
authored
feat(ui5-card): introduce accessibleName property (#4021)
1 parent a172903 commit 54fdb3a

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

packages/main/src/Card.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
class="{{classes}}"
33
dir="{{effectiveDir}}"
44
role="region"
5-
aria-labelledby="{{_id}}-desc">
5+
aria-label="{{_getAriaLabel}}">
66
{{#if _hasHeader}}
77
<div class="ui5-card-header-root">
88
<slot name="header"></slot>
@@ -11,5 +11,4 @@
1111
<div role="group" aria-label="{{_ariaCardContentLabel}}">
1212
<slot></slot>
1313
</div>
14-
<span id="{{_id}}-desc" class="ui5-hidden-text">{{_ariaCardRoleDescription}}</span>
1514
</div>

packages/main/src/Card.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
4+
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
45
import CardTemplate from "./generated/templates/CardTemplate.lit.js";
56
import Icon from "./Icon.js";
67

@@ -47,6 +48,18 @@ const metadata = {
4748
},
4849
properties: /** @lends sap.ui.webcomponents.main.Card.prototype */ {
4950

51+
/**
52+
* Defines the accessible name of the component, which is used as the name of the card region and should be unique per card.
53+
* <b>Note:</b> <code>accessibleName</code> should be always set.
54+
*
55+
* @type {String}
56+
* @defaultvalue ""
57+
* @public
58+
* @since 1.0.0-rc.16
59+
*/
60+
accessibleName: {
61+
type: String,
62+
},
5063
},
5164
events: /** @lends sap.ui.webcomponents.main.Card.prototype */ {
5265

@@ -116,8 +129,10 @@ class Card extends UI5Element {
116129
return !!this.header.length;
117130
}
118131

119-
get _ariaCardRoleDescription() {
120-
return this.i18nBundle.getText(ARIA_ROLEDESCRIPTION_CARD);
132+
get _getAriaLabel() {
133+
const effectiveAriaLabelText = getEffectiveAriaLabelText(this),
134+
effectiveAriaLabel = effectiveAriaLabelText ? ` ${effectiveAriaLabelText}` : "";
135+
return this.i18nBundle.getText(ARIA_ROLEDESCRIPTION_CARD) + effectiveAriaLabel;
121136
}
122137

123138
get _ariaCardContentLabel() {

packages/main/test/pages/Card.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@
203203
</ui5-list>
204204
</ui5-card>
205205

206+
<ui5-card id="textCard" accessible-name="Internships">
207+
<ui5-card-header slot="header" id="header4" title-text="New Internships">
208+
</ui5-card-header>
209+
</ui5-card>
206210
<script>
207211
function onClick(event) {
208212
console.log(event);

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ describe("Card general interaction", () => {
4141
assert.strictEqual(await field.getProperty("value"), "3", "The events count should remain 3 as the header is not interactive.");
4242
});
4343

44-
it("tests aria-labelledby", async () => {
44+
it("tests aria-label", async () => {
4545
const card = await browser.$("#textAreaAriaLabel").shadow$(".ui5-card-root");
46-
const cardId = await browser.$("#textAreaAriaLabel").getProperty("_id");
47-
const EXPECTED_ARIA_LABELLEDBY_CARD = `${cardId}-desc`;
4846

49-
assert.strictEqual(await card.getAttribute("aria-labelledby"), EXPECTED_ARIA_LABELLEDBY_CARD,
47+
assert.strictEqual(await card.getAttribute("aria-label"), "Card",
5048
"The aria-labelledby of card is correctly set.");
5149
})
5250

@@ -86,6 +84,17 @@ describe("CardHeader", () => {
8684
"The aria-labelledby is correctly set.");
8785
assert.strictEqual(await header2.getAttribute("aria-labelledby"), EXPECTED_ARIA_LABELLEDBY_HEADER2,
8886
"The aria-labelledby is correctly set.");
89-
})
87+
});
88+
});
89+
describe("Card Accessibility", () => {
90+
before(async () => {
91+
await browser.url(`http://localhost:${PORT}/test-resources/pages/Card.html`);
92+
});
9093

94+
it("test accessibleName", async () => {
95+
const card = await browser.$("#textCard").shadow$(".ui5-card-root");
96+
97+
assert.strictEqual(await card.getAttribute("aria-label"), "Card Internships",
98+
"The aria-label is correctly when accessibleName is used.");
99+
});
91100
});

0 commit comments

Comments
 (0)