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
88 changes: 88 additions & 0 deletions packages/fiori/cypress/specs/SideNavigation.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,94 @@ describe("Side Navigation interaction", () => {
});
});

it("Tests link opening with mouse click", () => {
cy.mount(
<SideNavigation id="sideNav">
<SideNavigationItem id="item" text="1" />
<SideNavigationItem id="unselectableItemWithLink" text="external link" unselectable={true} href="#test"/>
</SideNavigation>
);

cy.url().should("not.include", "#test");

cy.get("#unselectableItemWithLink").realClick();

cy.url().should("include", "#test");

// Remove #test from the URL
cy.window().then(win => {
win.history.back();
});

cy.url().should("not.include", "#test");
});

it("Tests link opening with Enter", () => {
cy.mount(
<SideNavigation>
<SideNavigationItem id="focusStart" text="focus start" />
<SideNavigationItem text="external link" unselectable={true} href="#test"/>
</SideNavigation>
);

cy.url().should("not.include", "#test");

cy.get("#focusStart").realClick();
cy.realPress("ArrowDown");
cy.realPress("Enter");

cy.url().should("include", "#test");

// Remove #test from the URL
cy.window().then(win => {
win.history.back();
});

cy.url().should("not.include", "#test");
});

it("Tests link opening with Space", () => {
cy.mount(
<SideNavigation>
<SideNavigationItem id="focusStart" text="focus start" />
<SideNavigationItem id="linkItem" text="external link" unselectable={true} href="#test"/>
</SideNavigation>
);

cy.url().should("not.include", "#test");

cy.get("#focusStart").realClick();
cy.realPress("ArrowDown");
cy.realPress("Space");

cy.url().should("include", "#test");

// Remove #test from the URL
cy.window().then(win => {
win.history.back();
});

cy.url().should("not.include", "#test");

cy.get("#focusStart").realClick();
cy.realPress("ArrowDown");
cy.get("#linkItem").should("be.focused");

// act
cy.focused().trigger("keyup", {
key: " ",
});

cy.url().should("include", "#test");

// Remove #test from the URL
cy.window().then(win => {
win.history.back();
});

cy.url().should("not.include", "#test");
});

it("Tests 'selection-change' event", () => {
cy.mount(
<SideNavigation id="sideNav">
Expand Down
12 changes: 12 additions & 0 deletions packages/fiori/src/SideNavigationSelectableItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ class SideNavigationSelectableItemBase extends SideNavigationItemBase {
_onkeyup(e: KeyboardEvent) {
if (isSpace(e)) {
this._activate(e);

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

customEvent.stopImmediatePropagation();
if (this.getDomRef()!.querySelector("a")) {
this.getDomRef()!.querySelector("a")!.dispatchEvent(customEvent);
} else {
// when Side Navigation is collapsed and it is first level item we have directly <a> element
this.getDomRef()!.dispatchEvent(customEvent);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/fiori/test/pages/SideNavigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ui5-side-navigation-sub-item text="Local" href="https://sap.com" target="_blank"></ui5-side-navigation-sub-item>
<ui5-side-navigation-sub-item text="Others"></ui5-side-navigation-sub-item>
</ui5-side-navigation-item>
<ui5-side-navigation-item id="externalLinkItem" text="External Link Unselectable" icon="chain-link" href="https://sap.com" unselectable target="_blank"></ui5-side-navigation-item>
<ui5-side-navigation-item id="externalLinkItem" text="External Link" icon="chain-link" href="https://sap.com" target="_blank"></ui5-side-navigation-item>

<ui5-side-navigation-item id="item4" text="Home" icon="home" tooltip="Home tooltip">
Expand Down
6 changes: 3 additions & 3 deletions packages/fiori/test/specs/SideNavigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ describe("Component Behavior", () => {

// fixed items
assert.strictEqual(await sideNavigationFixedTree.getAttribute("aria-roledescription"), roleDescription, "Role description of the SideNavigation fixed tree element is correctly set");
assert.notExists(await items[10].getAttribute("aria-roledescription"), "Role description of the SideNavigation fixed tree item is not set");
assert.strictEqual(await items[10].getAttribute("aria-haspopup"), "tree", "There is 'aria-haspopup' with correct value");
assert.notExists(await items[11].getAttribute("aria-haspopup"), "There is no 'aria-haspopup'");
assert.notExists(await items[11].getAttribute("aria-roledescription"), "Role description of the SideNavigation fixed tree item is not set");
assert.strictEqual(await items[11].getAttribute("aria-haspopup"), "tree", "There is 'aria-haspopup' with correct value");
assert.notExists(await items[12].getAttribute("aria-haspopup"), "There is no 'aria-haspopup'");

// popup
await browser.$("#item2").click();
Expand Down