removing focused input element from DOM breaks text selection

Originator:stefan-google
Number:rdar://45040527 Date Originated:October 5 2018
Status:Open Resolved:
Product:iOS + SDK | Safari Product Version:12.0 (16A366)
Classification: Reproducible:yes
 
Area:
Safari

Summary:
When a focused input element (i.e. keyboard open) is removed from the DOM through JavaScript, iOS automatically dismisses the keyboard without restoring the ability to select text. 

Steps to Reproduce:
1. save attached index.html somewhere
2. serve the file so that iOS Safari can view it
3. Observe selecting text works
4. Focus the text field. Selecting text is now disabled. This appears to be by design.
5. click "remove field" button, which removes field from the DOM
6. Observe selecting text is now broken, even though the keyboard was auto-dismissed

Expected Results:
After clicking the "remove field" button, I expect to be able to select text again.

Actual Results:
Can't select text.

Version/Build:
12.0 (16A366), multiple devices
We cannot reproduce it on iOS 10.

Note:
The index.html is a minimal example to reproduce the issue. The actual use case is a simple React app with a form.



index.html attachment:
<!doctype html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>

<body>
  <ol>
    <li>Observe selecting text works</li>
    <li>Focus the text field. Selecting text is now disabled. This appears to be by design.</li>
    <li>click "remove field" button, which removes field from the DOM</li>
    <li>Observe selecting text is now broken, even though the keyboard was auto-dismissed</li>
  </ol>

  <input id="field">
  <button onclick="document.getElementById('field').remove()">remove field</button>
</body>
</html>

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!