Skip to content

Commit

Permalink
fix(menu): don't collapse menu which has a selected item (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg authored and nnixaa committed Feb 15, 2018
1 parent 7dbefd6 commit 5c489f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/app/menu-test/menu-test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export class NbMenuItem4Component { }
<nb-menu id="menu-sidebar" tag="sidebarMenu" [items]="menuItems"></nb-menu>
</nb-sidebar>
<nb-layout-column>
<nb-card size="medium">
<nb-card size="xxlarge">
<nb-card-body>
<nb-menu id="menu-first" tag="firstMenu" [items]="menuItems"></nb-menu>
<nb-menu id="menu-first" tag="firstMenu" [items]="menuItems" [autoCollapse]="true"></nb-menu>
<router-outlet></router-outlet>
<button class="btn btn-primary" id="addBtn" (click)="addMenuItem()">Add</button>
<button class="btn btn-primary" id="homeBtn" (click)="navigateHome()">Home</button>
Expand Down
8 changes: 7 additions & 1 deletion src/framework/theme/components/menu/menu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,14 @@ export class NbMenuInternalService {
});
}

private isParent(parent, child) {
return child.parent
? child.parent === parent || this.isParent(parent, child.parent)
: false;
}

private collapseItem(item: NbMenuItem, tag: string, except?: NbMenuItem) {
if (except && item === except) {
if (except && (item === except || this.isParent(item, except))) {
return;
}

Expand Down

0 comments on commit 5c489f3

Please sign in to comment.