Skip to content

Commit

Permalink
feat(module:menu): selected child item, its parent highlight (#264)
Browse files Browse the repository at this point in the history
close #262
  • Loading branch information
hsuanxyz authored and wilsoncook committed Sep 16, 2017
1 parent 686f5fd commit 970e968
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/components/menu/nz-menu.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ describe('NzMenuComponent', () => {
// const debugElement4 = fixture.debugElement.query(By.directive(NzSubMenuComponent));
// expect(debugElement4.nativeElement.classList.contains('ant-menu-submenu-open')).toBe(true);
})

it('should apply class based on sub-items select state', () => {
const fixture = TestBed.createComponent(TestMenuSubMenu);
const testComponent = fixture.debugElement.componentInstance;
const debugElement = fixture.debugElement.query(By.directive(NzSubMenuComponent));
expect(debugElement).toBeDefined();

testComponent._mode = 'vertical';
testComponent.selectOne = false;
fixture.detectChanges();
const debugElement1 = fixture.debugElement.query(By.directive(NzSubMenuComponent));
expect(debugElement1.nativeElement.classList.contains('ant-menu-submenu-selected')).toBe(false);

testComponent._mode = 'vertical';
testComponent.selectOne = true;
fixture.detectChanges();
const debugElement2 = fixture.debugElement.query(By.directive(NzSubMenuComponent));
expect(debugElement2.nativeElement.classList.contains('ant-menu-submenu-selected')).toBe(true);

})
});
});

Expand Down Expand Up @@ -238,7 +258,7 @@ class TestMenuTheme {
<li nz-submenu [(nzOpen)]="isOpenOne" (nzOpenChange)="openChange('one')">
<span title><i class="anticon anticon-mail"></i> Navigation One</span>
<ul>
<li nz-menu-item>Option 1</li>
<li nz-menu-item [nzSelected]="selectOne">Option 1</li>
</ul>
</li>
<li nz-submenu [(nzOpen)]="isOpenTwo" (nzOpenChange)="openChange('Two')">
Expand All @@ -255,6 +275,7 @@ class TestMenuSubMenu {
isTestOpen = true;
isOpenOne = false;
isOpenTwo = false;
selectOne = false;

openChange(value) {
if (!this.isTestOpen) {
Expand Down
13 changes: 12 additions & 1 deletion src/components/menu/nz-submenu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
@Input() nzOpen = false;
@Output() nzOpenChange: EventEmitter<boolean> = new EventEmitter();

get subItemSelected(): boolean {
return !!this.nzMenuComponent.menuItems.find(e => e.selected && e.nzSubMenuComponent === this);
}
get submenuSelected(): boolean {
return !!this.subMenus._results.find(e => e !== this && e.subItemSelected)
}

clickSubMenuTitle() {
if ((this.nzMenuComponent.nzMode === 'inline') || (!this.isInDropDown)) {
this.nzOpen = !this.nzOpen;
Expand Down Expand Up @@ -106,12 +113,16 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
return this.isInDropDown && (this.nzMenuComponent.nzMode === 'horizontal');
}


@HostBinding('class.ant-menu-submenu')
get setMenuSubmenuClass() {
return !this.isInDropDown;
}

@HostBinding('class.ant-menu-submenu-selected')
get setMenuSubmenuSelectedClass() {
return this.submenuSelected || this.subItemSelected;
}

@HostBinding('class.ant-menu-submenu-vertical')
get setMenuVerticalClass() {
return (!this.isInDropDown) && (this.nzMenuComponent.nzMode === 'vertical');
Expand Down

0 comments on commit 970e968

Please sign in to comment.