@angular/cdk 13.2.5 → 13.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -492,6 +492,9 @@ class OverlayRef {
492
492
  this._detachments = new Subject();
493
493
  this._locationChanges = Subscription.EMPTY;
494
494
  this._backdropClickHandler = (event) => this._backdropClick.next(event);
495
+ this._backdropTransitionendHandler = (event) => {
496
+ this._disposeBackdrop(event.target);
497
+ };
495
498
  /** Stream of keydown events dispatched to this overlay. */
496
499
  this._keydownEvents = new Subject();
497
500
  /** Stream of mouse outside events dispatched to this overlay. */
@@ -781,22 +784,9 @@ class OverlayRef {
781
784
  if (!backdropToDetach) {
782
785
  return;
783
786
  }
784
- let timeoutId;
785
- const finishDetach = () => {
786
- // It may not be attached to anything in certain cases (e.g. unit tests).
787
- if (backdropToDetach) {
788
- backdropToDetach.removeEventListener('click', this._backdropClickHandler);
789
- backdropToDetach.removeEventListener('transitionend', finishDetach);
790
- this._disposeBackdrop(backdropToDetach);
791
- }
792
- if (this._config.backdropClass) {
793
- this._toggleClasses(backdropToDetach, this._config.backdropClass, false);
794
- }
795
- clearTimeout(timeoutId);
796
- };
797
787
  backdropToDetach.classList.remove('cdk-overlay-backdrop-showing');
798
788
  this._ngZone.runOutsideAngular(() => {
799
- backdropToDetach.addEventListener('transitionend', finishDetach);
789
+ backdropToDetach.addEventListener('transitionend', this._backdropTransitionendHandler);
800
790
  });
801
791
  // If the backdrop doesn't have a transition, the `transitionend` event won't fire.
802
792
  // In this case we make it unclickable and we try to remove it after a delay.
@@ -804,7 +794,10 @@ class OverlayRef {
804
794
  // Run this outside the Angular zone because there's nothing that Angular cares about.
805
795
  // If it were to run inside the Angular zone, every test that used Overlay would have to be
806
796
  // either async or fakeAsync.
807
- timeoutId = this._ngZone.runOutsideAngular(() => setTimeout(finishDetach, 500));
797
+ this._backdropTimeout = this._ngZone.runOutsideAngular(() => setTimeout(() => {
798
+ console.log('fallback');
799
+ this._disposeBackdrop(backdropToDetach);
800
+ }, 500));
808
801
  }
809
802
  /** Toggles a single CSS class or an array of classes on an element. */
810
803
  _toggleClasses(element, cssClasses, isAdd) {
@@ -853,6 +846,8 @@ class OverlayRef {
853
846
  /** Removes a backdrop element from the DOM. */
854
847
  _disposeBackdrop(backdrop) {
855
848
  if (backdrop) {
849
+ backdrop.removeEventListener('click', this._backdropClickHandler);
850
+ backdrop.removeEventListener('transitionend', this._backdropTransitionendHandler);
856
851
  backdrop.remove();
857
852
  // It is possible that a new portal has been attached to this overlay since we started
858
853
  // removing the backdrop. If that is the case, only clear the backdrop reference if it
@@ -861,6 +856,10 @@ class OverlayRef {
861
856
  this._backdropElement = null;
862
857
  }
863
858
  }
859
+ if (this._backdropTimeout) {
860
+ clearTimeout(this._backdropTimeout);
861
+ this._backdropTimeout = undefined;
862
+ }
864
863
  }
865
864
  }
866
865