Skip to content

Commit 0b8b5dc

Browse files
committed
fix(dialog): backdrop not being removed if it doesn't have transitions
Fixes the dialog's backdrop not being removed if it's transition have been disabled. Fixes #1607.
1 parent 1e86066 commit 0b8b5dc

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/lib/core/overlay/overlay-ref.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ export class OverlayRef implements PortalHost {
9292

9393
// Add class to fade-in the backdrop after one frame.
9494
requestAnimationFrame(() => {
95-
this._backdropElement.classList.add('md-overlay-backdrop-showing');
95+
if (this._backdropElement) {
96+
this._backdropElement.classList.add('md-overlay-backdrop-showing');
97+
}
9698
});
9799
}
98100

@@ -101,18 +103,27 @@ export class OverlayRef implements PortalHost {
101103
let backdropToDetach = this._backdropElement;
102104

103105
if (backdropToDetach) {
106+
let onTransitionEnd = () => {
107+
if (backdropToDetach) {
108+
backdropToDetach.parentNode.removeChild(backdropToDetach);
109+
110+
// It is possible that a new portal has been attached to this overlay since we started
111+
// removing the backdrop. If that is the case, only clear the backdrop reference if it
112+
// is still the same instance that we started to remove.
113+
if (this._backdropElement == backdropToDetach) {
114+
this._backdropElement = null;
115+
}
116+
}
117+
};
118+
104119
backdropToDetach.classList.remove('md-overlay-backdrop-showing');
105120
backdropToDetach.classList.remove(this._state.backdropClass);
106-
backdropToDetach.addEventListener('transitionend', () => {
107-
backdropToDetach.parentNode.removeChild(backdropToDetach);
108-
109-
// It is possible that a new portal has been attached to this overlay since we started
110-
// removing the backdrop. If that is the case, only clear the backdrop reference if it
111-
// is still the same instance that we started to remove.
112-
if (this._backdropElement == backdropToDetach) {
113-
this._backdropElement = null;
114-
}
115-
});
121+
backdropToDetach.addEventListener('transitionend', onTransitionEnd);
122+
123+
// If the backdrop doesn't have a transition, the `transitionend` event won't fire.
124+
// In this case we make it unclickable and we try to remove it after a delay.
125+
backdropToDetach.style.pointerEvents = 'none';
126+
setTimeout(onTransitionEnd, 500);
116127
}
117128
}
118129
}

0 commit comments

Comments
 (0)