amphtml: input.focus is not working on iOS on a default `hidden` element
Good Day there, I have created a demo , please play around with iOS device, by clicking on the button, it will do the following 2 actions
- show the element which wraps the 
input - set 
focuson theinput 
As you can see, on the first click attempt on the button, the focus is not working as expected while it will only work on the second attempt.
About this issue
- Original URL
 - State: closed
 - Created 6 years ago
 - Comments: 23 (23 by maintainers)
 
Commits related to this issue
- ✨Autofocus on `show()` (#20687) ## Breakdown - Autofocuses optional `[autofocus]` element in the displayed tree via `show`/`toggle`. - Forces synchronous display-focus chain on iOS so that progr... — committed to ampproject/amphtml by alanorozco 5 years ago
 - ✨Autofocus on `show()` (#20687) ## Breakdown - Autofocuses optional `[autofocus]` element in the displayed tree via `show`/`toggle`. - Forces synchronous display-focus chain on iOS so that progr... — committed to nbeloglazov/amphtml by alanorozco 5 years ago
 - ✨Autofocus on `show()` (#20687) ## Breakdown - Autofocuses optional `[autofocus]` element in the displayed tree via `show`/`toggle`. - Forces synchronous display-focus chain on iOS so that progr... — committed to noranazmy/amphtml by alanorozco 5 years ago
 
@leonalicious
From this current dev channel onwards, the
show/toggleVisibilityactions willautofocusa corresponding element.Please note that in an explicit show-action chain, e.g.
on="tap: my-container.show, my-input.focus, iOS may actually blur the autofocused element, so it’s important to remove the explicitfocuscall (my-input.focus) and let theautofocusattribute do the work.Feel free to try the feature out in canary and let me know if anything is not working as expected! 😃
@leonalicious Thanks for the report. The root cause of this bus is that 1- iOS never focuses hidden elements 2- Our
hide/showis actually asynchronous (because of batch mutations for performance) butfocusis synchronous so focus is actually happening before show!I will try to find a way to batch
focuswith the rest of mutations.