Skip to content

autocompletes overlay position works wrong on mobile devices #6341

Closed

Description

@maku

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?

Activity

  1. willshowell commented on Aug 8, 2017

    @willshowell
    Contributor

    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

  2. crisbeto commented on Aug 8, 2017

    @crisbeto
    Member

    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?

  3. jelbourn commented on Aug 8, 2017

    @jelbourn
    Contributor

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

  4. added
    P3
    on Aug 8, 2017
  5. maku commented on Aug 14, 2017

    @maku
    Author

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

  6. crisbeto commented on Aug 14, 2017

    @crisbeto
    Member

    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.

  7. maku commented on Aug 14, 2017

    @maku
    Author

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

  8. crisbeto commented on Aug 14, 2017

    @crisbeto
    Member

    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.

  9. maku commented on Aug 16, 2017

    @maku
    Author

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

  10. xiongemi commented on Aug 29, 2017

    @xiongemi

    Any update on this issue?

  11. mahmood-sajjadi commented on Aug 31, 2017

    @mahmood-sajjadi

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

  12. crisbeto commented on Aug 31, 2017

    @crisbeto
    Member

    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).

  13. maku commented on Aug 31, 2017

    @maku
    Author

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

  14. 40 remaining items

  15. jpzwarte commented on Jun 27, 2018

    @jpzwarte
    Contributor

    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:

        this.overlayDir.positionChange.subscribe((position: ConnectedOverlayPositionChange) => {
          const clientRect = this.overlayDir.overlayRef.hostElement.getBoundingClientRect();
    
          if (clientRect.top !== 0) {
            const overlayElement = this.overlayDir.overlayRef.overlayElement,
                  overlayY = position.connectionPair.overlayY;
    
            if (overlayY === 'top') {
              const top = parseInt(overlayElement.style.top);
    
              overlayElement.style.top = top + Math.abs(clientRect.top) + 'px';
            } else if (overlayY === 'bottom') {
              const bottom = parseInt(overlayElement.style.bottom);
    
              if (bottom >= Math.abs(clientRect.top)) {
                overlayElement.style.bottom = bottom + clientRect.top + 'px';
              }
            }
          }
        });
    
  16. jinder commented on Jun 27, 2018

    @jinder

    @jpzwarte your workaround seems to work perfectly - thanks. My overlays now position correctly when the iOS keyboard is out.

  17. geoFlux commented on Jun 28, 2018

    @geoFlux

    @jpzwarte I don't understand your solution. How does one get a reference to overlayDir? Do you have a more complete example?

  18. jinder commented on Jun 28, 2018

    @jinder

    @geoFlux you can get it using a ViewChild on your cdkConnectedOverlay directive:

    <ng-template #connectedOverlay="cdkConnectedOverlay" cdkConnectedOverlay></ng-template>
    

    And then in your component:

      @ViewChild("connectedOverlay") private _connectedOverlay: CdkConnectedOverlay;
    
  19. vmachacek commented on Jul 5, 2018

    @vmachacek

    @jinder I was not able to make it work with sample provided. Do you mind sharing plunker, please?

  20. itsanmax commented on Jul 5, 2018

    @itsanmax

    @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.

  21. added a commit that references this issue on Jul 9, 2018
    bceba68
  22. added a commit that references this issue on Jul 10, 2018
    5802e6f
  23. added a commit that references this issue on Jul 11, 2018
    e75ee8d
  24. added a commit that references this issue on Jul 12, 2018
    a248c18
  25. added a commit that references this issue on Jul 25, 2018
    f6e12e0
  26. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  27. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P3

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions