Browse Source

select字段focus自动展开

Edwin Xu 3 years ago
parent
commit
4a3f26b37d
1 changed files with 15 additions and 0 deletions
  1. 15 0
      resources/views/scripts/select.blade.php

+ 15 - 0
resources/views/scripts/select.blade.php

@@ -59,3 +59,18 @@
 </script>
 @endif
 
+<script once>
+    // on first focus (bubbles up to document), open the menu
+    $(document).off('focus', '.select2-selection.select2-selection--single')
+        .on('focus', '.select2-selection.select2-selection--single', function (e) {
+            $(this).closest(".select2-container").siblings('select:enabled').select2('open');
+        });
+
+    // steal focus during close - only capture once and stop propogation
+    $(document).off('select2:closing', 'select.select2')
+        .on('select2:closing', 'select.select2', function (e) {
+            $(e.target).data("select2").$selection.one('focus focusin', function (e) {
+                e.stopPropagation();
+            });
+        });
+</script>