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 GridOverlays bypassing pointer events #5674

Merged

Conversation

philjones88
Copy link
Contributor

Fixes #5590

@mui-bot
Copy link

mui-bot commented Aug 1, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 255.1 671.9 401.1 407.02 153.508
Sort 100k rows ms 506.7 1,006.1 859.8 832.94 171.505
Select 100k rows ms 220.2 270.6 236.9 240 16.651
Deselect 100k rows ms 145.5 486 211.8 258.14 122.371

Generated by 🚫 dangerJS against 3e8530c

@cherniavskii
Copy link
Member

For the context: pointer-events: none was added to avoid this regression #4405 after we changed zIndex of overlay container in #5558

@philjones88
Copy link
Contributor Author

philjones88 commented Aug 2, 2022

@cherniavskii I'm not sure what to suggest then, the change to add pointerEvents caused other regressions, this one being one for us.

@cherniavskii
Copy link
Member

What we can do to solve both issues is to:

This diff should do the job:

diff --git a/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx b/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx
index 8e7e4ea35..55ef3921f 100644
--- a/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx
+++ b/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx
@@ -1,14 +1,23 @@
 import * as React from 'react';
 import PropTypes from 'prop-types';
 import CircularProgress from '@mui/material/CircularProgress';
+import { styled } from '@mui/material/styles';
 import { GridOverlay, GridOverlayProps } from './containers/GridOverlay';
 
+const GridLoadingOverlayRoot = styled(GridOverlay)({
+  position: 'absolute',
+  top: 0,
+  zIndex: 4, // should be above pinned columns, pinned rows and detail panel
+  width: '100%',
+  pointerEvents: 'none',
+});
+
 const GridLoadingOverlay = React.forwardRef<HTMLDivElement, GridOverlayProps>(
   function GridLoadingOverlay(props, ref) {
     return (
-      <GridOverlay ref={ref} {...props}>
+      <GridLoadingOverlayRoot ref={ref} {...props}>
         <CircularProgress />
-      </GridOverlay>
+      </GridLoadingOverlayRoot>
     );
   },
 );
diff --git a/packages/grid/x-data-grid/src/components/base/GridOverlays.tsx b/packages/grid/x-data-grid/src/components/base/GridOverlays.tsx
index c4f1fec86..ce3a618e5 100644
--- a/packages/grid/x-data-grid/src/components/base/GridOverlays.tsx
+++ b/packages/grid/x-data-grid/src/components/base/GridOverlays.tsx
@@ -44,8 +44,6 @@ function GridOverlayWrapper(props: React.PropsWithChildren<{}>) {
         position: 'absolute',
         top: headerHeight,
         bottom: height === 'auto' ? 0 : undefined,
-        zIndex: 4, // should be above pinned columns, pinned rows and detail panel
-        pointerEvents: 'none',
       }}
       {...props}
     />

@cherniavskii cherniavskii changed the title Remove DataGrid GridOverlays pointerEvents style [DataGrid] Fix GridOverlays bypassing pointer events Aug 3, 2022
@@ -44,8 +44,6 @@ function GridOverlayWrapper(props: React.PropsWithChildren<{}>) {
position: 'absolute',
top: headerHeight,
bottom: height === 'auto' ? 0 : undefined,
zIndex: 4, // should be above pinned columns, pinned rows and detail panel
Copy link
Member

Choose a reason for hiding this comment

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

@cherniavskii shouldn't we keep zIndex: 4 here? It was added in #4863. Without it, other overlays, e.g. no filter results, don't take the full height.

I added a background on purpose to one overlay. Here it's how it looks like:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add it back, I thought moving it in the git patch proposed would be ok but the naming suggests that zIndex only applies to loading overlays...

How can we test this locally? Is thee a way to produce a custom NPM package? do a file:/ reference in my project's package.json...

Copy link
Member

Choose a reason for hiding this comment

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

How can we test this locally?

@philjones88 Please refer to the contribution guide for options on how to test an unreleased package.

Copy link
Member

Choose a reason for hiding this comment

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

@m4theushw nice catch!
I think we should not keep zIndex on the overlay wrapper, because there's no way to customize it.

Instead, we can move those styles to GridOverlay instead:

diff --git a/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx b/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx
index 55ef3921f..8e7e4ea35 100644
--- a/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx
+++ b/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx
@@ -1,23 +1,14 @@
 import * as React from 'react';
 import PropTypes from 'prop-types';
 import CircularProgress from '@mui/material/CircularProgress';
-import { styled } from '@mui/material/styles';
 import { GridOverlay, GridOverlayProps } from './containers/GridOverlay';
 
-const GridLoadingOverlayRoot = styled(GridOverlay)({
-  position: 'absolute',
-  top: 0,
-  zIndex: 4, // should be above pinned columns, pinned rows and detail panel
-  width: '100%',
-  pointerEvents: 'none',
-});
-
 const GridLoadingOverlay = React.forwardRef<HTMLDivElement, GridOverlayProps>(
   function GridLoadingOverlay(props, ref) {
     return (
-      <GridLoadingOverlayRoot ref={ref} {...props}>
+      <GridOverlay ref={ref} {...props}>
         <CircularProgress />
-      </GridLoadingOverlayRoot>
+      </GridOverlay>
     );
   },
 );
diff --git a/packages/grid/x-data-grid/src/components/containers/GridOverlay.tsx b/packages/grid/x-data-grid/src/components/containers/GridOverlay.tsx
index 789704435..77146b237 100644
--- a/packages/grid/x-data-grid/src/components/containers/GridOverlay.tsx
+++ b/packages/grid/x-data-grid/src/components/containers/GridOverlay.tsx
@@ -29,8 +29,13 @@ const GridOverlayRoot = styled('div', {
   slot: 'Overlay',
   overridesResolver: (props, styles) => styles.overlay,
 })(({ theme }) => ({
-  display: 'flex',
+  position: 'absolute',
+  top: 0,
+  zIndex: 4, // should be above pinned columns, pinned rows and detail panel
+  width: '100%',
   height: '100%',
+  pointerEvents: 'none',
+  display: 'flex',
   alignSelf: 'center',
   alignItems: 'center',
   justifyContent: 'center',

This would make default overlays taking full height while allowing to scroll horizontally (for example to access column used for filtering that is not in the viewport).
But most importantly, it would allow to implement custom overlays with interactive elements while avoiding pointerEvents: none (so it won't cause another issue like #5590).

Copy link
Member

@cherniavskii cherniavskii Aug 9, 2022

Choose a reason for hiding this comment

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

I've tried to push the proposed changes to this branch to make sure there's no visual regressions, but turned out I don't have the permission to push to https://github.com/VQComms/mui-x/tree/remove-grid-overlays-pointer-events-style

@philjones88 could you push the changes so we trigger the CI? Merging latest master to this branch would be good as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've applied the git diff above, updated my fork and rebased this branch onto master latest.

Copy link
Member

Choose a reason for hiding this comment

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

@philjones88
Thanks! Can you rebase again to restart the CI? The failure in Argos CI looks like a false negative

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cherniavskii I pushed an empty commit to trigger the CI. The branch was already up to date with master. Seems to have all passed!

@m4theushw m4theushw added 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 labels Aug 4, 2022
@philjones88 philjones88 force-pushed the remove-grid-overlays-pointer-events-style branch from 1cdf936 to 15346e2 Compare August 10, 2022 07:34
@cherniavskii cherniavskii added the regression A bug, but worse label Aug 10, 2022
@@ -44,8 +44,6 @@ function GridOverlayWrapper(props: React.PropsWithChildren<{}>) {
position: 'absolute',
Copy link
Member

@m4theushw m4theushw Aug 11, 2022

Choose a reason for hiding this comment

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

We removed pointerEvents: none but this was not sufficient to fix #5725. Since we didn't add zIndex #5674 (comment), the overlay stays behind the virtual scroller because it has position: relative, while the overlay has position: absoulte. We need to put the overlay on top of everything to fix #5725 too

Suggested change
position: 'absolute',
position: 'relative',

In https://codesandbox.io/s/mui-x-norowsoverlay-bug-forked-g6npfv?file=/src/App.tsx I still can't click the button.

Copy link
Member

Choose a reason for hiding this comment

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

This PR only fixes the regression described in #5590
#5725 is a bit different, since it was reproducible in v5.13.0 as well (before #5590 regression introduced in 5.14.0) - see https://codesandbox.io/s/mui-x-norowsoverlay-bug-forked-tzjfhj?file=/src/App.tsx

the overlay stays behind the virtual scroller because it has position: relative, while the overlay has position: absoulte

We tried to fix it with #5558, but this introduced the regression above.
If we add zIndex to GridOverlays - then https://github.com/mui/mui-x/blob/master/test/e2e/index.test.ts#L330 would fail.
This is the reason I've added pointerEvents: 'none', so that scroll gets bypassed to virtualScroller.

So it's kind of a vicious circle with the regressions here :D

For the #5725, after we merge this PR users can do this for custom overlays:

const NoRowsOverlay = () => {
	return <div style={{ position: 'relative', zIndex: 1 }}></div>
}

That's the best trade-off I see right now, but I'm open to other solutions

Copy link
Member

Choose a reason for hiding this comment

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

One solution that would keep https://github.com/mui/mui-x/blob/master/test/e2e/index.test.ts#L330 passing is to render the overlays inside the virtualization component.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it will be possible to do without breaking changes - I'll take a look

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. It's what we can do given the constraints we have. In v6 we can rearrange the overlay to render correctly without additional styling.

@cherniavskii cherniavskii merged commit 2b10cdd into mui:master Aug 12, 2022
@cherniavskii
Copy link
Member

Thanks @philjones88

alexfauquette pushed a commit to alexfauquette/mui-x that referenced this pull request Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5.14.0 overlay change adds pointerEvents: none which breaks buttons inside no rows overlay
5 participants