Skip to content

Commit d9bb7ff

Browse files
committed
fix(overlay): backdrop exit animation not working
Fixes the transition when closing an overlay with an opaque backdrop appearing broken. The issue comes the fact that when we start animating the backdrop out, we also remove the `backdropClass` which makes the backdrop transparent. We don't need to remove the class, because we'll remove the backdrop from the DOM and clear the reference once the transition is done.
1 parent 64ef3a8 commit d9bb7ff

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -317,40 +317,40 @@ export class OverlayRef implements PortalOutlet {
317317
detachBackdrop(): void {
318318
let backdropToDetach = this._backdropElement;
319319

320-
if (backdropToDetach) {
321-
let finishDetach = () => {
322-
// It may not be attached to anything in certain cases (e.g. unit tests).
323-
if (backdropToDetach && backdropToDetach.parentNode) {
324-
backdropToDetach.parentNode.removeChild(backdropToDetach);
325-
}
326-
327-
// It is possible that a new portal has been attached to this overlay since we started
328-
// removing the backdrop. If that is the case, only clear the backdrop reference if it
329-
// is still the same instance that we started to remove.
330-
if (this._backdropElement == backdropToDetach) {
331-
this._backdropElement = null;
332-
}
333-
};
334-
335-
backdropToDetach.classList.remove('cdk-overlay-backdrop-showing');
336-
337-
if (this._config.backdropClass) {
338-
backdropToDetach.classList.remove(this._config.backdropClass);
320+
if (!backdropToDetach) {
321+
return;
322+
}
323+
324+
let finishDetach = () => {
325+
// It may not be attached to anything in certain cases (e.g. unit tests).
326+
if (backdropToDetach && backdropToDetach.parentNode) {
327+
backdropToDetach.parentNode.removeChild(backdropToDetach);
339328
}
340329

341-
backdropToDetach.addEventListener('transitionend', finishDetach);
330+
// It is possible that a new portal has been attached to this overlay since we started
331+
// removing the backdrop. If that is the case, only clear the backdrop reference if it
332+
// is still the same instance that we started to remove.
333+
if (this._backdropElement == backdropToDetach) {
334+
this._backdropElement = null;
335+
}
336+
};
342337

343-
// If the backdrop doesn't have a transition, the `transitionend` event won't fire.
344-
// In this case we make it unclickable and we try to remove it after a delay.
345-
backdropToDetach.style.pointerEvents = 'none';
338+
backdropToDetach.classList.remove('cdk-overlay-backdrop-showing');
346339

347-
// Run this outside the Angular zone because there's nothing that Angular cares about.
348-
// If it were to run inside the Angular zone, every test that used Overlay would have to be
349-
// either async or fakeAsync.
350-
this._ngZone.runOutsideAngular(() => {
351-
setTimeout(finishDetach, 500);
352-
});
353-
}
340+
this._ngZone.runOutsideAngular(() => {
341+
backdropToDetach!.addEventListener('transitionend', finishDetach);
342+
});
343+
344+
// If the backdrop doesn't have a transition, the `transitionend` event won't fire.
345+
// In this case we make it unclickable and we try to remove it after a delay.
346+
backdropToDetach.style.pointerEvents = 'none';
347+
348+
// Run this outside the Angular zone because there's nothing that Angular cares about.
349+
// If it were to run inside the Angular zone, every test that used Overlay would have to be
350+
// either async or fakeAsync.
351+
this._ngZone.runOutsideAngular(() => {
352+
setTimeout(finishDetach, 500);
353+
});
354354
}
355355
}
356356

0 commit comments

Comments
 (0)