MCPcopy Create free account
hub / github.com/angular/components / _setIsOpen

Method _setIsOpen

src/material/menu/menu.ts:476–508  ·  view source on GitHub ↗
(isOpen: boolean)

Source from the content-addressed store, hash-verified

474 }
475
476 _setIsOpen(isOpen: boolean) {
477 this._panelAnimationState = isOpen ? 'enter' : 'void';
478
479 if (isOpen) {
480 if (this._keyManager.activeItemIndex === 0) {
481 // Scroll the content element to the top as soon as the animation starts. This is necessary,
482 // because we move focus to the first item while it's still being animated, which can throw
483 // the browser off when it determines the scroll position. Alternatively we can move focus
484 // when the animation is done, however moving focus asynchronously will interrupt screen
485 // readers which are in the process of reading out the menu already. We take the `element`
486 // from the `event` since we can't use a `ViewChild` to access the pane.
487 const menuPanel = this._resolvePanel();
488
489 if (menuPanel) {
490 menuPanel.scrollTop = 0;
491 }
492 }
493 } else if (!this._animationsDisabled) {
494 // Some apps do `* { animation: none !important; }` in tests which will prevent the
495 // `animationend` event from firing. Since the exit animation is loading-bearing for
496 // removing the content from the DOM, add a fallback timer.
497 this._exitFallbackTimeout = setTimeout(() => this._onAnimationDone(EXIT_ANIMATION), 200);
498 }
499
500 // Animation events won't fire when animations are disabled so we simulate them.
501 if (this._animationsDisabled) {
502 setTimeout(() => {
503 this._onAnimationDone(isOpen ? ENTER_ANIMATION : EXIT_ANIMATION);
504 });
505 }
506
507 this._changeDetectorRef.markForCheck();
508 }
509
510 /**
511 * Sets up a stream that will keep track of any newly-added menu items and will update the list

Callers 2

_openMenuFunction · 0.80
_destroyMenuFunction · 0.80

Calls 3

_resolvePanelMethod · 0.95
_onAnimationDoneMethod · 0.95
markForCheckMethod · 0.80

Tested by

no test coverage detected