浏览代码

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.
Kevin Brown 10 年之前
父节点
当前提交
68286e3cff

+ 4 - 0
dist/js/select2.amd.full.js

@@ -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 () {

+ 4 - 0
dist/js/select2.amd.js

@@ -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 () {

+ 4 - 0
dist/js/select2.full.js

@@ -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 () {

文件差异内容过多而无法显示
+ 0 - 0
dist/js/select2.full.min.js


+ 4 - 0
dist/js/select2.js

@@ -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 () {

文件差异内容过多而无法显示
+ 0 - 0
dist/js/select2.min.js


+ 4 - 0
src/js/select2/dropdown/search.js

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

部分文件因为文件数量过多而无法显示