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] Improve custom overlay slots positioning #3832

Merged
merged 20 commits into from
Feb 25, 2022

Conversation

cherniavskii
Copy link
Member

@cherniavskii cherniavskii commented Feb 3, 2022

Closes #3795
Fixes #4026

Preview: https://codesandbox.io/s/fullfeatureddemo-material-demo-forked-efmqf

Our layout requires overlays to have position absolute. Otherwise things like horizontal scrolling won't work (overlay might push render zone down below the grid footer).
At the same time, we allow to override overlays using slots.
So in order to make custom overlays work as good as default ones, we have to make sure custom slots are positioned in the way as default ones.
I've solved it by wrapping overlays with a component that has all position-related styles applied, so that they stay there when using custom overlays.

UPDATE: I just noticed, that in our demos we use GridOverlay component.
https://mui.com/components/data-grid/components/#loading-overlay
I think this PR makes it unnecessary. Also, it's not obvious GridOverlay is required - as seen in #3795
I'll update the demos.

Our layout requires overlays to have position absolute. otherwise e.g. horizontal scrolling won't work.
At the same time we allow to override overlays using slots.
So in order to make custom overlays work as good as default ones, we have to make sure custom slots are positioned the way default ones are.
This is solved by wrapping overlays with a component that has all position-related styles applied, so that they stay there when using custom overlays
@cherniavskii cherniavskii added component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request feature: Rendering layout Related to the data grid Rendering engine labels Feb 3, 2022
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';

export function GridOverlaysRoot(props: React.PropsWithChildren<{}>) {
Copy link
Member Author

Choose a reason for hiding this comment

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

It's basically extracted from GridOverlay.tsx

@mui-bot
Copy link

mui-bot commented Feb 3, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 243.3 460.2 360.9 344.76 87.536
Sort 100k rows ms 401.6 918.2 611 621.48 177.935
Select 100k rows ms 162 320.4 217.1 237.44 66.87
Deselect 100k rows ms 135.1 314.7 162.8 187.54 64.574

Generated by 🚫 dangerJS against 0c8d1cd

@@ -24,7 +14,7 @@ export default function CustomLoadingOverlayGrid() {
<div style={{ height: 400, width: '100%' }}>
<DataGrid
components={{
LoadingOverlay: CustomLoadingOverlay,
LoadingOverlay: LinearProgress,
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 love this change!

@siriwatknp

This comment was marked as resolved.

@github-actions

This comment was marked as resolved.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 8, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 11, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 17, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@m4theushw m4theushw self-requested a review February 18, 2022 14:44
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 18, 2022
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.

It was a bit complicate to understand how these overlay components work together. That's a signal that we should simplify the tree. What do you think about removing GridOverlay from the default overlays (e.g. no result overlay) and integrate the styles into GridOverlays? GridOverlay would still be exported but it wouldn't have styles, only kept for backwards compatibility.

top: headerHeight,
left: 0,
right: 0,
bottom: 0,
Copy link
Member

Choose a reason for hiding this comment

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

bottom and right are not necessary if we also define the height and width.

Copy link
Member Author

Choose a reason for hiding this comment

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

turns out bottom: 0 is needed here when height: auto, otherwise overlay won't take the whole height

@@ -72,7 +73,9 @@ function GridBody(props: GridBodyProps) {

return (
<GridMainContainer>
<GridOverlays />
<GridOverlaysRoot>
<GridOverlays />
Copy link
Member

Choose a reason for hiding this comment

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

Could GridOverlaysRoot be the root element of GridOverlays? This approach kinda breaks the internal convention for styled components:

<GridOverlays>
  <GridOverlaysRoot>
    {currentOverlay}
  </GridOverlaysRoot>
</GridOverlays>

For the error overlay we can make an exception and export GridOverlaysRoot.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree!

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 kept GridOverlayWrapper in separate file though to avoid exporting it in the package

Comment on lines 45 to 46
bottom: 0,
left: 0,
Copy link
Member

Choose a reason for hiding this comment

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

Not needed.

Suggested change
bottom: 0,
left: 0,

Copy link
Member Author

Choose a reason for hiding this comment

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

bottom is needed when height is auto, because otherwise overlay won't take the full height and some tests will fail

Copy link
Member

Choose a reason for hiding this comment

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

True, I forgot #3832 (comment). Then, maybe keep bottom=0 only when height=auto, otherwise it's undefined. That way we don't have two properties competing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, done

height,
width: viewportInnerSize?.width ?? 0,
position: 'absolute',
top: headerHeight,
Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at #4026, I think we should set top: 0 and full height (including footer) for ErrorOverlay, since neither grid column header nor footer are rendered.
At this point, I don't think we need GridOverlayWrapper for ErrorOverlay at all, since scrolling is not an issue if there's an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

And since GridOverlayWrapper is used only in GridOverlays, I've moved it to GridOverlays

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.

Much better. 👍

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 new feature New feature or request
Projects
None yet
4 participants