5

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.

Ben Zittlau
  • 2,345
  • 1
  • 21
  • 30
  • 1
    I'm hitting basically the same issue, but by calling .focus() programmatically on page load. As soon as there's a touch anywhere on the page, focus goes to the input and the keyboard pops up. Have you reported this to Apple? It's new to iOS 8. – Dan Dec 09 '14 at 23:45

1 Answers1

2

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.

Community
  • 1
  • 1
Dan
  • 1,313
  • 1
  • 14
  • 21