1
0
mirror of synced 2025-02-09 16:49:24 +03:00

Search focus should also happen in a timeout

For the dropdown search on single select instances, the search
focus should happen in a `setTimeout` call. This is because many
browsers trigger the element focus on `click`, so our original call
to `$search.focus` will essentially be ignored. By also focusing
it in a timeout, this will delay the call to `focus` so the browser
will no longer take it back.

We do not have this issue for multiple select instances, as they
trigger the `open` event on `click`, instead of using `mousedown`.

This fixes https://github.com/select2/select2/issues/2900.
This commit is contained in:
Kevin Brown 2015-01-08 10:07:33 -05:00
parent e76460a392
commit 68286e3cff
7 changed files with 22 additions and 2 deletions

View File

@ -2890,6 +2890,10 @@ define('select2/dropdown/search',[
self.$search.attr('tabindex', 0);
self.$search.focus();
window.setTimeout(function () {
self.$search.focus();
}, 0);
});
container.on('close', function () {

View File

@ -2890,6 +2890,10 @@ define('select2/dropdown/search',[
self.$search.attr('tabindex', 0);
self.$search.focus();
window.setTimeout(function () {
self.$search.focus();
}, 0);
});
container.on('close', function () {

View File

@ -12425,6 +12425,10 @@ define('select2/dropdown/search',[
self.$search.attr('tabindex', 0);
self.$search.focus();
window.setTimeout(function () {
self.$search.focus();
}, 0);
});
container.on('close', function () {

File diff suppressed because one or more lines are too long

4
dist/js/select2.js vendored
View File

@ -3318,6 +3318,10 @@ define('select2/dropdown/search',[
self.$search.attr('tabindex', 0);
self.$search.focus();
window.setTimeout(function () {
self.$search.focus();
}, 0);
});
container.on('close', function () {

File diff suppressed because one or more lines are too long

View File

@ -40,6 +40,10 @@ define([
self.$search.attr('tabindex', 0);
self.$search.focus();
window.setTimeout(function () {
self.$search.focus();
}, 0);
});
container.on('close', function () {