1
0
mirror of synced 2024-11-22 13:06:08 +03:00

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]: d87e93dd45
[4]: http://stackoverflow.com/a/15439809/359284
[5]: https://github.com/ivaynberg/select2/issues/1541#issuecomment-39805859
This commit is contained in:
Kevin Brown 2014-04-20 13:42:43 -04:00
parent 79e031fbdf
commit 2e79f5eb4f

View File

@ -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;