-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
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
import { useGridApiContext } from '../../hooks/utils/useGridApiContext'; | ||
import { useGridRootProps } from '../../hooks/utils/useGridRootProps'; | ||
|
||
export function GridOverlaysRoot(props: React.PropsWithChildren<{}>) { |
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.
It's basically extracted from GridOverlay.tsx
These are the results for the performance tests:
|
@@ -24,7 +14,7 @@ export default function CustomLoadingOverlayGrid() { | |||
<div style={{ height: 400, width: '100%' }}> | |||
<DataGrid | |||
components={{ | |||
LoadingOverlay: CustomLoadingOverlay, | |||
LoadingOverlay: LinearProgress, |
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 love this change!
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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.
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, |
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.
bottom
and right
are not necessary if we also define the height and width.
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.
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 /> |
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 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
.
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.
Agree!
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've kept GridOverlayWrapper
in separate file though to avoid exporting it in the package
bottom: 0, | ||
left: 0, |
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.
Not needed.
bottom: 0, | |
left: 0, |
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.
bottom
is needed when height
is auto
, because otherwise overlay won't take the full height and some tests will fail
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.
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.
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.
Sure, done
packages/grid/x-data-grid/src/internals/components/base/GridOverlays.tsx
Show resolved
Hide resolved
height, | ||
width: viewportInnerSize?.width ?? 0, | ||
position: 'absolute', | ||
top: headerHeight, |
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.
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.
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.
cc @m4theushw
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.
And since GridOverlayWrapper
is used only in GridOverlays
, I've moved it to GridOverlays
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.
Much better. 👍
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 #3795I'll update the demos.