Skip to content
Closed
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
26 changes: 23 additions & 3 deletions src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {MenuPositionX, MenuPositionY} from './menu-positions';
host: {
'aria-haspopup': 'true',
'(mousedown)': '_handleMousedown($event)',
'(click)': 'toggleMenu()',
'(click)': 'toggleMenu($event)',
},
exportAs: 'mdMenuTrigger'
})
Expand All @@ -54,6 +54,9 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
// the first item of the list when the menu is opened via the keyboard
private _openedByMouse: boolean = false;

/** Wether the preventClose for menu instance is asked or not.*/
@Input() preventClose: boolean = false;

/** @deprecated */
@Input('md-menu-trigger-for')
get _deprecatedMdMenuTriggerFor(): MdMenuPanel { return this.menu; }
Expand Down Expand Up @@ -93,8 +96,25 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
get menuOpen(): boolean { return this._menuOpen; }

/** Toggles the menu between the open and closed states. */
toggleMenu(): void {
return this._menuOpen ? this.closeMenu() : this.openMenu();
toggleMenu(event): void {
/** whent it's a void function why there is a return statement? */
/** Removed `return` */

/** Checks if preventClose is defined and has true value or not. */
if (this.preventClose) {
/**
* `this._element.nativeElement.contains(event.target)`.
* Checks if the target, where click was fired, falls inside menu panel or not.
*/
if (this._menuOpen && !this._element.nativeElement.contains(event.target)) {
this.closeMenu();
} else {
this.openMenu();
}
} else {
/** If no `preventClose` is defined, it will go same old way. */
this._menuOpen ? this.closeMenu() : this.openMenu();
}
}

/** Opens the menu. */
Expand Down