Skip to content

fix(material/menu): incorrectly detaching lazy content when menu is transferred to a new trigger #31690

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

Merged
merged 1 commit into from
Aug 14, 2025
Merged
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
9 changes: 8 additions & 1 deletion src/material/menu/menu-trigger-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,14 @@ export abstract class MatMenuTriggerBase implements OnDestroy {
if (menu instanceof MatMenu && this._ownsMenu(menu)) {
this._pendingRemoval = menu._animationDone.pipe(take(1)).subscribe(() => {
overlayRef.detach();
menu.lazyContent?.detach();

// Only detach the lazy content if no other trigger took over the menu, otherwise we may
// detach something we no longer own. Note that we don't use `this._ownsMenu` here,
// because the current trigger relinquishes ownership as soon as the closing sequence
// is kicked off whereas the animation takes some time to play out.
if (!PANELS_TO_TRIGGERS.has(menu)) {
menu.lazyContent?.detach();
}
});
menu._setIsOpen(false);
} else {
Expand Down
Loading