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

Method _setOpen

src/material/sidenav/drawer.ts:585–629  ·  view source on GitHub ↗

* Toggles the opened state of the drawer. * @param isOpen Whether the drawer should open or close. * @param restoreFocus Whether focus should be restored on close. * @param focusOrigin Origin to use when restoring focus.

(
    isOpen: boolean,
    restoreFocus: boolean,
    focusOrigin: Exclude<FocusOrigin, null>,
  )

Source from the content-addressed store, hash-verified

583 * @param focusOrigin Origin to use when restoring focus.
584 */
585 private _setOpen(
586 isOpen: boolean,
587 restoreFocus: boolean,
588 focusOrigin: Exclude<FocusOrigin, null>,
589 ): Promise<MatDrawerToggleResult> {
590 if (isOpen === this.opened) {
591 return Promise.resolve(isOpen ? 'open' : 'close');
592 }
593
594 this._opened.set(isOpen);
595 this._getContent()?._drawerToggled(this);
596
597 if (this._container?._transitionsEnabled) {
598 if (this._isAnimating) {
599 this._setIsAnimating(false);
600 this._simulateAnimation();
601 } else {
602 // Note: it's important to set this as early as possible,
603 // otherwise the animation can look glitchy in some cases.
604 this._setIsAnimating(true);
605
606 // Previously we dispatched this in a `transitionrun` event, but it might not fire
607 // if the element is hidden (see #32992). Since this event is load-bearing for the
608 // margin calculations, we need it to fire consistently.
609 setTimeout(() => this._animationStarted.next());
610 }
611 } else {
612 // Simulate the animation events if animations are disabled.
613 this._simulateAnimation();
614 }
615
616 this._elementRef.nativeElement.classList.toggle('mat-drawer-opened', isOpen);
617
618 if (!isOpen && restoreFocus) {
619 this._restoreFocus(focusOrigin);
620 }
621
622 // Needed to ensure that the closing sequence fires off correctly.
623 this._changeDetectorRef.markForCheck();
624 this._updateFocusTrapState();
625
626 return new Promise<MatDrawerToggleResult>(resolve => {
627 this.openedChange.pipe(take(1)).subscribe(open => resolve(open ? 'open' : 'close'));
628 });
629 }
630
631 /** Gets the current content element. */
632 private _getContent() {

Callers 2

toggleMethod · 0.95

Calls 11

_getContentMethod · 0.95
_setIsAnimatingMethod · 0.95
_simulateAnimationMethod · 0.95
_restoreFocusMethod · 0.95
_updateFocusTrapStateMethod · 0.95
resolveMethod · 0.80
setMethod · 0.80
_drawerToggledMethod · 0.80
markForCheckMethod · 0.80
toggleMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected