Bug 195884 - Autofocus on text input does not show keyboard
Summary: Autofocus on text input does not show keyboard
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: Safari 12
Hardware: iPhone / iPad iOS 12
: P1 Critical
Assignee: Nobody
Keywords: InRadar
Depends on:
Reported: 2019-03-18 06:41 PDT by pza1
Modified: 2019-03-29 04:49 PDT (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description pza1 2019-03-18 06:41:26 PDT
The javascript focus function does not display the keyboard when it is used outside Touch events, e.g. after being performed by the WKWebView method evaluateJavaScript.
Comment 1 pza1 2019-03-18 07:18:08 PDT
Example code:

webView.evaluateJavaScript("document.getElementById('someElement').focus()", completionHandler: nil)

after that element is focused, but the keyboard does not appear.
Comment 2 pza1 2019-03-18 07:18:22 PDT
Our customers already experienced this problem on their production sites. This feature is critical in case of web application using scanning where users do not want to touch the screen each time they scan something. From user perspective screen should open with focused input and all they need is just hit scan button (e.g. etui with integrated scanner device).
Comment 3 Radar WebKit Bug Importer 2019-03-19 15:41:40 PDT
Comment 4 Daniel Bates 2019-03-19 17:21:29 PDT
So, I've got some good news 🙂 and some bad news 🙁 for you. Let's do good news first:

Following the fix in bug #190017 we now allow programmatic focus if you have a hardware keyboard attached (i.e. calling .focus() in JavaScript will do something now! 🎉)

Now the bad news:

We (Apple) like the current behavior and do not want programmatic focus to bring up the keyboard when you do not have a hardware keyboard attached and the programmatic focus was not invoked in response to a user gesture. Why you may ask...because auto bringing up the software keyboard can be seen as annoying and a distraction to a user (not for your customers, but for everyone not using your app) given that:

1. We bring up the keyboard, which takes up valuable real estate on screen.
2. When we intent to bring up the software keyboard we zoom and scroll the page to give a pleasing input experience (or at least we hope it is pleasing; file bugs if not).

But you're an app developer and are embedding a WKWebView you say... you may be in luck 🍀. I could swear we have API you can toggle to tell WebKit you are OK with auto-showing the keyboard, CC'ing Wenson as maybe my memory is wrong or it's SPI ("private API") or it's non-existent. If we don't have such API then there is still hope for you, re-title this bug, and re-phrase this request as an enhancement. Otherwise, as this bug is titled and worded now it is destined for Resolved Not To Be Fixed.