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

fix(ui5-card): correct aria-labelledBy to card and header #2577

Merged
merged 5 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions packages/main/src/Card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
dir="{{effectiveDir}}"
role="region"
aria-label="{{ariaLabelText}}"
aria-labelledby="{{_id}}-desc {{_id}}-heading">
aria-labelledby="{{ariaLabelledByCard}}">
{{#if hasHeader}}
<div class="{{classes.header}}"
@click="{{_headerClick}}"
@keydown="{{_headerKeydown}}"
@keyup="{{_headerKeyup}}"
role="{{ariaHeaderRole}}"
aria-labelledby="{{_id}}-subheading {{_id}}-status"
aria-labelledby="{{ariaLabelledByHeader}}"
aria-level="{{ariaLevel}}"
aria-roledescription="{{ariaCardHeaderRoleDescription}}"
tabindex="0">

{{#if hasAvatar}}
<div class="ui5-card-avatar" aria-label="{{ariaCardAvatarLabel}}">
<div id="{{_id}}-avatar" class="ui5-card-avatar" aria-label="{{ariaCardAvatarLabel}}">
<slot name="avatar"></slot>
</div>
{{/if}}
Expand Down
22 changes: 22 additions & 0 deletions packages/main/src/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,28 @@ class Card extends UI5Element {
return this.i18nBundle.getText(ARIA_LABEL_CARD_CONTENT);
}

get ariaLabelledByHeader() {
const labels = [];

if (this.subheading) {
labels.push(`${this._id}-subheading`);
}

if (this.status) {
labels.push(`${this._id}-status`);
}

if (this.hasAvatar) {
labels.push(`${this._id}-avatar`);
}

return labels.length !== 0 ? labels.join(" ") : undefined;
}

get ariaLabelledByCard() {
return this.heading ? `${this._id}-heading ${this._id}-desc` : `${this._id}-desc`;
}

get hasAvatar() {
return !!this.avatar.length;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/test/pages/Card.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</ui5-list>
</ui5-card>

<ui5-card heading="Quick Links" subheading="quick links">
<ui5-card id="card3" heading="Quick Links" subheading="quick links">
<ui5-list id="myList3" separators="Inner">
<ui5-li icon="horizontal-bullet-chart" >Template Based Segmentation</ui5-li>
<ui5-li icon="opportunity" >Segmentation Models</ui5-li>
Expand Down
25 changes: 24 additions & 1 deletion packages/main/test/specs/Card.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("Card general interaction", () => {
assert.strictEqual(field.getProperty("value"), "3", "The events count should remain 3 as the header is not interactive.");
});

it("Tests aria-label and aria-labelledby", () => {
it("Tests aria-label", () => {
const card1 = browser.$("#textAreaAriaLabel").shadow$(".ui5-card-root");
const card2 = browser.$("#textAreaAriaLabelledBy").shadow$(".ui5-card-root");
const EXPECTED_ARIA_LABEL1 = "Hello World";
Expand All @@ -44,4 +44,27 @@ describe("Card general interaction", () => {
assert.strictEqual(card2.getAttribute("aria-label"), EXPECTED_ARIA_LABEL2,
"The aria-label is correctly set internally.");
});

it("Tests internal aria-labelledby labeling", () => {
const card1 = browser.$("#card2").shadow$(".ui5-card-root");
const header = browser.$("#card2").shadow$(".ui5-card-header");
const card2 = browser.$("#card3").shadow$(".ui5-card-root");
const header2 = browser.$("#card3").shadow$(".ui5-card-header");
const EXPECTED_ARIA_LABELLEDBY_CARD = "ui5wc_20-heading ui5wc_20-desc";
Copy link
Member

@ilhan007 ilhan007 Dec 14, 2020

Choose a reason for hiding this comment

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

To make the test more robust you can use the built-in "_id" property - card1.getProperty("_id"), card2.getProperty("_id") to get these parts ui5wc_20 and ui5wc_21.
Because, if someone adds more cards in the test page, these cards might get different IDs, f.e. ui5wc_23, ui5wc_24 as these numbers depend on the component's definition order and every time the test might need to be adjusted as it would fail.

const card1Id = card1.getProperty("_id");
const EXPECTED_ARIA_LABELLEDBY_CARD = `${card1Id}-heading ${card1Id}-desc`;
const EXPECTED_ARIA_LABELLEDBY_HEADER = "${card1Id}-subheading ${card1Id}-status ${card1Id}-avatar";

const card2Id = card2.getProperty("_id");
...

Also, for reference how "_id" is used you can see NotificationList.spec.js -> "tests List Group Item ACC ariaLabelledBy".

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks for the feedback. :) applied to the change.

const EXPECTED_ARIA_LABELLEDBY_HEADER = "ui5wc_20-subheading ui5wc_20-status ui5wc_20-avatar";
const EXPECTED_ARIA_LABELLEDBY_CARD2 = "ui5wc_21-heading ui5wc_21-desc";
const EXPECTED_ARIA_LABELLEDBY_HEADER2 = "ui5wc_21-subheading";




GerganaKremenska marked this conversation as resolved.
Show resolved Hide resolved
assert.strictEqual(card1.getAttribute("aria-labelledby"), EXPECTED_ARIA_LABELLEDBY_CARD,
"The aria-labelledby of card is correctly set internally.");
assert.strictEqual(header.getAttribute("aria-labelledby"), EXPECTED_ARIA_LABELLEDBY_HEADER,
"The aria-labelledby is correctly set internally.");
assert.strictEqual(card2.getAttribute("aria-labelledby"), EXPECTED_ARIA_LABELLEDBY_CARD2,
"The aria-labelledby of card is correctly set internally.");
assert.strictEqual(header2.getAttribute("aria-labelledby"), EXPECTED_ARIA_LABELLEDBY_HEADER2,
"The aria-labelledby is correctly set internally.");
});
});