Skip to content
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

Merged
merged 2 commits into from
Nov 11, 2016

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Nov 3, 2016

Fixes the dialog's backdrop not being removed if it's transition have been disabled.

Fixes #1607.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 3, 2016
backdropToDetach.classList.remove('md-overlay-backdrop-showing');
backdropToDetach.classList.remove(this._state.backdropClass);
backdropToDetach.addEventListener('transitionend', () => {
let styles = getComputedStyle(backdropToDetach);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using getComputedStyle, let's just set pointer-events: none on the backdrop and dismiss it after whichever comes frist: transitionend or a short wait (say, 300ms). This will ensure that the backdrop doesn't get in the way of doing anything and that it always gets removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, although from my testing the getComputedStyle only takes 1-3ms on IE11 and Edge (it's even faster on other browsers). It may be different on a more complex page, though.

@crisbeto crisbeto force-pushed the 1607/backdrop-transition-none branch from e593a8d to 0b8b5dc Compare November 9, 2016 19:02
@crisbeto
Copy link
Member Author

crisbeto commented Nov 9, 2016

Updated @jelbourn. I went with a 500ms timeout, because the default transition is 400ms.

EDIT: Seems like the CI didn't pass due to some null checks. I'll fix it later today.

@crisbeto crisbeto force-pushed the 1607/backdrop-transition-none branch from 0b8b5dc to c68ea6e Compare November 10, 2016 17:10
Fixes the dialog's backdrop not being removed if it's transition have been disabled.

Fixes angular#1607.
// 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';
setTimeout(onTransitionEnd, 500);
Copy link

@rolandjitsu rolandjitsu Nov 10, 2016

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I initially opened the PR, it was using getComputedStyle, however it can cause performance issues in some slower browsers.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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 👍

backdropToDetach.classList.remove(this._state.backdropClass);
backdropToDetach.addEventListener('transitionend', () => {
backdropToDetach.parentNode.removeChild(backdropToDetach);
let onTransitionEnd = () => {
Copy link
Member

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

};

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to remove the backdropClass? Wouldn't this potentially cause the backdrop to appear in cases where we use the class to hide it?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.


// 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need unit test to assert that pointerEvents is set.

@crisbeto
Copy link
Member Author

Updated with a unit test for the pointer-events and renamed callback.

@jelbourn
Copy link
Member

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 11, 2016
@jelbourn jelbourn merged commit accab20 into angular:master Nov 11, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Turning backdrop transition off causes backdrop to stick around
4 participants