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

fix(module:menu): fix submenu level bug & fix menu routerLinkActive b… #77

Merged
merged 1 commit into from
Aug 18, 2017
Merged
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
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