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

feat(module:menu): selected child item, its parent highlight #264

Merged
merged 2 commits into from
Sep 16, 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
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