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

  1. show the element which wraps the input
  2. set focus on the input

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

Most upvoted comments

@leonalicious

From this current dev channel onwards, the show/toggleVisibility actions will autofocus a 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 explicit focus call (my-input.focus) and let the autofocus attribute 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/show is actually asynchronous (because of batch mutations for performance) but focus is synchronous so focus is actually happening before show!

I will try to find a way to batch focus with the rest of mutations.