Skip to content

Commit 60414e9

Browse files
committed
fix(material/menu): incorrectly detaching lazy content when menu is transferred to a new trigger (#31690)
The menu has some logic that detaches its lazy content when the animation is finished, however while the animation was running, the panel might've been picked up by another trigger. This ends up opening an empty menu panel to the new trigger. These changes resolve the issue by checking if another trigger picked up the panel before detaching the lazy content. Fixes #31687. (cherry picked from commit b1514c4)
1 parent 98b3ccc commit 60414e9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/material/menu/menu-trigger-base.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,14 @@ export abstract class MatMenuTriggerBase implements OnDestroy {
300300
if (menu instanceof MatMenu && this._ownsMenu(menu)) {
301301
this._pendingRemoval = menu._animationDone.pipe(take(1)).subscribe(() => {
302302
overlayRef.detach();
303-
menu.lazyContent?.detach();
303+
304+
// Only detach the lazy content if no other trigger took over the menu, otherwise we may
305+
// detach something we no longer own. Note that we don't use `this._ownsMenu` here,
306+
// because the current trigger relinquishes ownership as soon as the closing sequence
307+
// is kicked off whereas the animation takes some time to play out.
308+
if (!PANELS_TO_TRIGGERS.has(menu)) {
309+
menu.lazyContent?.detach();
310+
}
304311
});
305312
menu._setIsOpen(false);
306313
} else {

0 commit comments

Comments
 (0)