소스 검색

Only disable keyboard focusing for touch devices [Fixes #1541]

This fixes the issue [1] by first checking to see if the current
device is a touch device.  The other issue [2] that occured because
of the original fix [3] is now fixed, because the hidden inputs
are always focused by default on non-touch devices.

The code used for detecting touch devices was pulled from
StackOverflow [4].  Information on the reasoning behind this fix
can be found on GitHub [5].

[1]: https://github.com/ivaynberg/select2/issues/1541
[2]: https://github.com/ivaynberg/select2/issues/2223
[3]: https://github.com/ivaynberg/select2/commit/d87e93dd45ade99e7894ac4854bf65e8f59667d4
[4]: http://stackoverflow.com/a/15439809/359284
[5]: https://github.com/ivaynberg/select2/issues/1541#issuecomment-39805859
Kevin Brown 11 년 전
부모
커밋
2e79f5eb4f
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      select2.js

+ 9 - 0
select2.js

@@ -3384,6 +3384,15 @@ the specific language governing permissions and limitations under the Apache Lic
         searchInputPlaceholder: '',
         createSearchChoicePosition: 'top',
         shouldFocusInput: function (instance) {
+            // Attempt to detect touch devices
+            var supportsTouchEvents = (('ontouchstart' in window) ||
+                                       (navigator.msMaxTouchPoints > 0));
+
+            // Only devices which support touch events should be special cased
+            if (!supportsTouchEvents) {
+                return true;
+            }
+
             // Never focus the input if search is disabled
             if (instance.opts.minimumResultsForSearch < 0) {
                 return false;