MCPcopy Index your code
hub / github.com/angular/components / _destroyMenu

Function _destroyMenu

src/material/menu/menu-trigger-base.ts:273–321  ·  view source on GitHub ↗

Closes the menu and does the necessary cleanup.

(reason: MenuCloseReason)

Source from the content-addressed store, hash-verified

271
272 /** Closes the menu and does the necessary cleanup. */
273 protected _destroyMenu(reason: MenuCloseReason) {
274 const overlayRef = this._overlayRef;
275 const menu = this._menu;
276
277 if (!overlayRef || !this.menuOpen) {
278 return;
279 }
280
281 this._closingActionsSubscription.unsubscribe();
282 this._pendingRemoval?.unsubscribe();
283
284 // Note that we don't wait for the animation to finish if another trigger took
285 // over the menu, because the panel will end up empty which looks glitchy.
286 if (menu instanceof MatMenu && this._ownsMenu(menu)) {
287 this._pendingRemoval = menu._animationDone.pipe(take(1)).subscribe(() => {
288 overlayRef.detach();
289
290 // Only detach the lazy content if no other trigger took over the menu, otherwise we may
291 // detach something we no longer own. Note that we don't use `this._ownsMenu` here,
292 // because the current trigger relinquishes ownership as soon as the closing sequence
293 // is kicked off whereas the animation takes some time to play out.
294 if (!PANELS_TO_TRIGGERS.has(menu)) {
295 menu.lazyContent?.detach();
296 }
297 });
298 menu._setIsOpen(false);
299 } else {
300 overlayRef.detach();
301 menu?.lazyContent?.detach();
302 }
303
304 if (menu && this._ownsMenu(menu)) {
305 PANELS_TO_TRIGGERS.delete(menu);
306 }
307
308 // Always restore focus if the user is navigating using the keyboard or the menu was opened
309 // programmatically. We don't restore for non-root triggers, because it can prevent focus
310 // from making it back to the root trigger when closing a long chain of menus by clicking
311 // on the backdrop.
312 if (
313 this.restoreFocus &&
314 (reason === 'keydown' || !this._openedBy || !this._triggersSubmenu())
315 ) {
316 this.focus(this._openedBy);
317 }
318
319 this._openedBy = undefined;
320 this._setIsMenuOpen(false);
321 }
322
323 // set state rather than toggle to support triggers sharing a menu
324 private _setIsMenuOpen(isOpen: boolean): void {

Callers

nothing calls this directly

Calls 4

_setIsOpenMethod · 0.80
detachMethod · 0.65
deleteMethod · 0.65
focusMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…