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(datepicker): unable to close calendar when opened on focus in IE11 #8918

Merged
merged 1 commit into from
Dec 13, 2017

Conversation

crisbeto
Copy link
Member

Fixes not being able to close a datepicker's calendar in IE11, if the datepicker's trigger opens it on focus. The issue comes down to the fact that all browsers focus elements synchronously, whereas IE does so asynchronously. Since our logic depends on everything firing in sequence, when IE focuses at a later point, the datepicker is already considered as closed which causes the logic that restores focus to the trigger to reopen the calendar.

Fixes #8914.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 10, 2017
this._focusedElementBeforeOpen.focus();
this._focusedElementBeforeOpen = null;
setTimeout(completeClose);
Copy link
Member Author

@crisbeto crisbeto Dec 10, 2017

Choose a reason for hiding this comment

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

Note: I'm not a fan of having to do this timeout, however it's probably the least-breaking option. The alternatives are:

  1. Adding a one-time focus event to the _focusedElementBeforeOpen that completes the closing logic. This works as well as the timeout, however it makes it a lot harder to flush out during unit tests, because you'd need to know the document.activeElement and you'd need to dispatch a fake focus event to it.
  2. Adding a blur event on the currently-focused element so we know when focus was moved. Has the same issues as 1.
  3. Scoping the timeout only to IE. The problem is that it makes unit tests inconsistent. Some fakeAsync tests would run fine on all browsers, but throw an X timer(s) still in queue error in IE.

Copy link
Contributor

@mmalerba mmalerba Dec 11, 2017

Choose a reason for hiding this comment

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

is Promise.resolve().then too quick for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't remember trying it, but it should work. I went with the timeout since it would be more obvious what you need to do if your tests start failing. We can switch to the Promise.resolve if we want to make the sync easier.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to use it when possible since it executes quicker. I think adding a flush to your test will fix it in either case

Copy link
Member Author

Choose a reason for hiding this comment

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

It will, but the Promise.resolve won't throw the X timers in queue error which makes it a little harder to track down.

Copy link
Contributor

Choose a reason for hiding this comment

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

really? so what happens if it never gets flushed, does the test just pass?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whatever is supposed to execute in the callback will happen after the test. In our case the opened property on the datepicker would always stay at false.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that sucks, would have expected fakeAsync to catch that. Fine with leaving it as setTimeout then

@crisbeto crisbeto force-pushed the 8914/datepicker-ie11-on-focus branch from 4f48754 to e636e02 Compare December 10, 2017 14:24
Fixes not being able to close a datepicker's calendar in IE11, if the datepicker's trigger opens it on focus. The issue comes down to the fact that all browsers focus elements synchronously, whereas IE does so asynchronously. Since our logic depends on everything firing in sequence, when IE focuses at a later point, the datepicker is already considered as closed which causes the logic that restores focus to the trigger to reopen the calendar.

Fixes angular#8914.
@crisbeto crisbeto force-pushed the 8914/datepicker-ie11-on-focus branch from e636e02 to d166b24 Compare December 10, 2017 15:14
@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Dec 11, 2017
@crisbeto crisbeto added the target: minor This PR is targeted for the next minor release label Dec 11, 2017
@andrewseguin andrewseguin merged commit a411382 into angular:master Dec 13, 2017
@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 7, 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 target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IE11: Datepicker cannot be dismissed by user interaction after being opened programmatically
4 participants