Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
62 changes: 61 additions & 1 deletion packages/main/cypress/specs/Icon.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,64 @@ describe("Icon general interaction", () => {
.find(".ui5-icon-root")
.should("have.attr", "role", "img");
});
});

it("Tests accessibilityInfo getter", () => {
const interactiveMode = "Interactive";
const imageMode = "Image";
const decorativeMode = "Decorative";
const accessibleName = "Test Icon";

// Test with Interactive mode
cy.mount(
<Icon
name="add-equipment"
mode={interactiveMode}
accessibleName={accessibleName}
/>
);

cy.get("[ui5-icon][mode='Interactive']").then($icon => {
const icon = $icon[0] as any;
const accessibilityInfo = icon.accessibilityInfo;

// For Interactive mode, accessibilityInfo should have role and description
expect(accessibilityInfo).to.not.be.undefined;
expect(accessibilityInfo.role).to.equal("button");
expect(accessibilityInfo.description).to.equal(accessibleName);
});

// Test with Decorative mode
cy.mount(
<Icon
name="add-equipment"
mode={decorativeMode}
accessibleName={accessibleName}
/>
);

cy.get("[ui5-icon][mode='Decorative']").then($icon => {
const icon = $icon[0] as any;
const accessibilityInfo = icon.accessibilityInfo;

// For Decorative mode, accessibilityInfo should be undefined
expect(accessibilityInfo).to.be.undefined;
});

// Test with Image mode
cy.mount(
<Icon
name="add-equipment"
mode={imageMode}
accessibleName={accessibleName}
/>
);

cy.get("[ui5-icon][mode='Image']").then($icon => {
const icon = $icon[0] as any;
const accessibilityInfo = icon.accessibilityInfo;

// For Image mode, accessibilityInfo should be undefined
expect(accessibilityInfo).to.be.undefined;
});
});
});
11 changes: 11 additions & 0 deletions packages/main/src/Icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import jsxRender from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import type { AriaRole } from "@ui5/webcomponents-base/dist/types.js";
import type { IconData, UnsafeIconData } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
import { getIconData, getIconDataSync } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
Expand Down Expand Up @@ -327,6 +328,16 @@ class Icon extends UI5Element implements IIcon {
get hasIconTooltip() {
return this.showTooltip && this.effectiveAccessibleName;
}

get accessibilityInfo() {
if (this.mode === IconMode.Interactive) {
return {
role: this.effectiveAccessibleRole as AriaRole,
description: this.effectiveAccessibleName,
};
}
return undefined;
}
}

Icon.define();
Expand Down
Loading