Skip to content

Commit

Permalink
Fix rowModesModel controlled prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed May 8, 2024
1 parent 1af982d commit a26069a
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 a26069a

Please sign in to comment.