Skip to content

Commit 830cd10

Browse files
authored
[DataGrid] Fix tree data unable to deselect row for exclude model (#19846)
1 parent 148fc22 commit 830cd10

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

packages/x-data-grid-pro/src/tests/rowSelection.DataGridPro.test.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as React from 'react';
22
import { spy } from 'sinon';
33
import { RefObject } from '@mui/x-internals/types';
4-
import { getCell, getColumnValues, getRows, includeRowSelection } from 'test/utils/helperFn';
4+
import {
5+
getCell,
6+
getColumnValues,
7+
getRows,
8+
includeRowSelection,
9+
excludeRowSelection,
10+
} from 'test/utils/helperFn';
511
import { createRenderer, screen, act, fireEvent } from '@mui/internal-test-utils';
612
import {
713
GridApi,
@@ -1283,6 +1289,25 @@ describe('<DataGridPro /> - Row selection', () => {
12831289
});
12841290
});
12851291

1292+
describe('apiRef: getPropagatedRowSelectionModel', () => {
1293+
it('`getPropagatedRowSelectionModel` should return exclude models unchanged', () => {
1294+
render(<TreeDataGrid rowSelectionPropagation={{ descendants: true, parents: true }} />);
1295+
1296+
// Exclude models are not affected by propagation
1297+
const excludeModel = excludeRowSelection([1]);
1298+
const propagatedModel = apiRef.current?.getPropagatedRowSelectionModel(excludeModel);
1299+
1300+
expect(propagatedModel).to.equal(excludeModel); // same object
1301+
1302+
// Include models are affected by propagation
1303+
const includeModel = includeRowSelection([1]);
1304+
const propagatedIncludeModel = apiRef.current?.getPropagatedRowSelectionModel(includeModel);
1305+
1306+
expect(propagatedIncludeModel?.type).to.equal('include');
1307+
expect(propagatedIncludeModel?.ids).to.have.keys([1, 2, 3, 4, 5, 6, 7]);
1308+
});
1309+
});
1310+
12861311
it('should select only filtered rows after filter is applied', async () => {
12871312
const { user } = render(<TestDataGridSelection checkboxSelection />);
12881313
const selectAll = screen.getByRole('checkbox', {

packages/x-data-grid/src/hooks/features/rowSelection/useGridRowSelection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ export const useGridRowSelection = (
435435
if (
436436
!isNestedData ||
437437
!applyAutoSelection ||
438+
inputSelectionModel.type === 'exclude' ||
438439
(inputSelectionModel.ids.size === 0 && inputSelectionModel.type === 'include')
439440
) {
440441
return inputSelectionModel;

test/utils/helperFn.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,7 @@ export function getSelectByName(name: string) {
199199
export const includeRowSelection = (ids: GridRowId[]) => {
200200
return { type: 'include', ids: new Set(ids) } as const;
201201
};
202+
203+
export const excludeRowSelection = (ids: GridRowId[]) => {
204+
return { type: 'exclude', ids: new Set(ids) } as const;
205+
};

0 commit comments

Comments
 (0)