Skip to content

fix(ui5-side-navigation): right arrow and left arrow behavior fixed #11434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
108 changes: 108 additions & 0 deletions packages/fiori/cypress/specs/SideNavigation.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,114 @@ describe("Side Navigation interaction", () => {
cy.get("#unselectableItem").should("be.focused").and("not.have.attr", "expanded");
});

it("Tests expanding and collapsing of unselectable items with ArrowLeft and ArrowRight", () => {
cy.mount(
<SideNavigation id="sn">
<SideNavigationItem id="focusStart" text="focus start"></SideNavigationItem>
<SideNavigationItem id="unselectableItem" text="1" unselectable={true}>
<SideNavigationSubItem text="1.2" />
</SideNavigationItem>
</SideNavigation>
);

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

cy.get("#unselectableItem").should("have.attr", "expanded");

cy.realPress("ArrowLeft");

cy.get("#unselectableItem").should("not.have.attr", "expanded");

cy.realPress("ArrowRight");
cy.realPress("ArrowRight");

cy.get("#unselectableItem").should("have.attr", "expanded");

cy.realPress("ArrowLeft");
cy.realPress("ArrowLeft");

cy.get("#unselectableItem").should("not.have.attr", "expanded");

cy.get("#sn").invoke("prop", "collapsed", true);

cy.get("#focusStart").realClick();
cy.focused().should(($focused) => {
expect($focused.text()).to.equal("focus start");
});
cy.realPress("ArrowDown");
cy.realPress("ArrowRight");

cy.get("#sn")
.shadow()
.find("[ui5-responsive-popover]")
.as("popover");

cy.get("@popover").should("be.visible");

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

cy.get("@popover").should("not.be.visible");
});

it("Tests expanding and collapsing of unselectable items with ArrowLeft and ArrowRight for rtl", () => {
cy.mount(
<div dir="rtl">
<SideNavigation id="sn">
<SideNavigationItem id="focusStart" text="focus start"></SideNavigationItem>
<SideNavigationItem id="unselectableItem" text="1" unselectable={true}>
<SideNavigationSubItem text="1.2" />
</SideNavigationItem>
</SideNavigation>
</div>
);

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

cy.get("#unselectableItem").should("have.attr", "expanded");

cy.realPress("ArrowRight");

cy.get("#unselectableItem").should("not.have.attr", "expanded");

cy.realPress("ArrowLeft");
cy.realPress("ArrowLeft");

cy.get("#unselectableItem").should("have.attr", "expanded");

cy.realPress("ArrowRight");
cy.realPress("ArrowRight");

cy.get("#unselectableItem").should("not.have.attr", "expanded");

cy.get("#sn").invoke("prop", "collapsed", true);

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

cy.get("#sn")
.shadow()
.find("[ui5-responsive-popover]")
.as("popover");

cy.get("@popover").should("be.visible");

cy.get("#focusStart").realClick();
cy.focused().should(($focused) => {
expect($focused.text()).to.equal("focus start");
});
cy.realPress("ArrowDown");
cy.realPress("ArrowRight");

cy.get("@popover").should("not.be.visible");
});

it("Tests expanding and collapsing of unselectable parent item when SideNavigation is collapsed", () => {
cy.mount(
<SideNavigation id="sideNav" collapsed={true}>
Expand Down
2 changes: 2 additions & 0 deletions packages/fiori/src/SideNavigationGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ class SideNavigationGroup extends SideNavigationItemBase {

_onkeydown(e: KeyboardEvent) {
if (isLeft(e) || isMinus(e)) {
e.preventDefault();
this.expanded = false;
return;
}

if (isRight(e) || isPlus(e)) {
e.preventDefault();
this.expanded = true;
}
}
Expand Down
15 changes: 12 additions & 3 deletions packages/fiori/src/SideNavigationItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SideNavigationItem extends SideNavigationSelectableItemBase {
_fixed = false;

/**
* Defines nested items by passing `ui5-side-navigation-sub-item` to the default slot.
* Defines nested items by passing `ui5-side-navigation-sub-item` to the default slot.
*
* @public
*/
Expand Down Expand Up @@ -199,13 +199,22 @@ class SideNavigationItem extends SideNavigationSelectableItemBase {
}

_onkeydown(e: KeyboardEvent) {
const isRTL = this.effectiveDir === "rtl";

if (this.sideNavigation.classList.contains("ui5-side-navigation-in-popover") || this.sideNavCollapsed) {
super._onkeydown(e);
return;
}

if (isLeft(e) || isMinus(e)) {
this.expanded = false;
e.preventDefault();
this.expanded = !!isRTL;
return;
}

if (isRight(e) || isPlus(e)) {
this.expanded = true;
e.preventDefault();
this.expanded = !isRTL;
return;
}

Expand Down
19 changes: 17 additions & 2 deletions packages/fiori/src/SideNavigationSelectableItemBase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
import {
isSpace,
isEnter,
isLeft,
isRight,
} from "@ui5/webcomponents-base/dist/Keys.js";
import SideNavigationItemBase from "./SideNavigationItemBase.js";
import type SideNavigationItemDesign from "./types/SideNavigationItemDesign.js";
import type { AccessibilityAttributes } from "@ui5/webcomponents-base/dist/types.js";
Expand Down Expand Up @@ -194,13 +199,23 @@ class SideNavigationSelectableItemBase extends SideNavigationItemBase {
}

_onkeydown(e: KeyboardEvent) {
if (isSpace(e)) {
const isRTL = this.effectiveDir === "rtl";

if (isSpace(e) || isRight(e) || isLeft(e)) {
e.preventDefault();
}

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

if ((isRTL ? isLeft(e) : isRight(e)) && this.sideNavCollapsed) {
this._activate(e);
}

if ((isRTL ? isRight(e) : isLeft(e)) && !this.sideNavCollapsed) {
this._activate(e);
}
}

_onkeyup(e: KeyboardEvent) {
Expand Down
1 change: 0 additions & 1 deletion packages/fiori/src/themes/SideNavigationGroup.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
.ui5-sn-item.ui5-sn-item-group {
min-height: 2rem;
padding-inline-start: var(--_ui5_side_navigation_group_padding);;
gap: 0.4375rem;
font-family: var(--sapFontFamily);
font-size: var(--sapFontSize);
}
Expand Down
Loading