Skip to content

Commit 1b6aae3

Browse files
sai6855romgrk
authored andcommitted
[DataGrid] Fix pagination when pagination={undefined} (mui#13349)
Co-authored-by: Rom Grk <romgrk.cc@gmail.com>
1 parent 2a300ff commit 1b6aae3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

packages/x-data-grid/src/DataGrid/useDataGridProps.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,26 @@ export const useDataGridProps = <R extends GridValidRowModel>(inProps: DataGridP
104104
[themedProps.slots],
105105
);
106106

107+
const injectDefaultProps = React.useMemo(() => {
108+
return (
109+
Object.keys(DATA_GRID_PROPS_DEFAULT_VALUES) as Array<
110+
keyof DataGridPropsWithDefaultValues<any>
111+
>
112+
).reduce((acc, key) => {
113+
// @ts-ignore
114+
acc[key] = themedProps[key] ?? DATA_GRID_PROPS_DEFAULT_VALUES[key];
115+
return acc;
116+
}, {} as DataGridPropsWithDefaultValues<any>);
117+
}, [themedProps]);
118+
107119
return React.useMemo<DataGridProcessedProps<R>>(
108120
() => ({
109-
...DATA_GRID_PROPS_DEFAULT_VALUES,
110121
...themedProps,
122+
...injectDefaultProps,
111123
localeText,
112124
slots,
113125
...DATA_GRID_FORCED_PROPS,
114126
}),
115-
[themedProps, localeText, slots],
127+
[themedProps, localeText, slots, injectDefaultProps],
116128
);
117129
};

packages/x-data-grid/src/tests/DataGrid.test.tsx

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { createRenderer } from '@mui/internal-test-utils';
33
import { expect } from 'chai';
4-
import { DataGrid } from '@mui/x-data-grid';
4+
import { DataGrid, DATA_GRID_PROPS_DEFAULT_VALUES } from '@mui/x-data-grid';
55

66
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
77

@@ -62,4 +62,34 @@ describe('<DataGrid />', () => {
6262
</div>,
6363
);
6464
});
65+
66+
it('should not cause unexpected behavior when props are explictly set to undefined', () => {
67+
const rows = [
68+
{ id: 'a', col1: 'Hello', col2: 'World' },
69+
{ id: 'constructor', col1: 'DataGridPro', col2: 'is Awesome' },
70+
{ id: 'hasOwnProperty', col1: 'MUI', col2: 'is Amazing' },
71+
];
72+
73+
const columns = [
74+
{ field: 'col1', headerName: 'Column 1', width: 150 },
75+
{ field: 'col2', headerName: 'Column 2', width: 150 },
76+
];
77+
expect(() => {
78+
render(
79+
<DataGrid
80+
{...(
81+
Object.keys(DATA_GRID_PROPS_DEFAULT_VALUES) as Array<
82+
keyof typeof DATA_GRID_PROPS_DEFAULT_VALUES
83+
>
84+
).reduce((acc, key) => {
85+
// @ts-ignore
86+
acc[key] = undefined;
87+
return acc;
88+
}, {})}
89+
rows={rows}
90+
columns={columns}
91+
/>,
92+
);
93+
}).not.toErrorDev();
94+
});
6595
});

0 commit comments

Comments
 (0)