Skip to content
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] Fix horizontal scroll not working on empty grid #3821

Merged
merged 10 commits into from
Feb 14, 2022

Conversation

cherniavskii
Copy link
Member

@cherniavskii cherniavskii commented Feb 2, 2022

@cherniavskii cherniavskii added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Other labels Feb 2, 2022
@mui-bot
Copy link

mui-bot commented Feb 2, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 232.3 395.7 338.3 327.36 52.939
Sort 100k rows ms 368 909.2 789.5 696.84 215.93
Select 100k rows ms 181 311.3 265.9 257.22 50.945
Deselect 100k rows ms 146 278 208 201.28 46.658

Generated by 🚫 dangerJS against 22fc2d9

Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add tests for this part? We should cover more the virtualization.

@m4theushw m4theushw added feature: Rendering layout Related to the data grid Rendering engine and removed feature: Other labels Feb 4, 2022
@siriwatknp

This comment was marked as resolved.

@cherniavskii
Copy link
Member Author

cherniavskii commented Feb 10, 2022

Could you add tests for this part? We should cover more the virtualization.

I've added a test to check virtualScrollContent height.
I wasn't able to test horizontal scroll itself, because firing scroll events on virtual scroller would pass regardless the content height.
I'll try to cover horizontal scroll in e2e test.

setShouldExtendContent(
apiRef.current.windowRef.current.scrollHeight <=
apiRef.current.windowRef.current.clientHeight,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This callback will be called when the virtualScrollerContentSizeChange event is fired and the event is fired when contentSize changes, which happens inside the hook. We can remove this state update and migrate the minHeight to contentSize, avoiding one rerender.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!
I noticed that the event is emitted in the same hook, but didn't think of removing unnecessary state

@@ -320,12 +320,19 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
const needsHorizontalScrollbar = containerWidth && columnsMeta.totalWidth > containerWidth;

const contentSize = React.useMemo(() => {
let shouldExtendContent = false;
const windowRef = apiRef.current.windowRef;
if (windowRef?.current && windowRef.current.scrollHeight <= windowRef.current.clientHeight) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that windowRef is a wrapper for the .MuiDataGrid-virtualScrollerContent element so windowRef.current.scrollHeight is equal to size.height.

Suggested change
if (windowRef?.current && windowRef.current.scrollHeight <= windowRef.current.clientHeight) {
if (windowRef?.current && size.height <= windowRef.current.clientHeight) {

Use ref instead of windowRef. They are the same thing:

<VirtualScrollerComponent
ref={windowRef}

const { getRootProps, getContentProps, getRenderZoneProps, getRows } = useGridVirtualScroller({
ref,

getRootProps: ({ style = {}, ...other } = {}) => ({
ref: handleRef,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used rootRef instead of ref, since ref has type React.Ref<HTMLDivElement>, which allows it to be a function and I wasn't able to just get .current from it.

Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

test/e2e/fixtures/DataGrid/EmptyGrid.tsx Outdated Show resolved Hide resolved
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Rendering layout Related to the data grid Rendering engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Horizontal Scrollbar disappears when NoResultsOverlay is used and no results in filter
4 participants