[DataGrid] Fix scroll jump when holding down arrow keys #15164
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #15158
Reverts #14888 (which tried to fix another regression)
Scrollbar scroll positions are not set directly anymore as they are not the same number (heights of scroller and scrollbar do not match)
With smaller offsets from the top the difference is minimal, but it grows over time which is why the issue can be observed after a bit of scrolling.
The original code also impacts the performance as the values are recalculated a lot more than before the change. All this lead me to revert everything back to the state prior to #14877.
This brought back the very first issue in the chain.
I found out that it is actually caused because of a stale value in
lastPosition
.Following steps in #14830 sets the lock in
onScrollbarScroll
, which prevents any code being executed inonScrollerScroll
so thelastPosition
keeps the old value. CallingscrollToIndexes
end up eventually inonScrollerScroll
, but it does not see the position changed, preventing the scrollbar position change as well.So, after all these updates, the only actual change is moving up the
lastPosition.current = scroller[propertyScroll];
assignment.Internal scrollbar references are still there (comparing to the code prior to all changes), but they could be useful in future. If there are objections, I can remove them as well.
Following issues should not appear anymore
#15158
#14877 (comment)
#14830
Before: https://codesandbox.io/p/sandbox/scroll-jump-before-2fdm8g
After: https://codesandbox.io/p/sandbox/scroll-jump-after-jvv95x