Skip to content

Commit

Permalink
fix(overlay): backdrop exit animation not working
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto committed Feb 26, 2018
1 parent 64ef3a8 commit d9bb7ff
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/cdk/overlay/overlay-ref.ts
Expand Up @@ -317,40 +317,40 @@ export class OverlayRef implements PortalOutlet {
detachBackdrop(): void {
let backdropToDetach = this._backdropElement;

if (backdropToDetach) {
let finishDetach = () => {
// It may not be attached to anything in certain cases (e.g. unit tests).
if (backdropToDetach && backdropToDetach.parentNode) {
backdropToDetach.parentNode.removeChild(backdropToDetach);
}

// It is possible that a new portal has been attached to this overlay since we started
// removing the backdrop. If that is the case, only clear the backdrop reference if it
// is still the same instance that we started to remove.
if (this._backdropElement == backdropToDetach) {
this._backdropElement = null;
}
};

backdropToDetach.classList.remove('cdk-overlay-backdrop-showing');

if (this._config.backdropClass) {
backdropToDetach.classList.remove(this._config.backdropClass);
if (!backdropToDetach) {
return;
}

let finishDetach = () => {
// It may not be attached to anything in certain cases (e.g. unit tests).
if (backdropToDetach && backdropToDetach.parentNode) {
backdropToDetach.parentNode.removeChild(backdropToDetach);
}

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

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

// Run this outside the Angular zone because there's nothing that Angular cares about.
// If it were to run inside the Angular zone, every test that used Overlay would have to be
// either async or fakeAsync.
this._ngZone.runOutsideAngular(() => {
setTimeout(finishDetach, 500);
});
}
this._ngZone.runOutsideAngular(() => {
backdropToDetach!.addEventListener('transitionend', finishDetach);
});

// If the backdrop doesn't have a transition, the `transitionend` event won't fire.
// In this case we make it unclickable and we try to remove it after a delay.
backdropToDetach.style.pointerEvents = 'none';

// Run this outside the Angular zone because there's nothing that Angular cares about.
// If it were to run inside the Angular zone, every test that used Overlay would have to be
// either async or fakeAsync.
this._ngZone.runOutsideAngular(() => {
setTimeout(finishDetach, 500);
});
}
}

Expand Down

0 comments on commit d9bb7ff

Please sign in to comment.