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-avatar): announce initials #10755

Merged
merged 1 commit into from
Feb 3, 2025
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
18 changes: 18 additions & 0 deletions packages/main/cypress/specs/Avatar.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Avatar from "../../src/Avatar.js";

describe("Accessibility", () => {
it("checks if initials of avatar are correctly announced", () => {
const INITIALS = "XS";

cy.mount(<Avatar id="interactive-avatar" initials={INITIALS} interactive></Avatar>);

// Store the expected label to compare against
const expectedLabel = `Avatar ${INITIALS}`;

// Check if the aria-label is correctly set
cy.get("#interactive-avatar")
.shadow()
.find(".ui5-avatar-root")
.should("have.attr", "aria-label", expectedLabel);
});
});
4 changes: 3 additions & 1 deletion packages/main/src/Avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ class Avatar extends UI5Element implements ITabbable, IAvatarGroupItem {
return this.accessibleName;
}

return Avatar.i18nBundle.getText(AVATAR_TOOLTIP) || undefined;
const defaultLabel = Avatar.i18nBundle.getText(AVATAR_TOOLTIP);

return this.initials ? `${defaultLabel} ${this.initials}`.trim() : defaultLabel;
}

get hasImage() {
Expand Down