-
-
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
Changes from 9 commits
1c366e1
dfb8600
bbc6459
e45a68e
ffb967d
5042267
6bac367
f13a620
09d049a
e8d5dc3
6eebb7d
51b9336
c6c46ec
16c3940
8b6946a
3c31d73
7aeb191
c2c046e
4d3ea29
0c8d1cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as React from 'react'; | ||
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/material/utils'; | ||
import { useGridSelector } from '../../hooks/utils/useGridSelector'; | ||
import { gridDensityHeaderHeightSelector } from '../../hooks/features/density/densitySelector'; | ||
import { GridEvents } from '../../models/events'; | ||
import { useGridApiContext } from '../../hooks/utils/useGridApiContext'; | ||
import { useGridRootProps } from '../../hooks/utils/useGridRootProps'; | ||
|
||
export function GridOverlaysRoot(props: React.PropsWithChildren<{}>) { | ||
const apiRef = useGridApiContext(); | ||
const rootProps = useGridRootProps(); | ||
const headerHeight = useGridSelector(apiRef, gridDensityHeaderHeightSelector); | ||
|
||
const [viewportInnerSize, setViewportInnerSize] = React.useState( | ||
() => apiRef.current.getRootDimensions()?.viewportInnerSize ?? null, | ||
); | ||
|
||
const handleViewportSizeChange = React.useCallback(() => { | ||
setViewportInnerSize(apiRef.current.getRootDimensions()?.viewportInnerSize ?? null); | ||
}, [apiRef]); | ||
|
||
useEnhancedEffect(() => { | ||
return apiRef.current.subscribeEvent( | ||
GridEvents.viewportInnerSizeChange, | ||
handleViewportSizeChange, | ||
); | ||
}, [apiRef, handleViewportSizeChange]); | ||
|
||
let height: React.CSSProperties['height'] = viewportInnerSize?.height ?? 0; | ||
if (rootProps.autoHeight && height === 0) { | ||
height = 'auto'; | ||
} | ||
|
||
if (!viewportInnerSize) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
height, | ||
width: viewportInnerSize?.width ?? 0, | ||
position: 'absolute', | ||
top: headerHeight, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. turns out |
||
}} | ||
{...props} | ||
/> | ||
); | ||
} |
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 ofGridOverlays
? This approach kinda breaks the internal convention for styled components: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