diff --git a/src/lib/menu/menu-trigger.ts b/src/lib/menu/menu-trigger.ts index 3a82acb7af4d..2eda28d7b6a2 100644 --- a/src/lib/menu/menu-trigger.ts +++ b/src/lib/menu/menu-trigger.ts @@ -106,6 +106,10 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy { /** References the menu instance that the trigger is associated with. */ @Input('matMenuTriggerFor') menu: MatMenuPanel; + /** Disables auto-closing the menu when the user clicks inside the panel */ + @Input() disableClose: boolean = false; + + /** Event emitted when the associated menu is opened. */ @Output() menuOpened = new EventEmitter(); @@ -186,7 +190,16 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy { /** Toggles the menu between the open and closed states. */ toggleMenu(): void { - return this._menuOpen ? this.closeMenu() : this.openMenu(); + if (this.disableClose) { + if (this._menuOpen && !this._element.nativeElement.contains(event.target)) { + this.closeMenu(); + } else { + this.openMenu(); + } + } else { + this._menuOpen ? this.closeMenu() : this.openMenu(); + } + this._menuOpen ? this.closeMenu() : this.openMenu(); } /** Opens the menu. */