Skip to content
Closed
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
15 changes: 15 additions & 0 deletions src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TODO(kara): prevent-close functionality
// wasn't this supposed to be from an outside developer who needs this feature urgently?

import {
AfterContentInit,
Expand Down Expand Up @@ -54,6 +55,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
@ContentChildren(MdMenuItem) items: QueryList<MdMenuItem>;
@Input() overlapTrigger = true;

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

constructor(@Attribute('xPosition') posX: MenuPositionX,
@Attribute('yPosition') posY: MenuPositionY,
@Attribute('x-position') deprecatedPosX: MenuPositionX,
Expand Down Expand Up @@ -115,6 +119,17 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
this.close.emit();
}

/**
* This emits a close event to which the trigger is subscribed, only when a user
* click inside menu panel and prevent close attribute/input is false. When emitted,
* the trigger will close the menu.
*/
_emitClickCloseEvent(): void {
if (!this.preventClose) {
this.close.emit();
}
}

private _setPositionX(pos: MenuPositionX): void {
if (pos !== 'before' && pos !== 'after') {
throw new MdMenuInvalidPositionX();
Expand Down
3 changes: 1 addition & 2 deletions src/lib/menu/menu.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<ng-template>
<div class="mat-menu-panel" [ngClass]="_classList" (keydown)="_keyManager.onKeydown($event)"
(click)="_emitCloseEvent()" [@transformMenu]="'showing'">
(click)="_emitClickCloseEvent()" [@transformMenu]="'showing'">
<div class="mat-menu-content" [@fadeInItems]="'showing'">
<ng-content></ng-content>
</div>
</div>
</ng-template>