components icon indicating copy to clipboard operation
components copied to clipboard

autocompletes overlay position works wrong on mobile devices

Open maku opened this issue 9 years ago • 59 comments

Bug, feature request, or proposal:

Bug

What is the expected behavior?

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 are the steps to reproduce?

E.g. use the https://material.angular.io/ demo for autocomplete 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?

maku avatar Aug 08 '17 06:08 maku

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:

img_4975

willshowell avatar Aug 08 '17 13:08 willshowell

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?

crisbeto avatar Aug 08 '17 16:08 crisbeto

@crisbeto that seems reasonable if we scope the delay to only apply for these cases. Let's address this after the overlay positioning refactor

jelbourn avatar Aug 08 '17 16:08 jelbourn

@crisbeto is there any timeframe until func is getting better on IOS -> Otherwise I have to consider to replace autocomplete temporarly...

maku avatar Aug 14 '17 10:08 maku

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.

crisbeto avatar Aug 14 '17 10:08 crisbeto

@crisbeto what is the way to "patch" autocomplete so that it work better on IOS???

maku avatar Aug 14 '17 10:08 maku

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.

crisbeto avatar Aug 14 '17 20:08 crisbeto

@crisbeto Is there a solution to this problem? What is the recommended way to go?

maku avatar Aug 16 '17 05:08 maku

Any update on this issue?

xiongemi avatar Aug 29 '17 15:08 xiongemi

@crisbeto, @maku is there any workaround or patch for this issue?

mahmood-sajjadi avatar Aug 31 '17 04:08 mahmood-sajjadi

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 https://github.com/angular/material2/issues/5187#issuecomment-324371834.

crisbeto avatar Aug 31 '17 05:08 crisbeto

@crisbeto dump question - how do other ui libraries handle this problem?

maku avatar Aug 31 '17 12:08 maku

The easiest way to handle it would be to use position: absolute to position the panel, however that is problematic when dealing with focus and overflow.

crisbeto avatar Aug 31 '17 16:08 crisbeto

@crisbeto I would really appreciate an advice what to do... - should we drop using autocomplete?? and looking for an alternative (also the fix #5187 does not work for me) Is there anything in the pipeline? The component as it is is NOT usable on IOS.

Just to be curious - what problems does material2 have what other libs don't have (so that this stuff works on IOS)?

maku avatar Sep 02 '17 12:09 maku

@crisbeto I really do not want to be annoying. But is there any kind of solution on the horizon?

maku avatar Sep 08 '17 14:09 maku

Any updates? using latest and issue with iOS positioning as well as touch. I can not select an item from autoComplete component. I'm using the code from your example to test. I have hammer js installed the toggle button works and requires hammer js as per your spec. Not sure why I can not select an item but positioning is still an issue. Thanks!

MatteoNY avatar Oct 04 '17 17:10 MatteoNY

This very issue is causing headaches on my side too.

The following two suggestions have helped the situation and make the autocomplete somewhat usable on iOS:

  1. Add cdkScrollable to your <main …> element (@crisbeto, #4557)
  2. Add custom scrolling strategy (@aitboudad, #5187)

LukasKlement avatar Oct 04 '17 22:10 LukasKlement

We have a related issue, maybe it's the same.

For us, the dropdown list gets hidden entirely by the keyboard, instead of the dropdown list going upwards (the autosuggest field is in the middle of the page).

https://imgur.com/a/nrBUw

kasperhhk avatar Oct 26 '17 08:10 kasperhhk

Any updates on this issue?! I'm facing the same problem!!

murilobd avatar Nov 06 '17 19:11 murilobd

Just want to add my thoughts on this. As I am facing this issue as well. Not sure if any of this information will help, but figured to add some notes here.

When testing on an iPad in debug mode connected to a MacBook, I noticed that when highlighting the AutoCompletePanel in the HTML element in the debugger, it does highlight the element, and the highlight is shown directly underneath the input field. So the positioning of the css is correct.

But the kicker is that the browser is rendering the auto complete panel NOT where the highlighted HTML is. Which leads me to believe that it is something with how iOS Safari is rendering the HTML elements while the keyboard is up.

This is just a comment supporting @crisbeto comment regaring iOS shifting it's coordinate grid.

michaeldev6 avatar Nov 20 '17 17:11 michaeldev6