From 72ea569d68220e1c41abecfc8a192a92c060dc81 Mon Sep 17 00:00:00 2001 From: mkolesnikov Date: Wed, 21 Mar 2018 16:41:59 +0300 Subject: [PATCH 1/2] fix(menu): avoid DOM elements creation for hidden menu items (fix#270) --- .../components/menu/menu-item.component.html | 57 ++++++++++--------- .../theme/components/menu/menu.component.ts | 47 ++++++++------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/framework/theme/components/menu/menu-item.component.html b/src/framework/theme/components/menu/menu-item.component.html index c122bff4a1..abbd6c5120 100644 --- a/src/framework/theme/components/menu/menu-item.component.html +++ b/src/framework/theme/components/menu/menu-item.component.html @@ -1,28 +1,28 @@ - + {{ menuItem.title }} - + {{ menuItem.title }} - + {{ menuItem.title }} - {{ menuItem.title }} - {{ menuItem.title }} + [class.ion-chevron-down]="menuItem.expanded"> - diff --git a/src/framework/theme/components/menu/menu.component.ts b/src/framework/theme/components/menu/menu.component.ts index 1892d22e58..c573532c73 100644 --- a/src/framework/theme/components/menu/menu.component.ts +++ b/src/framework/theme/components/menu/menu.component.ts @@ -5,20 +5,20 @@ */ import { - Component, - Input, - Output, - EventEmitter, - OnInit, - OnDestroy, - HostBinding, - ViewChildren, - QueryList, - ElementRef, - AfterViewInit, - PLATFORM_ID, - Inject, - } from '@angular/core'; + Component, + Input, + Output, + EventEmitter, + OnInit, + OnDestroy, + HostBinding, + ViewChildren, + QueryList, + ElementRef, + AfterViewInit, + PLATFORM_ID, + Inject, +} from '@angular/core'; import { isPlatformBrowser } from '@angular/common'; import { Router, NavigationEnd } from '@angular/router'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; @@ -153,14 +153,17 @@ export class NbMenuItemComponent implements AfterViewInit, OnDestroy { styleUrls: ['./menu.component.scss'], template: ` `, }) From e0bfe5f37deb222acec5f2fd203f90cc3df6d522 Mon Sep 17 00:00:00 2001 From: mkolesnikov Date: Mon, 26 Mar 2018 12:25:39 +0300 Subject: [PATCH 2/2] feat(menu): add tests for hidden menu item --- e2e/menu.e2e-spec.ts | 11 +++++- src/app/menu-test/menu-test.component.ts | 47 +++++++++++++++++++----- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/e2e/menu.e2e-spec.ts b/e2e/menu.e2e-spec.ts index 5a644b673b..5d2e4cc3a6 100644 --- a/e2e/menu.e2e-spec.ts +++ b/e2e/menu.e2e-spec.ts @@ -23,7 +23,8 @@ const menu333 = by.css('#menu-first ul li:nth-child(4) ul li:nth-child(3) ul li: const newMenu = by.css('#menu-first ul li:nth-child(5) a'); const addButton = by.css('#addBtn'); const homeButton = by.css('#homeBtn'); - +const hiddenMenuItem = by.css('#menu-second ul li:nth-child(3)'); +const hiddenSubmenuItem = by.css('#menu-second ul li:nth-child(2) ul li:nth-child(2)'); const waitTime = 20 * 1000; const sidebarMenu31 = by.css('#menu-sidebar ul li:nth-child(4) ul li:nth-child(1) > a > span'); @@ -276,4 +277,12 @@ describe('nb-menu', () => { expect(browser.getCurrentUrl()).toContain('#/menu/1'); }); }); + + it('hidden menu item should not be present', () => { + expect(element(hiddenMenuItem).isPresent()).toBe(false); + }); + + it('hidden submenu item should not be present', () => { + expect(element(hiddenSubmenuItem).isPresent()).toBeFalsy() + }); }); diff --git a/src/app/menu-test/menu-test.component.ts b/src/app/menu-test/menu-test.component.ts index 49a5cccd09..040aca2d4f 100644 --- a/src/app/menu-test/menu-test.component.ts +++ b/src/app/menu-test/menu-test.component.ts @@ -96,6 +96,11 @@ export class NbMenuItem4Component { } + + + + + `, @@ -119,6 +124,28 @@ export class NbMenuTestComponent implements OnInit, OnDestroy { }, ]; + menuItems1 = [ + { + title: 'Menu #1', + }, + { + title: 'Menu #2', + children: [ + { + title: 'Menu #2.1', + }, + { + title: 'Hidden Submenu Item', + hidden: true, + }, + ], + }, + { + title: 'Hidden Menu Item', + hidden: true, + }, + ]; + private alive: boolean = true; constructor(private menuService: NbMenuService) { } @@ -180,17 +207,17 @@ export class NbMenuTestComponent implements OnInit, OnDestroy { ], 'firstMenu', ); - } +} - ngOnDestroy() { - this.alive = false; - } +ngOnDestroy() { + this.alive = false; +} - addMenuItem() { - this.menuService.addItems([{ title: 'New Menu Item' }], 'firstMenu'); - } +addMenuItem() { + this.menuService.addItems([{ title: 'New Menu Item' }], 'firstMenu'); +} - navigateHome() { - this.menuService.navigateHome('firstMenu'); - } +navigateHome() { + this.menuService.navigateHome('firstMenu'); +} }