Skip to content

Commit

Permalink
fix(module:menu): fix submenu level bug & fix menu routerLinkActive b…
Browse files Browse the repository at this point in the history
…ug in lazyload module (#77)

this closes #35 #52 #74
  • Loading branch information
vthinkxie authored and wilsoncook committed Aug 18, 2017
1 parent 44865c2 commit b914afd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
28 changes: 19 additions & 9 deletions src/components/menu/nz-menu-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AfterViewInit,
HostListener,
ChangeDetectorRef,
Renderer2,
Optional,
ElementRef
} from '@angular/core';
Expand All @@ -14,17 +15,31 @@ import { NzSubMenuComponent } from './nz-submenu.component';
export const PADDING_BASE = 24;

@Component({
selector : '[nz-menu-item]',
template : `
selector: '[nz-menu-item]',
template: `
<ng-content></ng-content>`,
})

export class NzMenuItemComponent implements AfterViewInit {
level = 0;
padding = null;
isInDropDown = false;
selected = false;
@Input() nzDisable = false;
@Input() nzSelected = false;

@Input()
set nzSelected(value: boolean) {
this.selected = value;
if (value) {
this._renderer.addClass(this.hostElement.nativeElement, 'ant-menu-item-selected')
} else {
this._renderer.removeClass(this.hostElement.nativeElement, 'ant-menu-item-selected')
}
}

get nzSelected() {
return this.selected;
}

/** clear all item selected status except this */
@HostListener('click', [ '$event' ])
Expand All @@ -51,11 +66,6 @@ export class NzMenuItemComponent implements AfterViewInit {
return this.isInDropDown && this.nzDisable;
}

@HostBinding('class.ant-menu-item-selected')
get setMenuSelectedClass() {
return this.nzSelected;
}

@HostBinding('class.ant-menu-item-disabled')
get setMenuDisableClass() {
return (!this.isInDropDown) && this.nzDisable;
Expand All @@ -80,7 +90,7 @@ export class NzMenuItemComponent implements AfterViewInit {
}
}

constructor(public cd: ChangeDetectorRef, private nzMenuComponent: NzMenuComponent, @Optional() public nzSubMenuComponent: NzSubMenuComponent, private hostElement: ElementRef) {
constructor(private _renderer: Renderer2, public cd: ChangeDetectorRef, private nzMenuComponent: NzMenuComponent, @Optional() public nzSubMenuComponent: NzSubMenuComponent, private hostElement: ElementRef) {
this.nzMenuComponent.menuItems.push(this);
/** store origin padding in padding */
if (this.hostElement.nativeElement.style[ 'padding-left' ]) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/menu/nz-submenu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { Subject } from 'rxjs/Rx';

export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
isInDropDown = false;
level = 0;
level = 1;
_$mouseSubject = new Subject();
@ContentChildren(NzSubMenuComponent) subMenus;
@Input() nzOpen = false;
Expand Down Expand Up @@ -135,7 +135,7 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
ngAfterViewInit() {
this.isInDropDown = this.nzMenuComponent.isInDropDown;
if (this.subMenus.length && (this.nzMenuComponent.nzMode === 'inline')) {
this.subMenus.forEach(menu => {
this.subMenus.filter(x => x !== this).forEach(menu => {
setTimeout(_ => {
menu.level = this.level + 1;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { Component, OnInit } from '@angular/core';
]
})
export class NzDemoLayoutSideComponent implements OnInit {
isCollapsed = false;
isCollapsed = true;

constructor() {
}
Expand Down

0 comments on commit b914afd

Please sign in to comment.