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
Fixes IE11 issue with select losing focus having selected an item. #4860
Conversation
I closed the pull request because one of the automated tests failed. |
I did more testing and I don't see any issue even if the test fails. The input field might not have focus, but the select has had its focus call and thus everything works. |
src/js/select2/selection/search.js
Outdated
@@ -175,7 +175,7 @@ define([ | |||
|
|||
this.resizeSearch(); | |||
if (searchHadFocus) { | |||
this.$search.focus(); | |||
this.$element.focus(); |
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.
Will this have side effects on other types of inputs? I did another PR which only modifies the behaviour for tag input as a precaution. https://github.com/select2/select2/pull/4958/files
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.
$element.focus() invokes the focus function of the select2 plugin, not the "tag". This function should handle all cases so I don't think it has any side effects. We are using select elements in our solutions and the bug needs fixing for that too.
Did I understand you correctly?
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.
It seems that there are several competing solutions to this problem:
@ToreOlavKristiansen @jeznag can either of you confirm that this is still an issue in Select2 v4.0.5? We fixed a more glaring issue with |
@alexweissman it is improved in v4.0.5, but it is still a problem for multi-select: focus is lost when selecting an item in IE11. It works fine in Chrome. I tested v4.0.5 with this change. It fixes the problem. |
Alright, I'll merge this in! |
Actually, we need to fix the broken build. If you believe that the failing tests do not reflect accurately on the expected behavior, then we need to change either your code or the tests 😛 I notice that #4958 is handling the focus correctly, so maybe for your solution to work, we just need to add some logic for |
I will test some more tomorrow. In my test earlier today I did not alter base.js and it looked like Chrome was ok without it. If that is the case, I will add another pull request. |
I tested. We need both changes. I modified to please the unit tests. I also fixed an obvious duplicate text issue in the Norwegian translation. |
Awesome, thank you! Not sure what happened with the Norwegian translation, I must have performed a bad merge conflict resolution 😕 |
We use the select2 control a lot and really appreciate all the hard work put in on it. I am glad to contribute. Thanks :) |
Merged into |
Actually, one more question - did you try just checking |
I did. Then everything appears to be working fine, but the unit tests fail:
|
Ah ok, I understand. Everything is wrapped in |
@ToreOlavKristiansen I'm still seeing a possibly related problem in #3168 - can you take a look? |
@alexweissman I do get this issue in IE11. I wouldn't say it is related to the lost focus issue though. I see that the selected items are cleared first and then IE gets the backspace key event and goes back. Should we check for a backspace key event when clearing the items and prevent it from bubbling up? |
We could try that, but I'd like to know why this only seems to affect IE 😕 |
I see that having used backspace, it looks like the control has focus, but is not possible to start typing in Chrome. So the search textbox does not have focus. IE then probably figures since no input field has focus and goes back when it gets the backspace. The issue could be fixed by calling this.$element.focus(); having cleared the items. Then it is perhaps possible to start typing too. |
The prevent default on the event fixes the IE browser back issue. The focus fixes not being able to start typing for both IE and Chrome. |
Interesting...I wonder what #3394 is trying to achieve, then. Seems like it is doing something similar, but in |
Let me know if you want a pull request for this. |
Yes, that would be great! |
Here it is: #5161 I made the mistake of including the dist files. Will you be able to sort that out? |
Thanks! Yes, it would be more helpful if the PR didn't include changes to |
@ToreOlavKristiansen The fix you gave in 5161 doesn't work either. |
This pull request includes a
The following changes were made
If this is related to an existing ticket, include a link to it as #4570 #3332.