diff --git a/src/lib/menu/menu-directive.ts b/src/lib/menu/menu-directive.ts index 502f490c02fe..ba18c534f91b 100644 --- a/src/lib/menu/menu-directive.ts +++ b/src/lib/menu/menu-directive.ts @@ -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, @@ -54,6 +55,9 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy { @ContentChildren(MdMenuItem) items: QueryList; @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, @@ -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(); diff --git a/src/lib/menu/menu.html b/src/lib/menu/menu.html index 989bf1f56acb..259f65994967 100644 --- a/src/lib/menu/menu.html +++ b/src/lib/menu/menu.html @@ -1,9 +1,8 @@
+ (click)="_emitClickCloseEvent()" [@transformMenu]="'showing'">
-