Skip to content

Commit 7007f8e

Browse files
authoredAug 20, 2020
feat(ui5-card): add ariaLabel and ariaLabelledby properties (#2127)
1 parent e0f93fa commit 7007f8e

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
 

‎packages/main/src/Card.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
class="{{classes.main}}"
33
dir="{{effectiveDir}}"
44
role="region"
5+
aria-label="{{ariaLebelText}}"
56
aria-labelledby="{{_id}}-desc {{_id}}-heading">
67
{{#if hasHeader}}
78
<div class="{{classes.header}}"

‎packages/main/src/Card.js

+30
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/getEffectiveAriaLabelText.js";
45
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
56
import CardTemplate from "./generated/templates/CardTemplate.lit.js";
67
import Icon from "./Icon.js";
@@ -111,6 +112,31 @@ const metadata = {
111112
type: Boolean,
112113
},
113114

115+
/**
116+
* Defines the aria-label attribute for the <code>ui5-card</code>
117+
*
118+
* @type {String}
119+
* @since 1.0.0-rc.9
120+
* @private
121+
* @defaultvalue ""
122+
*/
123+
ariaLabel: {
124+
type: String,
125+
},
126+
127+
/**
128+
* Receives id(or many ids) of the elements that label the <code>ui5-card</code>
129+
*
130+
* @type {String}
131+
* @defaultvalue ""
132+
* @private
133+
* @since 1.0.0-rc.9
134+
*/
135+
ariaLabelledby: {
136+
type: String,
137+
defaultValue: "",
138+
},
139+
114140
_headerActive: {
115141
type: Boolean,
116142
noAttribute: true,
@@ -212,6 +238,10 @@ class Card extends UI5Element {
212238
return !!(this.heading || this.subheading || this.status || this.hasAction || this.avatar);
213239
}
214240

241+
get ariaLebelText() {
242+
return getEffectiveAriaLabelText(this);
243+
}
244+
215245
get ariaCardRoleDescription() {
216246
return this.i18nBundle.getText(ARIA_ROLEDESCRIPTION_CARD);
217247
}

‎packages/main/test/pages/Card.html

+19
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@
102102
<ui5-button icon="overflow" slot="action" design="Transparent"></ui5-button>
103103
</ui5-card>
104104

105+
<h3>Test ariaLabel and ariaLabelledBy</h3>
106+
<ui5-card
107+
id="textAreaAriaLabel"
108+
heading="Linked activities (5)"
109+
subheading="quick links"
110+
aria-label="Hello World"
111+
class="myCard">
112+
</ui5-card>
113+
114+
<br>
115+
<ui5-label id="infoText">info text</ui5-label>
116+
117+
<ui5-card
118+
id="textAreaAriaLabelledBy"
119+
aria-labelledby="infoText"
120+
heading="New jobs (5)"
121+
subheading="find one">
122+
</ui5-card>
123+
105124
<script>
106125
card.addEventListener("ui5-headerClick", function (event) {
107126
console.log(event);

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

+13
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,17 @@ describe("Card general interaction", () => {
3232

3333
assert.strictEqual(field.getProperty("value"), "3", "The events count should remain 3 as the header is not interactive.");
3434
});
35+
36+
37+
it("Tests aria-label and aria-labelledby", () => {
38+
const card1 = browser.$("#textAreaAriaLabel").shadow$(".ui5-card-root");
39+
const card2 = browser.$("#textAreaAriaLabelledBy").shadow$(".ui5-card-root");
40+
const EXPECTED_ARIA_LABEL1 = "Hello World";
41+
const EXPECTED_ARIA_LABEL2 = "info text";
42+
43+
assert.strictEqual(card1.getAttribute("aria-label"), EXPECTED_ARIA_LABEL1,
44+
"The aria-label is correctly set internally.");
45+
assert.strictEqual(card2.getAttribute("aria-label"), EXPECTED_ARIA_LABEL2,
46+
"The aria-label is correctly set internally.");
47+
});
3548
});

0 commit comments

Comments
 (0)
Please sign in to comment.