Skip to content

feat(menu): Disable closing the menu when contents are clicked #9302

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

Closed
wants to merge 1 commit into from
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
15 changes: 14 additions & 1 deletion src/lib/menu/menu-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>();

Expand Down Expand Up @@ -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. */
Expand Down