-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: store scroll pos when virtualized #8767
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR. There still seems to be some bad scroll behaviours, I'm not sure if it's related? I've built your PR over at #8773
|
@snowystinger Thanks for the build, we can take care of that issue also 👍 |
@snowystinger The issue you discovered only exists in storybook because the keyboard modality is never recognized when the relatedTarget is outside the owner document. When you test this with adjacent inputs the issue is gone 👍 |
I added buttons to the story in the PR where I built this to ease testing on our end. Thanks for chasing that down. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to make sense, will get others on the team to review it now. Thank you!
Closes #8234
This PR makes three changes:
1. Use isFocused instead of focusedKey for tabIndex
Previously, the tabIndex was determined by whether focusedKey was null. However, focusedKey persists even after tabbing out of the collection. This caused the collection root to remain non-tabbable, and as a result the browser would default to focusing the first or last focusable element inside the collection (e.g., a button) when tabbing back in. Once the browser focused that button, the focus logic ran and scrolled the focusedKey item into view — which led to the “jump” that was observed. By switching the condition to use isFocused instead, the collection root becomes tabbable whenever the collection itself is not focused. This prevents the browser from landing on inner focusable elements and eliminates the initial jump when tabbing back into the collection.
2. Always track scroll position
The useEvent(scrollRef, 'scroll', ...) handler is now always active, rather than being disabled for virtualized collections. This ensures the current scroll position is always stored, even when virtualization is used.
3. Always restore scroll position on focus
Similarly, the scroll position is now restored whenever the collection regains focus, regardless of whether it is virtualized. This prevents jumps when shift+tabbing back into the collection. I guess the issue #2233 is connected to the problem.
I am still curious why scroll position saving/restoring was originally disabled for virtualized collections. My assumption is that it may have been excluded to avoid interfering with virtualization behavior or for performance reasons.
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: