Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions packages/main/cypress/specs/Button.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,4 +577,61 @@ describe("Accessibility", () => {
cy.get("@tag")
.should("have.text", "999+");
});

it("accessibilityInfo returns correct properties for different button states", () => {
cy.mount(<Button design="Emphasized" accessibleDescription="Submit form">Submit</Button>);

cy.get<Button>("[ui5-button]")
.then($button => {
const button = $button.get(0);
const info = button.accessibilityInfo;

expect(info.description).to.include("Submit form");
expect(info.description).to.include(Button.i18nBundle.getText(BUTTON_ARIA_TYPE_EMPHASIZED));
expect(info.role).to.equal("button");
expect(info.disabled).to.be.false;
});
});

it("accessibilityInfo reflects custom role and disabled state", () => {
cy.mount(<Button accessibleRole="Link" disabled>Navigate</Button>);

cy.get<Button>("[ui5-button]")
.then($button => {
const button = $button.get(0);
const info = button.accessibilityInfo;

expect(info.role).to.equal("link");
expect(info.disabled).to.be.true;
expect(info.description).to.be.undefined;
});
});

it("accessibilityInfo updates when properties change", () => {
cy.mount(<Button>Click me</Button>);

cy.get<Button>("[ui5-button]")
.as("button");

cy.get<Button>("@button")
.then($button => {
const button = $button.get(0);
expect(button.accessibilityInfo.disabled).to.be.false;
expect(button.accessibilityInfo.role).to.equal("button");

button.disabled = true;
button.accessibleRole = "Link";
button.design = "Negative";
});

cy.get<Button>("@button")
.then($button => {
const button = $button.get(0);
const info = button.accessibilityInfo;

expect(info.disabled).to.be.true;
expect(info.role).to.equal("link");
expect(info.description).to.include("Negative Action");
});
});
});
8 changes: 8 additions & 0 deletions packages/main/src/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,14 @@ class Button extends UI5Element implements IButton {
};
}

get accessibilityInfo() {
return {
description: this.ariaDescriptionText,
role: this.effectiveAccRole,
disabled: this.disabled,
};
}

get effectiveBadgeDescriptionText() {
if (!this.shouldRenderBadge) {
return "";
Expand Down
Loading