diff --git a/packages/grid/x-data-grid/src/components/ErrorOverlay.tsx b/packages/grid/x-data-grid/src/components/ErrorOverlay.tsx index 04f12fbed5cf6..7745d3852412f 100644 --- a/packages/grid/x-data-grid/src/components/ErrorOverlay.tsx +++ b/packages/grid/x-data-grid/src/components/ErrorOverlay.tsx @@ -1,6 +1,8 @@ import * as React from 'react'; import { useGridApiContext } from '../hooks/utils/useGridApiContext'; import { GridOverlay, GridOverlayProps } from './containers/GridOverlay'; +import { useGridSelector } from '../hooks/utils/useGridSelector'; +import { gridDensityRowHeightSelector } from '../hooks/features/density/densitySelector'; export interface ErrorOverlayProps extends GridOverlayProps { message?: string; @@ -14,9 +16,10 @@ export const ErrorOverlay = React.forwardRef( const { message, hasError, errorInfo, ...other } = props; const apiRef = useGridApiContext(); const defaultLabel = apiRef.current.getLocaleText('errorOverlayDefaultLabel'); + const rowHeight = useGridSelector(apiRef, gridDensityRowHeightSelector); return ( - + {message || defaultLabel} ); diff --git a/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx b/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx index 4ef60a84302f3..8e7e4ea352347 100644 --- a/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx +++ b/packages/grid/x-data-grid/src/components/GridLoadingOverlay.tsx @@ -1,8 +1,9 @@ import * as React from 'react'; +import PropTypes from 'prop-types'; import CircularProgress from '@mui/material/CircularProgress'; import { GridOverlay, GridOverlayProps } from './containers/GridOverlay'; -export const GridLoadingOverlay = React.forwardRef( +const GridLoadingOverlay = React.forwardRef( function GridLoadingOverlay(props, ref) { return ( @@ -11,3 +12,17 @@ export const GridLoadingOverlay = React.forwardRef( +const GridNoRowsOverlay = React.forwardRef( function GridNoRowsOverlay(props, ref) { const apiRef = useGridApiContext(); const noRowsLabel = apiRef.current.getLocaleText('noRowsLabel'); @@ -14,3 +15,17 @@ export const GridNoRowsOverlay = React.forwardRef { - apiRef.current.publishEvent(GridEvents.resize, size); - }, - [apiRef], - ); - return ( ( - - {() => ( - - - - )} - + )} > 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 877f1238ce329..789704435357b 100644 --- a/packages/grid/x-data-grid/src/components/containers/GridOverlay.tsx +++ b/packages/grid/x-data-grid/src/components/containers/GridOverlay.tsx @@ -1,12 +1,16 @@ import * as React from 'react'; +import PropTypes from 'prop-types'; import clsx from 'clsx'; import { unstable_composeClasses as composeClasses } from '@mui/material'; -import { alpha, styled } from '@mui/material/styles'; +import { SxProps } from '@mui/system'; +import { Theme, alpha, styled } from '@mui/material/styles'; import { getDataGridUtilityClass } from '../../constants/gridClasses'; import { useGridRootProps } from '../../hooks/utils/useGridRootProps'; import { DataGridProcessedProps } from '../../models/props/DataGridProps'; -export type GridOverlayProps = React.HTMLAttributes; +export type GridOverlayProps = React.HTMLAttributes & { + sx?: SxProps; +}; type OwnerState = { classes: DataGridProcessedProps['classes'] }; @@ -33,7 +37,7 @@ const GridOverlayRoot = styled('div', { backgroundColor: alpha(theme.palette.background.default, theme.palette.action.disabledOpacity), })); -export const GridOverlay = React.forwardRef(function GridOverlay( +const GridOverlay = React.forwardRef(function GridOverlay( props: GridOverlayProps, ref, ) { @@ -44,3 +48,17 @@ export const GridOverlay = React.forwardRef(fu return ; }); + +GridOverlay.propTypes = { + // ----------------------------- Warning -------------------------------- + // | These PropTypes are generated from the TypeScript type definitions | + // | To update them edit the TypeScript types and run "yarn proptypes" | + // ---------------------------------------------------------------------- + sx: PropTypes.oneOfType([ + PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), + PropTypes.func, + PropTypes.object, + ]), +} as any; + +export { GridOverlay }; diff --git a/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx b/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx index 92f231db6a694..22fefc52d3faf 100644 --- a/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx +++ b/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx @@ -809,9 +809,29 @@ describe(' - Layout & Warnings', () => { , ); - expect(document.querySelectorAll('.MuiDataGrid-overlay')[0].clientHeight).to.equal( - rowHeight * 2, + expect( + (document.querySelector('.MuiDataGrid-overlay') as HTMLElement).clientHeight, + ).to.equal(rowHeight * 2); + }); + + it('should expand content height to one row height when there is an error', () => { + const error = { message: 'ERROR' }; + const rowHeight = 50; + + render( +
+ +
, ); + const errorOverlayElement = document.querySelector('.MuiDataGrid-overlay') as HTMLElement; + expect(errorOverlayElement.textContent).to.equal(error.message); + expect(errorOverlayElement.offsetHeight).to.equal(2 * rowHeight); }); }); @@ -984,7 +1004,9 @@ describe(' - Layout & Warnings', () => { , ); - expect(document.querySelectorAll('.MuiDataGrid-overlay')[0].textContent).to.equal(message); + expect((document.querySelector('.MuiDataGrid-overlay') as HTMLElement).textContent).to.equal( + message, + ); }); }); diff --git a/packages/storybook/src/stories/grid-error.stories.tsx b/packages/storybook/src/stories/grid-error.stories.tsx index 149b0ab0c77aa..70072807b9f4c 100644 --- a/packages/storybook/src/stories/grid-error.stories.tsx +++ b/packages/storybook/src/stories/grid-error.stories.tsx @@ -112,6 +112,17 @@ export const ThrowException = () => { ); }; +export const ErrorWithAutoHeight = () => { + const rows = React.useMemo(() => getRows(), []); + const cols = React.useMemo(() => getColumns(), []); + + return ( +
+ +
+ ); +}; + export const ShowErrorApi = () => { const api = useGridApiRef(); const rows = React.useMemo(() => getRows(), []);