Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect panel top position with getBoundingClientRect #591

Closed
deresatom opened this issue May 24, 2021 · 3 comments · Fixed by #593
Closed

Incorrect panel top position with getBoundingClientRect #591

deresatom opened this issue May 24, 2021 · 3 comments · Fixed by #593

Comments

@deresatom
Copy link

Description

The #536 PR attempted to fix a display issue, but this seems to be not working in every case. Sometimes it positions correctly, most of the time it doesn't.

Result panel displayed is displaying in random positions if the page is scrollable.

Reproduction

Steps

  1. Go to codesandbox
  2. Select index.html
  3. Set an arbitrary height +/ margin on the container so we can scroll down
 <div class="container" style="min-height: 1000px;margin-top:200px;">
      <div id="autocomplete"></div>
</div>
  1. Scroll a little bit
  2. Click the autocomplete input, the results panel will be displayed in random positions
autocomplete_1.0.1_getBoundingClientRect.mp4

Expected behavior

The results panel should appear below the autocomplete input field.

Environment

  • OS: Windows 10
  • Browser: Chrome 90.0.4430.212
  • Autocomplete version: 1.0.1
@francoischalifour
Copy link
Member

Thanks for the report!

We're currently working on a fix for this—it'll be shipped during the week.

@deresatom
Copy link
Author

Hey,

Thanks for the super quick fix!

document.body.scrollTop seems to be working inconsistently (sometimes it just calculates 0, sometimes returns the correct position) in Chrome for me.

There is a stackoverflow post regarding scrollTop being deprecated

I adjusted the code and by using this one is working perfectly on my end!

Solution:

var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; 
var top = scrollTop + containerRect.top + containerRect.height;

Thanks guys!
Keep up the great work

@francoischalifour
Copy link
Member

Thanks again @deresatom. I addressed this in #595.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants