-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dialog): backdrop not being removed if it doesn't have transitions #1716
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
} | ||
}); | ||
} | ||
|
||
|
@@ -101,18 +103,28 @@ 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', () => { | ||
backdropToDetach.parentNode.removeChild(backdropToDetach); | ||
let onTransitionEnd = () => { | ||
// 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('md-overlay-backdrop-showing'); | ||
backdropToDetach.classList.remove(this._state.backdropClass); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the custom class that can be added to the backdrop. It has been handled like that since 0b54668, I only moved it around. |
||
backdropToDetach.addEventListener('transitionend', onTransitionEnd); | ||
|
||
// 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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need unit test to assert that |
||
setTimeout(onTransitionEnd, 500); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if timeouts are reliable. What if at some point the transition timing is changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I initially opened the PR, it was using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, forgot to mention that it would probably make more sense to switch this over to Angular's animation API. This fix should suffice for now, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wanted to point out that there might be a better way of handling this, but if this can make it to the next alpha I guess it works 👍 |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this can be used in two ways now, we should rename it to something like
finishDetach