Skip to content

Commit b444706

Browse files
authored
fix(ui5-button): move button type text from aria-label to aria-description (#12474)
When a button has design property (like Emphasized, Negative), the type text should be in aria-description instead of aria-label for better semantic separation. Updated tests to verify the new behavior. Fixes #12413
1 parent a52e4c1 commit b444706

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,22 @@ describe("Accessibility", () => {
345345
.as("button");
346346

347347
cy.get("@button")
348-
.should("have.attr", "aria-label", "Action Emphasized");
348+
.should("have.attr", "aria-label", "Action");
349+
350+
cy.get("@button")
351+
.should("have.attr", "aria-description", "Emphasized");
349352
});
350353

351354
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>);
355+
cy.mount(<Button accessibleName="Custom Action Label">Button Text</Button>);
353356

354357
cy.get("[ui5-button]")
355358
.shadow()
356359
.find("button")
357360
.as("button");
358361

359362
cy.get("@button")
360-
.should("have.attr", "aria-label", "Custom Action Label Emphasized");
363+
.should("have.attr", "aria-label", "Custom Action Label");
361364
});
362365

363366
it("aria-expanded is properly applied on the button tag", () => {
@@ -424,7 +427,7 @@ describe("Accessibility", () => {
424427
.as("button");
425428

426429
cy.get("@button")
427-
.should("have.attr", "aria-description", "Decline");
430+
.should("have.attr", "aria-description", "Decline Negative Action");
428431
});
429432

430433

@@ -455,7 +458,10 @@ describe("Accessibility", () => {
455458
.as("button");
456459

457460
cy.get("@button")
458-
.should("have.attr", "aria-label", `Download ${BUTTON_ARIA_TYPE_EMPHASIZED.defaultText} 1 item`);
461+
.should("have.attr", "aria-label", `Download 1 item`);
462+
463+
cy.get("@button")
464+
.should("have.attr", "aria-description", BUTTON_ARIA_TYPE_EMPHASIZED.defaultText);
459465
});
460466

461467
it("setting accessible-name-ref on the host is reflected on the button tag", () => {

packages/main/src/Button.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,17 +628,20 @@ class Button extends UI5Element implements IButton {
628628
get ariaLabelText() {
629629
const effectiveAriaLabelText = getEffectiveAriaLabelText(this) || "";
630630
const textContent = this.textContent || "";
631-
const typeLabelText = this.hasButtonType ? this.buttonTypeText : "";
632631
const internalLabelText = this.effectiveBadgeDescriptionText || "";
633632

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

640639
get ariaDescriptionText() {
641-
return this.accessibleDescription === "" ? undefined : this.accessibleDescription;
640+
const accessibleDescription = this.accessibleDescription === "" ? undefined : this.accessibleDescription;
641+
const typeLabelText = this.hasButtonType ? this.buttonTypeText : "";
642+
643+
const descriptionParts = [accessibleDescription, typeLabelText].filter(part => part);
644+
return descriptionParts.length > 0 ? descriptionParts.join(" ") : undefined;
642645
}
643646

644647
get _computedAccessibilityAttributes(): ButtonAccessibilityAttributes {

0 commit comments

Comments
 (0)