diff --git a/packages/main/cypress/specs/Bar.cy.tsx b/packages/main/cypress/specs/Bar.cy.tsx new file mode 100644 index 000000000000..452afe4e859c --- /dev/null +++ b/packages/main/cypress/specs/Bar.cy.tsx @@ -0,0 +1,67 @@ +import Bar from "../../src/Bar.js"; +import Button from "../../src/Button.js"; + +describe("Bar Accessibility", () => { + it("Should use accessibleName property as aria-label", () => { + cy.mount( + + +
Page Title
+ +
+ ); + + cy.get("[ui5-bar]") + .shadow() + .find(".ui5-bar-root") + .should("have.attr", "aria-label", "Navigation Bar"); + }); + + it("Should fallback to design property when accessibleName is not provided", () => { + cy.mount( + + +
Application Header
+ +
+ ); + + cy.get("[ui5-bar]") + .shadow() + .find(".ui5-bar-root") + .should("have.attr", "aria-label", "Header"); + }); + + it("Should use accessibleName over design property when both are provided", () => { + cy.mount( + + +
Footer Content
+ +
+ ); + + cy.get("[ui5-bar]") + .shadow() + .find(".ui5-bar-root") + .should("have.attr", "aria-label", "Custom Footer Label"); + }); + + it("Should use accessibleNameRef over accessibleName when both are provided", () => { + cy.mount( +
+
External Navigation Label
+ + +
Content
+ +
+
+ ); + + cy.get("[ui5-bar]") + .shadow() + .find(".ui5-bar-root") + .should("have.attr", "aria-label", "External Navigation Label"); + }); +}); \ No newline at end of file diff --git a/packages/main/src/Bar.ts b/packages/main/src/Bar.ts index 479c9236b526..fe1dedccffe7 100644 --- a/packages/main/src/Bar.ts +++ b/packages/main/src/Bar.ts @@ -4,6 +4,7 @@ import property from "@ui5/webcomponents-base/dist/decorators/property.js"; import slot from "@ui5/webcomponents-base/dist/decorators/slot.js"; import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js"; import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js"; +import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js"; import type BarDesign from "./types/BarDesign.js"; import type BarAccessibleRole from "./types/BarAccessibleRole.js"; @@ -84,6 +85,24 @@ class Bar extends UI5Element { @property() accessibleRole: `${BarAccessibleRole}` = "Toolbar"; + /** + * Defines the accessible ARIA name of the component. + * @default undefined + * @since 2.16.0 + * @public + */ + @property() + accessibleName?: string; + + /** + * Receives id(or many ids) of the elements that label the bar. + * @default undefined + * @since 2.16.0 + * @public + */ + @property() + accessibleNameRef?: string; + /** * Defines the content at the start of the bar. * @public @@ -109,11 +128,19 @@ class Bar extends UI5Element { get accInfo() { return { - "label": this.design, + "label": this.ariaLabelText, "role": this.effectiveRole, }; } + get ariaLabelText(): string | undefined { + if (this.accessibleName || this.accessibleNameRef) { + return getEffectiveAriaLabelText(this); + } + + return this.design; + } + constructor() { super(); diff --git a/packages/main/src/BarTemplate.tsx b/packages/main/src/BarTemplate.tsx index 5228cdcb4777..e1a870299ade 100644 --- a/packages/main/src/BarTemplate.tsx +++ b/packages/main/src/BarTemplate.tsx @@ -4,7 +4,7 @@ export default function BarTemplate(this: Bar) { return (
diff --git a/packages/main/test/pages/Bar.html b/packages/main/test/pages/Bar.html index a79d21322533..d2468cc03bf6 100644 --- a/packages/main/test/pages/Bar.html +++ b/packages/main/test/pages/Bar.html @@ -16,7 +16,7 @@
- + Title Title