Skip to content

Commit

Permalink
[DataGrid] Fix onRowSelectionModelChange not being called after row…
Browse files Browse the repository at this point in the history
… is removed (#14972)
  • Loading branch information
arminmeh authored Oct 15, 2024
1 parent c1e882c commit 05e83ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export const useGridRowSelection = (

let hasChanged = false;
currentSelection.forEach((id: GridRowId) => {
if (filteredRowsLookup[id] === false) {
if (filteredRowsLookup[id] !== true) {
if (props.keepNonExistentRowsSelected) {
return;
}
Expand Down
21 changes: 21 additions & 0 deletions packages/x-data-grid/src/tests/rowSelection.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,27 @@ describe('<DataGrid /> - Row selection', () => {
expect(getSelectedRowIds()).to.deep.equal([0]);
});

// Related to https://github.com/mui/mui-x/issues/14964
it('should call `onRowSelectionModelChange` when outdated selected rows are removed', () => {
const data = getBasicGridData(4, 2);
const onRowSelectionModelChangeSpy = spy();

const { setProps } = render(
<TestDataGridSelection
rowSelectionModel={[0, 1, 2]}
onRowSelectionModelChange={onRowSelectionModelChangeSpy}
checkboxSelection
{...data}
/>,
);

setProps({
rows: data.rows.slice(0, 1),
});

expect(onRowSelectionModelChangeSpy.called).to.equal(true);
});

it('should retain the outdated selected rows when the rows prop changes when keepNonExistentRowsSelected is true', () => {
const data = getBasicGridData(10, 2);
const onRowSelectionModelChange = spy();
Expand Down

0 comments on commit 05e83ee

Please sign in to comment.