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