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

Make scrollToIndex (and scheduleImperativeScroll) awaitable #621

Open
blarfoon opened this issue Feb 2, 2025 · 2 comments
Open

Make scrollToIndex (and scheduleImperativeScroll) awaitable #621

blarfoon opened this issue Feb 2, 2025 · 2 comments

Comments

@blarfoon
Copy link

blarfoon commented Feb 2, 2025

I understand I probably have a very niche use case, but here it is.

I am implementing a find functionality in my app (very very similar to vscode ctrl + f). When the user clicks the next arrow I want the view to scroll to the next result. If the result is in a row that is already loaded in the dom there is no issue as I can directly scroll to it (since I have its dom ref).

The problem arises when the next result is in a row that is not loaded because too far away. In that case I need to first call scrollToIndex to the row index, and only once it's scrolled and loaded I can do my own scrolling to the specific result within the row (a row could be arbitrarily long).
What I am currently trying to do is something like

vRef.scrollToIndex(rowIndex)
currentResultRef.scrollIntoView({
  behavior: "instant",
  block: "center",
  inline: "center"
})

The problem is that scrollToIndex could take an arbitrary amount of time to complete because of how scheduleImperativeScroll works, and always overrides my own scrollIntoView.

Making scrollToIndex (and hence scheduleImperativeScroll) awaitable would probably fix this issue.
I am also open to other solutions because honestly I'm out of ideas on how to properly implement this

@inokawa
Copy link
Owner

inokawa commented Feb 3, 2025

A workaround in #542 (reply in thread) may solve it. And I agree with that awaitable scrollTo is needed in some case.

@blarfoon
Copy link
Author

blarfoon commented Feb 3, 2025

Worked like a charm! Unfortunately align center doesn't do much since the position is calculated with the offset, but with a bit or offset trickery I got it working! Thank you :)

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

No branches or pull requests

2 participants