Skip to content

Commit c6f75c7

Browse files
committed
feat(ui5-card): add "accessibleName"
1 parent ebd2065 commit c6f75c7

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

packages/main/src/Card.hbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
class="{{classes.main}}"
33
dir="{{effectiveDir}}"
44
role="region"
5-
aria-label="{{ariaLabelText}}"
6-
aria-labelledby="{{ariaLabelledByCard}}">
5+
aria-label="{{ariaLabelText}}">
76
{{#if hasHeader}}
87
<div class="{{classes.header}}"
98
@click="{{_headerClick}}"
@@ -42,5 +41,4 @@
4241
<section role="group" aria-label="{{ariaCardContentLabel}}">
4342
<slot></slot>
4443
</section>
45-
<span id="{{_id}}-desc" class="ui5-hidden-text">{{ariaCardRoleDescription}}</span>
4644
</div>

packages/main/src/Card.js

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ const metadata = {
6666
action: {
6767
type: HTMLElement,
6868
},
69+
70+
/**
71+
* Defines the accessible name of the component, which is used as the name of the card region and should be unique per card.
72+
* <b>Note:</b> <code>accessibleName</code> should be always set.
73+
*
74+
* @type {String}
75+
* @defaultvalue ""
76+
* @public
77+
* @since 1.0.0-rc.16
78+
*/
79+
accessibleName: {
80+
type: String,
81+
},
6982
},
7083
properties: /** @lends sap.ui.webcomponents.main.Card.prototype */ {
7184

@@ -255,12 +268,39 @@ class Card extends UI5Element {
255268
return !!(this.heading || this.subheading || this.status || this.hasAction || this.avatar);
256269
}
257270

271+
getEffectiveAriaLabelText(el) {
272+
if (!el.accessibleNameRef) {
273+
if (el.accessibleName) {
274+
return el.accessibleName;
275+
}
276+
277+
return undefined;
278+
}
279+
280+
return this.getAriaLabelledByTexts(el);
281+
};
282+
283+
getAriaLabelledByTexts(el, ownerDocument, readyIds = "") {
284+
const ids = (readyIds && readyIds.split(" ")) || el.accessibleNameRef.split(" ");
285+
const owner = ownerDocument || findNodeOwner(el);
286+
let result = "";
287+
288+
ids.forEach((elementId, index) => {
289+
const element = owner.querySelector(`[id='${elementId}']`);
290+
result += `${element ? element.textContent : ""}`;
291+
292+
if (index < ids.length - 1) {
293+
result += " ";
294+
}
295+
});
296+
297+
return result;
298+
};
299+
258300
get ariaLabelText() {
259-
return getEffectiveAriaLabelText(this);
260-
}
261-
262-
get ariaCardRoleDescription() {
263-
return this.i18nBundle.getText(ARIA_ROLEDESCRIPTION_CARD);
301+
const effectiveAriaLabelText = getEffectiveAriaLabelText(this),
302+
effectiveAriaLabel = effectiveAriaLabelText ? ` ${effectiveAriaLabelText}` : "";
303+
return this.i18nBundle.getText(ARIA_ROLEDESCRIPTION_CARD) + effectiveAriaLabel;
264304
}
265305

266306
get ariaCardHeaderRoleDescription() {
@@ -293,10 +333,6 @@ class Card extends UI5Element {
293333
return labels.length !== 0 ? labels.join(" ") : undefined;
294334
}
295335

296-
get ariaLabelledByCard() {
297-
return this.heading ? `${this._id}-heading ${this._id}-desc` : `${this._id}-desc`;
298-
}
299-
300336
get hasAvatar() {
301337
return !!this.avatar.length;
302338
}

packages/main/test/pages/Card.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ <h3>Test ariaLabel and ariaLabelledBy</h3>
107107
id="textAreaAriaLabel"
108108
heading="Linked activities (5)"
109109
subheading="quick links"
110-
aria-label="Hello World"
110+
accessible-name="Hello World"
111111
class="myCard">
112112
</ui5-card>
113113

0 commit comments

Comments
 (0)