Skip to content

Commit 684f1fc

Browse files
authored
fix(ui5-button): announce the text node properly (#12077)
fix(ui5-button): announce the text node properly Issue: - The inner text of the button wasn't announced when the design property was set. Solution: - The inner text is now part of the aria-label attribute alongside the design type text. Fixes: #12037
1 parent 72bcea7 commit 684f1fc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ describe("Accessibility", () => {
336336
.should("not.have.attr", "title");
337337
});
338338

339+
it("aria-label is properly applied on the button tag", () => {
340+
cy.mount(<Button design="Emphasized">Action</Button>);
341+
342+
cy.get("[ui5-button]")
343+
.shadow()
344+
.find("button")
345+
.as("button");
346+
347+
cy.get("@button")
348+
.should("have.attr", "aria-label", "Action Emphasized");
349+
});
350+
339351
it("aria-expanded is properly applied on the button tag", () => {
340352
cy.mount(<Button icon="home" design="Emphasized">Action Bar Button</Button>);
341353

packages/main/src/Button.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,12 @@ class Button extends UI5Element implements IButton {
625625
}
626626

627627
get ariaLabelText() {
628+
const textContent = this.textContent || "";
628629
const ariaLabelText = getEffectiveAriaLabelText(this) || "";
629630
const typeLabelText = this.hasButtonType ? this.buttonTypeText : "";
630631
const internalLabelText = this.effectiveBadgeDescriptionText || "";
631632

632-
const labelParts = [ariaLabelText, typeLabelText, internalLabelText].filter(part => part);
633+
const labelParts = [textContent, ariaLabelText, typeLabelText, internalLabelText].filter(part => part);
633634
return labelParts.join(" ");
634635
}
635636

0 commit comments

Comments
 (0)