Repository navigation
Description
Current behavior 🐛
In a browser on iOS, a TextBox that takes focus from code outside of a user gesture, such as the first field of a dialog that opens, shows its caret but no soft keyboard. Tapping the TextBox does not bring the keyboard up either. It takes tapping another field and coming back, or tapping the TextBox a couple more times.
Seen on an iOS device with an application on a 6.8 build.
By default WebKit shows the input view for an element only when it was focused while the user was interacting with the page, when it takes over from an element already being assisted, or when a hardware keyboard is attached (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]). The hidden <input> is focused from code, so none of those holds. The tap then lands on the canvas: the TextBox has focus already, the hidden input is not focused again, and nothing tells WebKit that the user asked for the field.
It does not show in the iOS Simulator with the Mac's keyboard connected, which the hardware keyboard exemption would explain.
Expected behavior 🎯
Tapping the focused TextBox brings up the keyboard.
(The keyboard coming up along with the dialog, as in a native app, is a separate matter: iOS does not show it for a focus made once the tap is over.)
How to reproduce it (as minimally and precisely as possible) 🔬
- A page with a
Buttonthat opens aContentDialogholding aTextBox, which is focused from code when the dialog has loaded (Focus(FocusState.Programmatic)). - Open the WebAssembly head in a browser on an iOS device and tap the button.
- The dialog opens with the caret in the
TextBoxand no keyboard. - Tap the
TextBox: still no keyboard.
Workaround 🛠️
Not focusing the TextBox from code on iOS, so that the first tap is what focuses it.
Affected platforms 📱💻🖥️
WebAssembly (Skia renderer), browsers on iOS
Uno.Sdk version (and other relevant versions) 📦
A 6.8 build (6.8.0-dev.212). The code involved is the same on master at efa2954.
IDE version 🧑💻
Not IDE related.
Anything else we need to know? 💬
This was first reported in #22258, for a ContentDialog that opens on a focused TextBox. This issue is about the half of it a page can do something about: the tap on the focused field.
A PR with a fix follows: the hidden input is focused again when its TextBox is tapped. WebKit treats focus() on the focused element as a refocus (Element::focus calls elementDidRefocus) and reports it to the UI process as long as no input view is showing for the element (WebPage::shouldDispatchUpdateAfterFocusingElement), this time as made while the user was interacting.
Activity