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
40 changes: 38 additions & 2 deletions packages/main/cypress/specs/ToolbarButton.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe("Toolbar general interaction", () => {
it("Should render the button with the correct accessibilityAttributes", () => {
cy.mount(
<Toolbar>
<ToolbarButton
<ToolbarButton
accessibleName="Add"
accessibilityAttributes={{ expanded: "true", controls: "btn", hasPopup: "dialog" }}
/>
</Toolbar>
);

cy.get("[ui5-toolbar]")
.find("[ui5-toolbar-button][accessible-name]")
.shadow()
Expand All @@ -68,4 +68,40 @@ describe("Toolbar general interaction", () => {
expect(accessibilityAttributes).to.have.property("expanded", "true");
});
});

it("Should forward accessibleRole to the inner button", () => {
cy.mount(
<Toolbar>
<ToolbarButton
text="Navigate"
accessibleRole="Link"
/>
</Toolbar>
);

cy.get("[ui5-toolbar]")
.find("[ui5-toolbar-button]")
.shadow()
.find("[ui5-button]")
.should("have.prop", "accessibleRole", "Link");
});

it("Should apply role=link on the inner button when accessibleRole is Link", () => {
cy.mount(
<Toolbar>
<ToolbarButton
text="Navigate"
accessibleRole="Link"
/>
</Toolbar>
);

cy.get("[ui5-toolbar]")
.find("[ui5-toolbar-button]")
.shadow()
.find("[ui5-button]")
.shadow()
.find("[role='link']")
.should("exist");
});
});
13 changes: 13 additions & 0 deletions packages/main/src/ToolbarButton.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 event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
import type { ButtonAccessibilityAttributes } from "./Button.js";
import type ButtonDesign from "./types/ButtonDesign.js";
import type ButtonAccessibleRole from "./types/ButtonAccessibleRole.js";
import type ToolbarItemOverflowBehavior from "./types/ToolbarItemOverflowBehavior.js";

import ToolbarItemBase from "./ToolbarItemBase.js";
Expand Down Expand Up @@ -142,6 +143,18 @@ class ToolbarButton extends ToolbarItemBase {
@property()
accessibleNameRef?: string;

/**
* Defines the ARIA role of the component.
*
* **Note:** Use `ButtonAccessibleRole.Link` role only with a press handler that performs navigation.
* In all other scenarios the default button semantics are recommended.
* @default "Button"
* @public
* @since 2.27.0
*/
@property()
accessibleRole: `${ButtonAccessibleRole}` = "Button";

/**
* Defines the additional accessibility attributes that will be applied to the component.
*
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/ToolbarButtonTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function ToolbarButtonTemplate(this: ToolbarButton) {
tooltip={this.tooltip}
accessibleName={this.accessibleName}
accessibleNameRef={this.accessibleNameRef}
accessibleRole={this.accessibleRole}
accessibilityAttributes={this.accessibilityAttributes}
design={this.design}
disabled={this.disabled}
Expand Down
Loading