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

[Autocomplete-js npm] result panel leaving space and go down on each page scroll #904

Open
dev-ronak-patel opened this issue Feb 23, 2022 · 14 comments

Comments

@dev-ronak-patel
Copy link

Description

[Autocomplete-js npm] result panel leaving space and go down on each page scroll

Reproduction

go to chrome browser demo where page height is more than screen size and autocomplete input is at top and then scroll one or two time and then click and search. the result will show at little down of autocomplete input

Expected behavior

it should open just attached to autocomplete input

Environment

  • OS: Linux / macOS
  • Browser: Chrome
  • Autocomplete version: [e.g. 1.5.3]
@Haroenv
Copy link
Contributor

Haroenv commented Feb 23, 2022

Screenshot 2022-02-23 at 13 16 12

Is this what you mean? You can change that by overriding the default .aa-Panel { margin: 8px 0 0 }. To have a "glued" autocomplete you can do:

.aa-Panel {
  margin: 0 !important;
}

You'll likely want to change the border-radius of the open panel too then

@dev-ronak-patel
Copy link
Author

No, not this sorry. it is leaving more and more space on each page scroll event. so for reproduce it you will need long page where window scroll is exist and then you can do one scroll and see panel position and then do one more scroll down and see panel position. Hope it make sense.

@Haroenv
Copy link
Contributor

Haroenv commented Feb 23, 2022

I can't reproduce it yet here, could you clarify? https://codesandbox.io/s/determined-dijkstra-ulp2g1?file=/index.html

@dev-ronak-patel
Copy link
Author

so here is the demo https://yu6nvd.csb.app/
not sure if i am doing something wrong
thanks

@dev-ronak-patel
Copy link
Author

image

@Haroenv
Copy link
Contributor

Haroenv commented Feb 23, 2022

Looks like this part of the code is responsible of setting a top value on the panel, which indeed should be tracking the input, not the whole page's scroll

const top = scrollTop + containerRect.top + containerRect.height;

@dev-ronak-patel
Copy link
Author

Yeah, Any quick fix / solution will be helpful. Thanks for investigating !

@dev-ronak-patel
Copy link
Author

So for information, it is properly working with version "1.0.0-alpha.49"

@Haroenv
Copy link
Contributor

Haroenv commented Feb 23, 2022

A workaround is to set the top position manually: https://codesandbox.io/s/sweet-tesla-v8m0y9?file=/src/autocomplete.tsx

@dev-ronak-patel
Copy link
Author

Yeah, can you share more info or code snippet sorry!
Thanks again !

@Haroenv
Copy link
Contributor

Haroenv commented Feb 23, 2022

@ronty123, the code snippet is in the link I shared: https://codesandbox.io/s/sweet-tesla-v8m0y9?file=/src/autocomplete.tsx:6772-7079

  render({ children }, root) {
    // hardcoded fix for https://github.com/algolia/autocomplete/issues/904
    const container = document.querySelector("#autocomplete");
    const rect = container.getBoundingClientRect();
    root.style.top = rect.top + rect.height + "px";

    render(children, root);
  },

@dev-ronak-patel
Copy link
Author

Thanks mate, cheers!

@Giozar
Copy link

Giozar commented Sep 20, 2023

Have you been able to solve the problem? I have the exact same problem

@dev-ronak-patel
Copy link
Author

Yes, it was fixed for me with above solution

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

No branches or pull requests

4 participants