Skip to content

Commit

Permalink
fix(dialog): backdrop not being removed if it doesn't have transitions
Browse files Browse the repository at this point in the history
Fixes the dialog's backdrop not being removed if it's transition have been disabled.

Fixes #1607.
  • Loading branch information
crisbeto committed Nov 3, 2016
1 parent 1e86066 commit e593a8d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/lib/core/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export class OverlayRef implements PortalHost {

// Add class to fade-in the backdrop after one frame.
requestAnimationFrame(() => {
this._backdropElement.classList.add('md-overlay-backdrop-showing');
if (this._backdropElement) {
this._backdropElement.classList.add('md-overlay-backdrop-showing');
}
});
}

Expand All @@ -101,9 +103,8 @@ export class OverlayRef implements PortalHost {
let backdropToDetach = this._backdropElement;

if (backdropToDetach) {
backdropToDetach.classList.remove('md-overlay-backdrop-showing');
backdropToDetach.classList.remove(this._state.backdropClass);
backdropToDetach.addEventListener('transitionend', () => {
let styles = getComputedStyle(backdropToDetach);
let onTransitionEnd = () => {
backdropToDetach.parentNode.removeChild(backdropToDetach);

// It is possible that a new portal has been attached to this overlay since we started
Expand All @@ -112,7 +113,16 @@ export class OverlayRef implements PortalHost {
if (this._backdropElement == backdropToDetach) {
this._backdropElement = null;
}
});
};

backdropToDetach.classList.remove('md-overlay-backdrop-showing');
backdropToDetach.classList.remove(this._state.backdropClass);

if (parseFloat(styles.transitionDuration)) {
backdropToDetach.addEventListener('transitionend', onTransitionEnd);
} else {
onTransitionEnd();
}
}
}
}
Expand Down

0 comments on commit e593a8d

Please sign in to comment.