Skip to content
Closed
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
17 changes: 17 additions & 0 deletions packages/fiori/cypress/specs/ShellBarBranding.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,22 @@ describe("ShellBarBranding", () => {
.find("a")
.should("have.attr", "tabIndex", "0");
});

it("fires click event on Enter and Space", () => {
basicTemplate();

cy.get("#shellbarBranding").then(branding => {
branding.get(0).addEventListener("ui5-click", cy.stub().as("brandingClick"));
});

cy.get("@shellbarBranding")
.find("a")
.focus()
.realPress("Enter")
.realPress("Space");

cy.get("@brandingClick")
.should("have.been.calledTwice");
});
});
});
27 changes: 19 additions & 8 deletions packages/fiori/src/ShellBarBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,36 @@ class ShellBarBranding extends UI5Element {
this.fireDecoratorEvent("click");
}

_onclick(e: MouseEvent) {
private _activate(e: Event) {
e.stopPropagation();
this._fireClick();
}

_onkeyup(e: KeyboardEvent) {
if (isSpace(e)) {
this._fireClick();
}
_onclick(e: MouseEvent) {
this._activate(e);
}

_onkeydown(e: KeyboardEvent) {
if (isSpace(e)) {
if (isEnter(e) && !this.href) {
this._activate(e);
e.preventDefault();
} else if (isSpace(e)) {
e.preventDefault();
}
}

_onkeyup(e: KeyboardEvent) {
if (!isSpace(e)) {
return;
}

if (isEnter(e)) {
this._fireClick();
this._activate(e);

if (this.href && !e.defaultPrevented) {
const customEvent = new MouseEvent("click");

customEvent.stopImmediatePropagation();
this.getDomRef()!.dispatchEvent(customEvent);
}
}
}
Expand Down
Loading