Skip to content
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

chore(ui5-side-navigation): improve selection #10230

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
2 changes: 1 addition & 1 deletion packages/fiori/src/SideNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class SideNavigation extends UI5Element {
}

_selectItem(item: SideNavigationSelectableItemBase) {
if (item.disabled) {
if (item.disabled || !item.canBeSelected) {
return;
}

Expand Down
16 changes: 16 additions & 0 deletions packages/fiori/src/SideNavigationItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ class SideNavigationItem extends SideNavigationSelectableItemBase {
get isSideNavigationItem() {
return true;
}

_activate(e: KeyboardEvent | PointerEvent) {
super._activate(e);

if (!this.canBeSelected) {
this.expanded = !this.expanded;
}
}

get canBeSelected() {
if (this.items.length > 0 && !this.href) {
return false;
}

return !this.isExternalLink;
}
}

SideNavigationItem.define();
Expand Down
4 changes: 4 additions & 0 deletions packages/fiori/src/SideNavigationSelectableItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ class SideNavigationSelectableItemBase extends SideNavigationItemBase {
}
}

get canBeSelected() {
return !this.isExternalLink;
}

get isSideNavigationSelectableItemBase() {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fiori/test/pages/NavigationLayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<!-- Items -->
<ui5-side-navigation-item text="Home" href="#home" icon="home"></ui5-side-navigation-item>
<ui5-side-navigation-group text="Group 1" expanded>
<ui5-side-navigation-item text="Item 1" expanded href="#item1" icon="locate-me">
<ui5-side-navigation-item text="Item 1" expanded icon="locate-me">
<ui5-side-navigation-sub-item text="Sub Item 1" href="#subitem1"></ui5-side-navigation-sub-item>
<ui5-side-navigation-sub-item text="Sub Item 2" href="#subitem2"></ui5-side-navigation-sub-item>
</ui5-side-navigation-item>
<ui5-side-navigation-item text="Item 2" href="#item2" icon="calendar" expanded>
<ui5-side-navigation-item text="Item 2" icon="calendar" expanded>
<ui5-side-navigation-sub-item text="Sub Item 3" href="#subitem3"></ui5-side-navigation-sub-item>
<ui5-side-navigation-sub-item text="Sub Item 4" href="#subitem4"></ui5-side-navigation-sub-item>
</ui5-side-navigation-item>
Expand Down
Loading