Skip to content

Commit f8e77cb

Browse files
authored
fix(ui5-button): announce aria description (#11264)
Issue: - The `accessibleDescription` text is not getting announced by the screen reader when the ui5-button has it's design attribute set. Solution: - Move the text related to the design property from the aria-describedby to the aria-description attribute. Fixes: #10899
1 parent 9f0d907 commit f8e77cb

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import ButtonBadge from "../../src/ButtonBadge.js";
55
import download from "@ui5/webcomponents-icons/dist/download.js";
66
import employee from "@ui5/webcomponents-icons/dist/employee.js";
77

8+
import {
9+
BUTTON_ARIA_TYPE_REJECT,
10+
} from "../../src/generated/i18n/i18n-defaults.js";
11+
812
describe("Button general interaction", () => {
913
it("tests button's text rendering", () => {
1014
cy.mount(<Button icon={download} design="Negative">Action Bar Button</Button>);
@@ -301,7 +305,6 @@ describe("Accessibility", () => {
301305
});
302306

303307
it("aria-describedby properly applied on the button tag", () => {
304-
const hiddenTextTypeId = "ui5-button-hiddenText-type";
305308
cy.mount(<Button design="Attention">Content</Button>);
306309

307310
cy.get("[ui5-button]")
@@ -310,12 +313,19 @@ describe("Accessibility", () => {
310313
cy.get("@button")
311314
.shadow()
312315
.find("button")
313-
.should("have.attr", "aria-describedby", hiddenTextTypeId);
316+
.should("have.attr", "aria-description", "Warning");
317+
});
318+
319+
it("accessibleDescription in combination with design property applied on the button tag", () => {
320+
cy.mount(<Button design="Negative" accessibleDescription="Decline">Content</Button>);
321+
322+
cy.get("[ui5-button]")
323+
.as("button");
314324

315325
cy.get("@button")
316326
.shadow()
317-
.find(`span[id="${hiddenTextTypeId}"]`)
318-
.should("exist");
327+
.find("button")
328+
.should("have.attr", "aria-description", `${BUTTON_ARIA_TYPE_REJECT.defaultText} Decline`);
319329
});
320330

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

packages/main/src/Button.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ import ButtonBadgeDesign from "./types/ButtonBadgeDesign.js";
3232
import type ButtonAccessibleRole from "./types/ButtonAccessibleRole.js";
3333
import type ButtonBadge from "./ButtonBadge.js";
3434
import ButtonTemplate from "./ButtonTemplate.js";
35-
import { BUTTON_ARIA_TYPE_ACCEPT, BUTTON_ARIA_TYPE_REJECT, BUTTON_ARIA_TYPE_EMPHASIZED } from "./generated/i18n/i18n-defaults.js";
35+
import {
36+
BUTTON_ARIA_TYPE_ACCEPT,
37+
BUTTON_ARIA_TYPE_REJECT,
38+
BUTTON_ARIA_TYPE_EMPHASIZED,
39+
BUTTON_ARIA_TYPE_ATTENTION,
40+
} from "./generated/i18n/i18n-defaults.js";
3641

3742
// Styles
3843
import buttonCss from "./generated/themes/Button.css.js";
@@ -482,6 +487,7 @@ class Button extends UI5Element implements IButton {
482487
"Positive": BUTTON_ARIA_TYPE_ACCEPT,
483488
"Negative": BUTTON_ARIA_TYPE_REJECT,
484489
"Emphasized": BUTTON_ARIA_TYPE_EMPHASIZED,
490+
"Attention": BUTTON_ARIA_TYPE_ATTENTION,
485491
};
486492
}
487493

@@ -519,12 +525,12 @@ class Button extends UI5Element implements IButton {
519525
return getEffectiveAriaLabelText(this);
520526
}
521527

522-
get ariaDescribedbyText() {
523-
return this.hasButtonType ? "ui5-button-hiddenText-type" : undefined;
524-
}
525-
526528
get ariaDescriptionText() {
527-
return this.accessibleDescription === "" ? undefined : this.accessibleDescription;
529+
const ariaDescribedByText = this.hasButtonType ? this.buttonTypeText : "";
530+
const accessibleDescription = this.accessibleDescription || "";
531+
const ariaDescriptionText = `${ariaDescribedByText} ${accessibleDescription}`.trim();
532+
533+
return ariaDescriptionText || undefined;
528534
}
529535

530536
get _isSubmit() {

packages/main/src/ButtonTemplate.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export default function ButtonTemplate(this: Button, injectedProps?: {
3636
aria-controls={this.accessibilityAttributes.controls}
3737
aria-haspopup={this._hasPopup}
3838
aria-label={this.ariaLabelText}
39-
aria-describedby={this.ariaDescribedbyText}
4039
aria-description={this.ariaDescriptionText}
4140
title={this.buttonTitle}
4241
part="button"
@@ -66,10 +65,6 @@ export default function ButtonTemplate(this: Button, injectedProps?: {
6665
/>
6766
}
6867

69-
{this.hasButtonType &&
70-
<span id="ui5-button-hiddenText-type" aria-hidden="true" class="ui5-hidden-text">{this.buttonTypeText}</span>
71-
}
72-
7368
{this.shouldRenderBadge &&
7469
<slot name="badge"/>
7570
}

packages/main/src/i18n/messagebundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ BUTTON_ARIA_TYPE_REJECT=Negative Action
7676
#XACT: ARIA announcement for the emphasized button
7777
BUTTON_ARIA_TYPE_EMPHASIZED=Emphasized
7878

79+
#XACT: ARIA announcement for the warning button
80+
BUTTON_ARIA_TYPE_ATTENTION=Warning
81+
7982
#XACT: Text for Today item in CalendarLegend
8083
CAL_LEGEND_TODAY_TEXT=Today
8184

packages/main/test/pages/Button.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<ui5-button class="button2auto button3auto" design="Transparent">Secondary <span >button</span></ui5-button>
3838
<ui5-button disabled id="button-disabled">Inactive</ui5-button>
3939
<ui5-button design="Positive">Accept</ui5-button>
40-
<ui5-button design="Negative">Decline</ui5-button>
40+
<ui5-button design="Negative" accessible-description="Decline the action">Decline</ui5-button>
4141

4242
<br />
4343
<br />

0 commit comments

Comments
 (0)