Skip to content

Commit

Permalink
[DataGrid] Fix rowModesModel controlled prop (mui#13056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored and thomasmoon committed Sep 6, 2024
1 parent ae4a01a commit 97a9fcd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,15 @@ describe('<DataGridPro /> - Row editing', () => {
expect(getCell(0, 1)).not.to.have.class('MuiDataGrid-cell--editing');
});

it('should stop edit mode when rowModesModel empty', () => {
const { setProps } = render(
<TestCase rowModesModel={{ 0: { mode: GridRowModes.Edit } }} />,
);
expect(getCell(0, 1)).to.have.class('MuiDataGrid-cell--editing');
setProps({ rowModesModel: {} });
expect(getCell(0, 1)).not.to.have.class('MuiDataGrid-cell--editing');
});

it('should ignode modifications if ignoreModifications=true', async () => {
const { setProps } = render(
<TestCase rowModesModel={{ 0: { mode: GridRowModes.Edit } }} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,9 @@ export const useGridRowEditing = (
const copyOfPrevRowModesModel = prevRowModesModel.current;
prevRowModesModel.current = deepClone(rowModesModel); // Do a deep-clone because the attributes might be changed later

Object.entries(rowModesModel).forEach(([id, params]) => {
const ids = new Set([...Object.keys(rowModesModel), ...Object.keys(copyOfPrevRowModesModel)]);
Array.from(ids).forEach((id) => {
const params = rowModesModel[id] ?? { mode: GridRowModes.View };
const prevMode = copyOfPrevRowModesModel[id]?.mode || GridRowModes.View;
const originalId = idToIdLookup[id] ?? id;
if (params.mode === GridRowModes.Edit && prevMode === GridRowModes.View) {
Expand Down

0 comments on commit 97a9fcd

Please sign in to comment.