Skip to content

Commit 68e6a3e

Browse files
authored
fix(ui5-button): prioritize accessibleName over button text in aria-label (#12473)
When both text content and accessibleName are provided, the aria-label should use only the accessibleName value plus button type text, not concatenate both text content and accessibleName. Fixes #12398
1 parent a4ec76e commit 68e6a3e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/main/cypress/specs/Button.cy.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ describe("Accessibility", () => {
348348
.should("have.attr", "aria-label", "Action Emphasized");
349349
});
350350

351+
it("aria-label uses accessibleName when both text and accessibleName are provided", () => {
352+
cy.mount(<Button design="Emphasized" accessibleName="Custom Action Label">Button Text</Button>);
353+
354+
cy.get("[ui5-button]")
355+
.shadow()
356+
.find("button")
357+
.as("button");
358+
359+
cy.get("@button")
360+
.should("have.attr", "aria-label", "Custom Action Label Emphasized");
361+
});
362+
351363
it("aria-expanded is properly applied on the button tag", () => {
352364
cy.mount(<Button icon="home" design="Emphasized">Action Bar Button</Button>);
353365

packages/main/src/Button.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,14 @@ class Button extends UI5Element implements IButton {
626626
}
627627

628628
get ariaLabelText() {
629+
const effectiveAriaLabelText = getEffectiveAriaLabelText(this) || "";
629630
const textContent = this.textContent || "";
630-
const ariaLabelText = getEffectiveAriaLabelText(this) || "";
631631
const typeLabelText = this.hasButtonType ? this.buttonTypeText : "";
632632
const internalLabelText = this.effectiveBadgeDescriptionText || "";
633633

634-
const labelParts = [textContent, ariaLabelText, typeLabelText, internalLabelText].filter(part => part);
634+
// Use either the effective aria label text (if accessibleName is provided) or the button's text content
635+
const mainLabelText = effectiveAriaLabelText || textContent;
636+
const labelParts = [mainLabelText, typeLabelText, internalLabelText].filter(part => part);
635637
return labelParts.join(" ");
636638
}
637639

0 commit comments

Comments
 (0)