You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
autocompletes overlay position works wrong on mobile devices #6341
Correct overlay position so that the component can be used on mobile devices
What is the current behavior?
On mobile devices (e.g iphone6+ with latest IOS, Android etc.) the position of the overlay is strange.
Sometimes the overlay disappears or the overlay overlaps the input fields ...
So autocomplete is NOT usable on mobile devices....
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 4.3.3, Material 2.0.0-beta.8
Is there anything else we should know?
Reacted by Dylan Van Bommel, Nico Cunin, Vlad Dubov, Jeff Heigl, Robert Dey, martynas19942, Massimo Artizzu, Dmytro, Lukas Shawford, Markus Mohoritsch and 5 more
The issue is that the keyboard animation throws off the positioning logic. I've been considering whether having a setTimeout on focus for iOS and Android would make sense @jelbourn?
The initial plan was to address this after we refactor some of our positioning logic, but I suppose that shouldn't really change what we do in the autocomplete. There should be a way for you to patch it on your side temporarily, but it'll be very hacky, because it would need to access private properties on the autocomplete trigger.
I've been playing around with the approach I mentioned above, but it doesn't really work the way I expected it to. It seems like the autocomplete does figure out the proper position values, however iOS throws it off when it scrolls the input into the middle of the view. Delaying the positioning call doesn't help in this case.
This is somewhat tricky to fix on our end, because iOS seems to shift the coordinate grid when it focuses the into view, which makes it so we can't recalculate the position correctly. The best approach for now might be to disable scrolling for the autocomplete altogether. See #5187 (comment).
So aside from the PR, i also added a workaround to my custom component. The code below works for me on iOS: the overlay is positioned correctly when scrolling with the keyboard visible:
@stevenmcountryman : Thanks for your solution provided here: #6341 (comment). I've applied same solution in my project. This resolve issue of showing list options at correct position but getting issue with selecting option by clicking function "selectItem(item)". Issue here is, selectItem function fires on 2nd time click. It doesn't fire on first time click. Any idea how to solve this issue? It would be really great help if you can help to sort out this issue.
Activity
willshowell commentedon Aug 8, 2017
The positioning of the autocomplete just changed to be more accurately connected to the input. Here is an example with the latest build: http://plnkr.co/edit/HnQwfr7WlNVLdP3P6ukQ?p=preview
However, I am still seeing some weird positioning in landscape mode with the keyboard open:
crisbeto commentedon Aug 8, 2017
The issue is that the keyboard animation throws off the positioning logic. I've been considering whether having a
setTimeouton focus for iOS and Android would make sense @jelbourn?jelbourn commentedon Aug 8, 2017
@crisbeto that seems reasonable if we scope the delay to only apply for these cases. Let's address this after the overlay positioning refactor
maku commentedon Aug 14, 2017
@crisbeto is there any timeframe until func is getting better on IOS -> Otherwise I have to consider to replace autocomplete temporarly...
crisbeto commentedon Aug 14, 2017
The initial plan was to address this after we refactor some of our positioning logic, but I suppose that shouldn't really change what we do in the autocomplete. There should be a way for you to patch it on your side temporarily, but it'll be very hacky, because it would need to access private properties on the autocomplete trigger.
maku commentedon Aug 14, 2017
@crisbeto what is the way to "patch" autocomplete so that it work better on IOS???
crisbeto commentedon Aug 14, 2017
I've been playing around with the approach I mentioned above, but it doesn't really work the way I expected it to. It seems like the autocomplete does figure out the proper position values, however iOS throws it off when it scrolls the input into the middle of the view. Delaying the positioning call doesn't help in this case.
maku commentedon Aug 16, 2017
@crisbeto Is there a solution to this problem? What is the recommended way to go?
xiongemi commentedon Aug 29, 2017
Any update on this issue?
mahmood-sajjadi commentedon Aug 31, 2017
@crisbeto, @maku is there any workaround or patch for this issue?
crisbeto commentedon Aug 31, 2017
This is somewhat tricky to fix on our end, because iOS seems to shift the coordinate grid when it focuses the into view, which makes it so we can't recalculate the position correctly. The best approach for now might be to disable scrolling for the autocomplete altogether. See #5187 (comment).
maku commentedon Aug 31, 2017
@crisbeto dump question - how do other ui libraries handle this problem?
40 remaining items
jpzwarte commentedon Jun 27, 2018
So aside from the PR, i also added a workaround to my custom component. The code below works for me on iOS: the overlay is positioned correctly when scrolling with the keyboard visible:
jinder commentedon Jun 27, 2018
@jpzwarte your workaround seems to work perfectly - thanks. My overlays now position correctly when the iOS keyboard is out.
geoFlux commentedon Jun 28, 2018
@jpzwarte I don't understand your solution. How does one get a reference to overlayDir? Do you have a more complete example?
jinder commentedon Jun 28, 2018
@geoFlux you can get it using a ViewChild on your cdkConnectedOverlay directive:
And then in your component:
vmachacek commentedon Jul 5, 2018
@jinder I was not able to make it work with sample provided. Do you mind sharing plunker, please?
itsanmax commentedon Jul 5, 2018
@stevenmcountryman : Thanks for your solution provided here: #6341 (comment). I've applied same solution in my project. This resolve issue of showing list options at correct position but getting issue with selecting option by clicking function "selectItem(item)". Issue here is, selectItem function fires on 2nd time click. It doesn't fire on first time click. Any idea how to solve this issue? It would be really great help if you can help to sort out this issue.
fix(overlay): account for virtual keyboard offset on mobile devices
fix(overlay): account for virtual keyboard offset on mobile devices
fix(overlay): account for virtual keyboard offset on mobile devices
fix(overlay): account for virtual keyboard offset on mobile devices (#…
fix(overlay): account for virtual keyboard offset on mobile devices (#…
angular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.