ftlabs / fastclick

Polyfill to remove click delays on browsers with touch UIs
MIT License
18.66k stars 3.23k forks source link

ios input focus bug #571

Open yansm opened 5 years ago

yansm commented 5 years ago

FastClick.prototype.focus = function(targetElement) { var length; if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') { // must targetElement.focus() first length = targetElement.value.length; targetElement.setSelectionRange(length, length); } else { targetElement.focus(); } }; method setSelectionRange can set selection in a focused input element and in this example (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange),
function SelectText () { var input = document.getElementById("mytextbox"); input.focus(); input.setSelectionRange(2,5); }

also input.focus() first so, if you want use setSelectionRange, you must input.focus() first

in my code, click input can not focus, must rewrite FastClick.prototype.focus.

is it a bug in ios?

franciscobrba commented 5 years ago

@ftlabs please, help with that

AntiMoron commented 4 years ago

Try this?

class="needsclick"

This works for me... I ran into same problem today.