-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[DataGrid] Fix scroll jump with dynamic row height #16763
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
Merged
cherniavskii
merged 6 commits into
mui:master
from
cherniavskii:dynamic-row-height-scroll-jump
Mar 3, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7974c3b
add failing unit test
cherniavskii 21f90e0
try to make test fail in ci
cherniavskii 4f3140c
.only
cherniavskii 8af9006
log scrollPositions
cherniavskii 542c40d
add e2e test instead
cherniavskii 935e56f
fix failing test
cherniavskii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
|
||
const rows = [ | ||
{ id: 0 }, | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
{ id: 4 }, | ||
{ id: 5 }, | ||
{ id: 6 }, | ||
{ id: 7 }, | ||
{ id: 8 }, | ||
{ id: 9 }, | ||
{ id: 10 }, | ||
{ id: 11 }, | ||
{ id: 12 }, | ||
{ id: 13 }, | ||
{ id: 14 }, | ||
{ id: 15 }, | ||
{ id: 16 }, | ||
{ id: 17 }, | ||
{ id: 18 }, | ||
{ id: 19 }, | ||
{ id: 20 }, | ||
]; | ||
|
||
export default function DynamicRowHeight() { | ||
return ( | ||
<div style={{ height: 300, width: 400 }}> | ||
<DataGrid rows={rows} columns={[{ field: 'id' }]} getRowHeight={() => 'auto'} /> | ||
</div> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Can we use
waitForSelector
here?In the description of
waitForTimeout
it saysThere 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.
Without a timeout, the assertion will happen before the potential scroll jump, and the test will pass without the fix applied.
I can't see
waitForSelector
as a replacement here, but I'm open for suggestions.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.
I didn't test it out, but what I had in mind is to wait for the last row to become attached or first row detached because of the virtualization and assert then
could that work?
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.
Both happen before the scroll jump, so the test will pass without the fix applied.
Perhaps it's possible to make an assertion that will wait for the first row to appear again after scroll with a timeout, and throw if it does appear. But it's not that different from the current solution.
WDYT?
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.
yes, that would also just spend time waiting for nothing to happen 🙂
in that case, I am fine leave it as is for now