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(context-menu): hide on menu item click #431

Merged
merged 4 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions e2e/context-menu.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ describe('nb-context-menu', () => {
browser.get('#/context-menu').then(done);
});

it('have to hide when click on item', () => {
element(withContextMenu).click();
const containerContent = element(popover).all(by.css('nb-menu > ul > li')).get(2);
expect(containerContent.isPresent()).toBeTruthy();

containerContent.click();
expect(containerContent.isPresent()).toBeFalsy();
});

it('have to be opened by click', () => {
element(withContextMenu).click();
const containerContent = element(popover).element(by.css('nb-menu > ul'));

expect(containerContent.isPresent()).toBeTruthy();
});

it('should have two menu items', () => {
it('should have three menu items', () => {
element(withContextMenu).click();
const menuItems = element(popover).all(by.css('nb-menu > ul > li'));

expect(menuItems.count()).toEqual(2);
expect(menuItems.count()).toEqual(3);
});

it('have to open user page after click on first item', () => {
Expand Down
1 change: 1 addition & 0 deletions src/app/context-menu-test/context-menu-test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class NbContextMenuTestComponent {
items = [
{ title: 'Profile', link: '/user' },
{ title: 'Logout', link: '/popover' },
{ title: 'Another action' },
];

itemsWithIcons = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
ComponentFactoryResolver, Directive, ElementRef, HostListener, Inject, Input, OnDestroy,
OnInit, PLATFORM_ID,
} from '@angular/core';
import { filter } from 'rxjs/operators';
import { NbPopoverDirective } from '../popover/popover.directive';
import { NbMenuItem } from '../menu/menu.service';
import { NbMenuItem, NbMenuService } from '../menu/menu.service';
import { NbThemeService } from '../../services/theme.service';
import { NbPopoverAdjustment, NbPopoverPlacement } from '../popover/helpers/model';
import { NbContextMenuComponent } from './context-menu.component';
Expand Down Expand Up @@ -66,6 +67,8 @@ import { NbPlacementHelper } from '../popover/helpers/placement.helper';
@Directive({ selector: '[nbContextMenu]' })
export class NbContextMenuDirective implements OnInit, OnDestroy {

private menuTag: string;

/**
* Basic menu items, will be passed to the internal NbMenuComponent.
* */
Expand Down Expand Up @@ -99,6 +102,7 @@ export class NbContextMenuDirective implements OnInit, OnDestroy {
* */
@Input('nbContextMenuTag')
set tag(tag: string) {
this.menuTag = tag;
this.popover.context = Object.assign(this.context, { tag });
}

Expand All @@ -112,7 +116,8 @@ export class NbContextMenuDirective implements OnInit, OnDestroy {
adjustmentHelper: NbAdjustmentHelper,
triggerHelper: NbTriggerHelper,
@Inject(PLATFORM_ID) platformId,
placementHelper: NbPlacementHelper) {
placementHelper: NbPlacementHelper,
private menuService: NbMenuService) {
/**
* Initialize popover with all the important inputs.
* */
Expand All @@ -131,6 +136,7 @@ export class NbContextMenuDirective implements OnInit, OnDestroy {

ngOnInit() {
this.popover.ngOnInit();
this.subscribeOnItemClick();
}

ngOnDestroy() {
Expand Down Expand Up @@ -172,4 +178,10 @@ export class NbContextMenuDirective implements OnInit, OnDestroy {
throw Error(`List of menu items expected, but given: ${items}`)
}
}

private subscribeOnItemClick() {
this.menuService.onItemClick()
.pipe(filter(({tag}) => tag === this.menuTag))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

takeWhilte(() => this.live)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.subscribe(() => this.hide());
}
}