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(useInfiniteScroll): new options #1354

Merged
merged 4 commits into from May 31, 2022
Merged

feat(useInfiniteScroll): new options #1354

merged 4 commits into from May 31, 2022

Conversation

innocenzi
Copy link
Contributor

Description

This PR adds two new options to useInfiniteScroll:

  • direction, to chose in which direction to use the infinite scroll
  • keepScrollPosition, to automatically compute the scroll position so it stays in place

The current behavior stays the same without explicitly defining these options.

Use case

I was building a chat with infinite scroll, which I want to behave kind of like Discord when you scroll up. For this, I had to revert the direction to top instead of the default bottom, and I needed to keep the scroll position the same after updating the message list.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@antfu antfu merged commit 5a1b932 into vueuse:main May 31, 2022
@innocenzi innocenzi deleted the feat/infinite-scroll-options branch May 31, 2022 13:06
@vincentbernat
Copy link

Did you consider adding direction: both as an option?

@innocenzi
Copy link
Contributor Author

No I didn't, how would that work and what's the use case?

@vincentbernat
Copy link

You could want to browse database records indexed by time of the day in both directions. You start at a given date and you can either scroll up or down. The callback function would need to receive the direction. I may implement that myself once I need it. I was just curious if you already considered it and didn't do it due to some difficulty.

@innocenzi
Copy link
Contributor Author

Ah true. I just thought of how Discord loads messages too, that's a use case. I didn't consider it because I didn't think of a use case, so I don't know if there are specific difficulties, but I don't think so. Feel free to PR when you need the feature. :)

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.

None yet

4 participants