Autofocus is, in theory, completely unsupported in mobile Safari (http://caniuse.com/#feat=autofocus). We're seeing, however, this very strange behaviour where when a touchstart
event is bound to document
(whether the function has any behaviour or not) when a click happens anywhere on the page the first input with autofocus
becomes focused and the onscreen keyboard displays.
This can be reproduced using iOS 8 in the iOS simulator. Here is the minimal html and javascript to reproduce the problem:
<html>
<head>
<script>
document.addEventListener("touchstart", function() {});
</script>
</head>
<body>
<input type="text">
<input type="text" autofocus="autofocus">
</body>
</html>
And here's a jsfiddle: http://jsfiddle.net/qd858nob/
Simply click anywhere outside of the inputs, and the second input will become autofocused. Ideally I'd love to find a global solution that resolves this without having to remove autofocus from all of our input elements.
See in iOS8 using .focus() will show virtual keyboard and scroll page after touch for a broader discussion on this issue. It looks like it's an iOS 8 "bug". I've filed a report with Apple -- best you can do is the same and hope it bubbles high enough up on their list to fix soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With