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

feat(js): scroll to top when query changes #457

Merged
merged 3 commits into from
Feb 19, 2021

Conversation

francoischalifour
Copy link
Member

Description

This scrolls to the top of the panel when the query changes (i.e., when new results come in) so that users don't have to.

How

We introduce a new CSS utility class in the theme called .aa-Panel--Scrollable which hints Autocomplete that this is the container responsible for displaying the list of items.

By default, this CSS class is attached to .aa-PanelLayout, but when we introduce the Preview Panel plugin, it will be attached to the left child of .aa-PanelLayout.

Whenever the query changes, we scroll to the top of this scrollable container.

Preview

Before

ac-scrolltop-query-change-before

After

ac-scrolltop-query-change-after

@shortcuts
Copy link
Member

shortcuts commented Feb 19, 2021

Could it make sense to expose this as a boolean (e.g. scrollToTopOnQueryUpdate)? I feel like this could be something that the user would want to toggle in some special cases

@francoischalifour
Copy link
Member Author

@shortcuts When would you want to not have this behavior?

@shortcuts
Copy link
Member

shortcuts commented Feb 19, 2021

@francoischalifour in some e-commerce cases I guess. I could imagine some side-by-side sections (like https://www.ldlc.com/) where you'd probably don't want to scroll all of them but handle it separately.

@francoischalifour
Copy link
Member Author

@shortcuts That's exactly why we have this .aa-Panel--Scrollable CSS class, you can add it to the containers you need 🙂

That makes me think that we should use document.querySelectorAll to scroll to the top of all the containers marked with this CSS class.

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart choice

@francoischalifour francoischalifour merged commit 706939c into next Feb 19, 2021
@francoischalifour francoischalifour deleted the feat/scroll-top-on-query-change branch February 19, 2021 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants