Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

autofocus: not focusing input on ios 10 #10080

Closed
lionelB opened this issue Dec 2, 2016 · 12 comments
Closed

autofocus: not focusing input on ios 10 #10080

lionelB opened this issue Dec 2, 2016 · 12 comments
Assignees
Labels
os: iOS This issue is specific to iOS P1: urgent Urgent issues that should be addressed in the next minor or patch release. resolution: fixed type: bug ui: CSS

Comments

@lionelB
Copy link

lionelB commented Dec 2, 2016

Actual Behavior:

  • What is the issue? * md-autofocus didn't focus input element, only add a css md-autofocus class
  • What is the expected behavior? Input should receive the focus

CodePen (or steps to reproduce the issue): *

Angular Versions: *

  • Angular Version: 1.5.9
  • Angular Material Version: 1.1.1

Additional Information:

  • Browser Type: * Mobile safari
  • Browser Version: * latest
  • OS: * IOS 10
  • Stack Traces:
@lionelB
Copy link
Author

lionelB commented Dec 2, 2016

This was working as expected is IOS9

@ThomasBurleson ThomasBurleson added this to the 1.1.3 milestone Dec 2, 2016
@ThomasBurleson ThomasBurleson added ui: CSS P1: urgent Urgent issues that should be addressed in the next minor or patch release. labels Dec 2, 2016
@clshortfuse
Copy link
Contributor

Safari on iOS prevents elements from receiving focus if no user interaction triggered the JavaScript code. It's either a timing issue or fastClick is causing issues.

@clshortfuse
Copy link
Contributor

@devversion I believe this may be either gesture related and/or event sequencing. I believe iOS doesn't allow focus on items unless there's an attached touch gesture.

@Splaktar Splaktar added the needs: investigation The cause of this issue is not well understood and needs to be investigated by the team or community label Jul 30, 2018
@Splaktar Splaktar modified the milestones: Future, 1.1.11 Jul 30, 2018
@Splaktar Splaktar assigned Splaktar and unassigned devversion Jul 30, 2018
@Splaktar Splaktar changed the title autofocus not focusing input on ios 10 autofocus: not focusing input on ios 10 Jul 30, 2018
@Splaktar Splaktar added the os: iOS This issue is specific to iOS label Jul 30, 2018
@Splaktar Splaktar modified the milestones: 1.1.11, 1.1.12 Sep 24, 2018
@Splaktar Splaktar modified the milestones: 1.1.12, 1.1.13 Jan 3, 2019
@Splaktar Splaktar modified the milestones: 1.1.13, 1.1.14 Feb 10, 2019
@Splaktar Splaktar modified the milestones: 1.1.14, g3: sync Feb 15, 2019
@Splaktar Splaktar removed this from the g3: sync milestone Apr 1, 2019
@Splaktar Splaktar modified the milestones: 1.1.18, 1.1.19 Apr 1, 2019
@kevin-j-f
Copy link

We're getting the same issue on Angular 1.5.3 with Angular Material 1.1.4. We upgraded material to 1.1.18 and it seems to fix the issue with inputs, but then has the same issue with dropdowns. This only started happening on iOS 12.2 for us, all earlier versions work

@kevin-j-f
Copy link

kevin-j-f commented Apr 17, 2019

https://material.angularjs.org/latest/api/service/$mdGestureProvider

Found out by setting $mdGestureProvider.skipClickHijack(), it fixes the issue. There must be a bug with the click hijacking logic.

@Splaktar
Copy link
Contributor

@kevin-j-f $mdGestureProvider.skipClickHijack() can certainly help with a lot of gesture issues. Setting that fixed it for you in 1.1.4 or it fixed the dropdown issue in 1.1.18?

@clshortfuse
Copy link
Contributor

This is over two years old, but I did write some custom heuristics to safely skip click hijack if it's not needed:

#8996 (comment)

@kevin-j-f
Copy link

@Splaktar

We encountered the issue with input's not being focusable until long press in 1.1.4. Then we upgraded to 1.1.18 and that fixed inputs, but then dropdown's started having the same issue where they would open and then immediately close. We reverted to 1.1.4 and tried to hack things to make it work. We eventually found that skipClickHijack() completely fixed it in 1.1.4, so we didn't upgrade since it's kind of a big app and didn't want to deal with any issues that might have come up from jumping 14 versions.

I imagine that it would fix the dropdown in 1.1.18 after doing some more reading on the issues, but I can't confirm. I was mostly posting in case anyone else was having the issue, we've been searching for a week+ and couldn't find any info, or if it might help someone debug why it causes an issue. Our issues seem to be solved by just turning off click jacking though

@Splaktar Splaktar modified the milestones: 1.1.19, 1.1.20 May 30, 2019
@Splaktar Splaktar modified the milestones: 1.1.20, 1.1.21 Aug 15, 2019
@Splaktar Splaktar added type: bug resolution: fixed and removed needs: investigation The cause of this issue is not well understood and needs to be investigated by the team or community labels Sep 8, 2019
@Splaktar Splaktar removed this from the 1.1.21 milestone Sep 8, 2019
@Splaktar
Copy link
Contributor

Splaktar commented Sep 8, 2019

I just verified that this is fixed in Safari 12 (iOS 12.4.1 tested) using this updated CodePen. This is without the need to call skipClickHijack(). It may also have been fixed in iOS 11.

@welljsjs
Copy link

welljsjs commented Oct 27, 2019

Ah, no, sorry, the example you provided does not work for me. The keyboard does not show up on iOS 13.1.3.

@clshortfuse
Copy link
Contributor

From my own testing, building a solution from scratch, in order for a dialog to show up, focus on an input, and have the keyboard open up:

  • it must all be done within the CLICK event function. You can't delay with setTimeout, or requestAnimationFrame.
  • the input element must be visible. It won't work if the element is not in the viewport bounds (easy for dialogs, harder for tabs)

So, basically, you need to make sure the element dialog and input are visible with synchronous changes to the DOM before the event is over. That means a timeout in the click highjacker won't work. Also, you can't wait for a digest loop either. Nor can you use a promise.

That said, the codepen provided does work for me on 13.1.3, but sometimes it didn't trigger, and I'm not sure why. If there's a fault somewhere, it would be in one of two criteria I described not being met.

@Splaktar Splaktar added this to the 1.1.22 milestone Nov 2, 2019
@Splaktar
Copy link
Contributor

Splaktar commented Nov 2, 2019

I just tested on iPadOS 13.2 with Safari and Chrome and the input was auto focused in both cases (class applied), but the keyboard does not consistently open in the CodePen editor. I think that this is a CodePen issue.

When testing in the debug view on both browsers, the input was focused and the keyboard appeared both times.

@Splaktar Splaktar removed this from the 1.1.22 milestone Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
os: iOS This issue is specific to iOS P1: urgent Urgent issues that should be addressed in the next minor or patch release. resolution: fixed type: bug ui: CSS
Projects
None yet
Development

No branches or pull requests

7 participants