-
-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1c366e1
extract overlay position related styles to separate component
cherniavskii dfb8600
get rid of GridOverlay in demos
cherniavskii bbc6459
fix failing test
cherniavskii e45a68e
fix error overlay position
cherniavskii ffb967d
fix failing test
cherniavskii 5042267
Merge branch 'master' into custom-overlays
cherniavskii 6bac367
Merge branch 'master' into custom-overlays
cherniavskii f13a620
Merge branch 'master' into custom-overlays
cherniavskii 09d049a
fix failed merge
cherniavskii e8d5dc3
remove needless styles
cherniavskii 6eebb7d
move GridOverlaysRoot to GridOverlays
cherniavskii 51b9336
rename GridOverlaysRoot
cherniavskii c6c46ec
fix failing test
cherniavskii 16c3940
move GridOverlayWrapper to separate file
cherniavskii 8b6946a
Merge branch 'master' into custom-overlays
cherniavskii 3c31d73
remove unnecessary style
cherniavskii 7aeb191
return null if there's no overlay
cherniavskii c2c046e
apply `bottom` value conditionally
cherniavskii 4d3ea29
make ErrorOverlay to take full width and height of the grid
cherniavskii 0c8d1cd
move GridOverlayWrapper to GridOverlays
cherniavskii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/grid/_modules_/grid/components/base/GridOverlaysRoot.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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