-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[DataGrid] Scroll restoration #15623
base: master
Are you sure you want to change the base?
Conversation
Deploy preview: https://deploy-preview-15623--material-ui-x.netlify.app/ Updated pages: |
packages/x-data-grid/src/components/virtualization/GridVirtualScrollbar.tsx
Outdated
Show resolved
Hide resolved
useEnhancedEffect(() => { | ||
apiRef.current.publishEvent('virtualScrollerContentSizeChange'); | ||
}, [apiRef, props.style]); | ||
|
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.
Isn't there a way to keep this logic in the feature hook? Imho, it feels a bit cleaner to have it there, considering all the other similar logic is also there.
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 completely agree with you there, and just finishing a commit on that note. Wasn't completely obvious to me initially how I could do it in a clean way, as it needs to run before paint to avoid triggering reflows – so at useLayoutEffect of the ScrollerContent component.
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.
Fixed with a callbackRef. Also made it more complete for different use cases. E.g. when columns are not immediately available, and if columns and rows become available at different times.
ColumnVirtualizationGrid.tsx
in the docs turned out be a good test case.
if (left > 0) { | ||
scroller.scrollLeft = left; | ||
ignoreNextScrollEvent.current = true; | ||
} |
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.
Could you explain why we only deal with left
and not with top
here? Would it be relevant to leave a small comment to explain it?
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.
Added some notes now.
Fixes #15190
Pain to implement in userland currently, avoids recalculating render contexts and trashing wrong initial content, that's impossible to avoid in userland.
Added a section under scrolling in docs to demonstrate.