Skip to content

fix(ui5-button): announce accessible name #11396

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

unazko
Copy link
Contributor

@unazko unazko commented Apr 23, 2025

Issue:

  • The badge wasn't announced at all when an accessible-name attribute is provided
    for the ui5-button. The reason behind this behaviour is that the screen reader doesn't
    read the inner text nodes of the root button node when the same has aria-label attribute.

Solution:

  • The proper badge description text is placed into the aria-label attribute of the root
    button element. As a result the screen reader won't rely on the inner text content
    for the announcements.
  • Additionally the design description is also moved into the aria-label attribute,
    in order to keep a proper announcement order.

Fixes: #11350

@unazko unazko marked this pull request as ready for review April 23, 2025 14:49
@unazko unazko requested review from hinzzx and Copilot April 25, 2025 07:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an accessibility issue for the ui5-button by updating how the accessible name and badge description are announced. Key changes include:

  • Updating the aria-label generation by combining the accessible name, button type, and badge description.
  • Adjusting the aria-description handling to return undefined when empty.
  • Modifying the Cypress tests to validate the updated accessibility attributes.

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/main/src/Button.ts Updates aria-label and badge description generation for improved announcement.
packages/main/cypress/specs/Button.cy.tsx Updates tests to reflect new accessibility attribute behaviors.
Files not reviewed (1)
  • packages/main/src/i18n/messagebundle.properties: Language not supported
Comments suppressed due to low confidence (1)

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

  • Consider adding additional tests for edge cases such as badge values like "0" or unexpected non-numeric texts to ensure that the aria-label formation handles all scenarios robustly.
.should("have.attr", "aria-label", `Download 999+ items`);

Comment on lines +529 to +531
const internalLabelText = `${typeLabelText} ${this.effectiveBadgeDescriptionText}`.trim();

return `${ariaLabelText} ${internalLabelText}`.trim();
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider handling cases where both the effective aria label and button type text are empty to avoid potential extra spaces, even though trim() is used; a more modular construction of the final label might improve future maintenance.

Suggested change
const internalLabelText = `${typeLabelText} ${this.effectiveBadgeDescriptionText}`.trim();
return `${ariaLabelText} ${internalLabelText}`.trim();
const internalLabelText = this.effectiveBadgeDescriptionText || "";
// Combine non-empty components into an array and join with a space
const labelParts = [ariaLabelText, typeLabelText, internalLabelText].filter(part => part);
return labelParts.join(" ");

Copilot uses AI. Check for mistakes.

return "";
}

const badgeEffectiveText = this.badge[0].effectiveText;

Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Adding a comment to explain the rationale for using distinct i18n keys (BUTTON_BADGE_ONE_ITEM vs. BUTTON_BADGE_MANY_ITEMS) for singular and plural badge values would help improve code clarity.

Suggested change
// Use distinct i18n keys for singular and plural badge values to ensure proper localization.
// Some languages have different grammatical rules for singular and plural forms,
// so separate keys (BUTTON_BADGE_ONE_ITEM and BUTTON_BADGE_MANY_ITEMS) are necessary.

Copilot uses AI. Check for mistakes.

@@ -304,28 +304,47 @@ describe("Accessibility", () => {
.should("have.attr", "role", "button");
});

it("aria-describedby properly applied on the button tag", () => {
cy.mount(<Button design="Attention">Content</Button>);
it("accessibleDescription in combination with design property applied on the button tag", () => {
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Ensure that the test description accurately reflects the new behavior, verifying that the aria-description is set as expected for different design scenarios.

Suggested change
it("accessibleDescription in combination with design property applied on the button tag", () => {
it("verifies that accessibleDescription is correctly applied as aria-description on the button tag, in combination with the design property", () => {

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ui5-button]: Badge content is ignored when accessible-name is used
1 participant