Skip to content
Merged
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
67 changes: 67 additions & 0 deletions packages/main/cypress/specs/Bar.cy.tsx
Original file line number Diff line number Diff line change
@@ -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(
<Bar accessibleName="Navigation Bar">
<Button slot="startContent">Back</Button>
<div>Page Title</div>
<Button slot="endContent">Settings</Button>
</Bar>
);

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(
<Bar design="Header">
<Button slot="startContent">Menu</Button>
<div>Application Header</div>
<Button slot="endContent">Profile</Button>
</Bar>
);

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(
<Bar design="Footer" accessibleName="Custom Footer Label">
<Button slot="startContent">Help</Button>
<div>Footer Content</div>
<Button slot="endContent">Contact</Button>
</Bar>
);

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(
<div>
<div id="external-label">External Navigation Label</div>
<Bar accessibleName="Internal Label" accessibleNameRef="external-label">
<Button slot="startContent">Back</Button>
<div>Content</div>
<Button slot="endContent">Forward</Button>
</Bar>
</div>
);

cy.get("[ui5-bar]")
.shadow()
.find(".ui5-bar-root")
.should("have.attr", "aria-label", "External Navigation Label");
});
});
29 changes: 28 additions & 1 deletion packages/main/src/Bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/BarTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function BarTemplate(this: Bar) {
return (
<div
class="ui5-bar-root"
aria-label={this.accInfo.role && this.accInfo.label}
aria-label={this.accInfo.label}
role={this.accInfo.role}
part="bar"
>
Expand Down
2 changes: 1 addition & 1 deletion packages/main/test/pages/Bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<body class="bar1auto">
<section>
<ui5-bar design="Header" accessible-role="None">
<ui5-bar design="Header" accessible-role="None" accessible-name="Header Bar">
<ui5-title id="titleElement" slot="startContent">Title</ui5-title>
<ui5-label>Title</ui5-label>
<ui5-button icon="action-settings" tooltip="Go to settings" slot="endContent"></ui5-button>
Expand Down
Loading