-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[DataGrid] Prevent column header scroll #4280
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
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
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.
AFAIK this
preventScrollis not viable because it doesn't work on Safari. What I would propose instead is to look into why the container is scrollable in the first place. We use translate 3d, so why is it possible forscrollLeftto not always be 0 in the first place?Uh oh!
There was an error while loading. Please reload this page.
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.
Even adding
overflow: hiddenI still can scroll a div. It's expected: https://stackoverflow.com/questions/33703204/is-scrolltop-and-scrollleft-for-overflow-hidden-elements-reliableIn the past, we even did a small hack by listening to
scrolland callingscrollLeft=0to prevent scrolling the container - which hadoverflow: hidden- when using a touchpad device.mui-x/packages/grid/_modules_/grid/hooks/features/virtualization/useGridVirtualRows.ts
Lines 487 to 492 in b81daef
That's why I call
scrollLeft=0down below ifpreventScrollis not supported.Uh oh!
There was an error while loading. Please reload this page.
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.
Right ok, great points, all my previous points have been answered.
I had a closer look: did you consider this option?
mui-x/packages/grid/x-data-grid/src/components/columnHeaders/GridColumnHeaderItem.tsx
Line 210 in 65cf41c
mui-x/packages/grid/x-data-grid/src/hooks/features/columnHeaders/useGridColumnHeaders.tsx
Lines 52 to 54 in 6643404
I'm asking because using
preventScrollhere might introduce the same problems as #4282 (vertical scrolling) but for horizontal scrolling.Actually, speaking of horizontal scrolling, I have found a bug when
rows={[]}https://codesandbox.io/s/datagridprodemo-material-demo-forked-8e4l8w:Now, maybe we don't need to care. Who would try to scroll/use the arrow key? There are no data loaded 😁
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.
The "no row" bug can be fixed. It's an early return to modify in scroll hook
https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/hooks/features/scroll/useGridScroll.ts#L56:L58
Is it necessary to prevent scroll? I thought adding the
hasFocusun theuseLayoutEffectdependencies was enough to prevent scroll on renderingThe only bug I can think of with the scroll on rendering is when the element is unmounted because it goes out of the virtualization engine and comes back. But that's a larger problem.
For example, I set focus on a cell, I can use keyboard navigation as long as the cell is in the virtualisation buffer. As soon as it exits the buffer, the focus moves to
<body>and the gird does not respond anymore to keyboard interactionshttps://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/hooks/features/scroll/useGridScroll.ts#L56:L58
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 removed
preventScrolland kept onlyscrollLeft=0. I didn't realize the side effect of using it.It's not sufficient. If I remove
scrollLeft=0and scroll very fast to left and right the bug appears at some point. This happens because the column header component may be mounted during scroll.Interesting, I won't fix it here. Feel free to submit a PR.
If what caused "no results" was applying a filter in a column that's outside the visible area, then the user may use the arrow keys to navigate to them. We had a issue about that when we blocked the scrollbar if
rows=[]: #3795 (comment)