Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Fix deselection not working with isRowSelectable #15692

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Below are described the steps you need to make to migrate from v7 to v8.
- The default value of the `rowSelectionPropagation` prop has been changed to `{ parents: true, descendants: true }` which means that the selection will be propagated to the parents and descendants by default.
To revert to the previous behavior, pass `rowSelectionPropagation={{ parents: false, descendants: false }}`.
- The prop `indeterminateCheckboxAction` has been removed. Clicking on an indeterminate checkbox "selects" the unselected descendants.
- The "Select all" checkbox would now be checked when all the selectable rows are selected, ignoring rows that are not selectable because of the `isRowSelectable` prop.

### Changes to the public API

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ const GridHeaderCheckbox = React.forwardRef<HTMLButtonElement, GridColumnHeaderP
// Convert to an object to make O(1) checking if a row exists or not
// TODO create selector that returns visibleRowIds/paginatedVisibleRowIds as an object
return rowIds.reduce<Record<GridRowId, true>>((acc, id) => {
if (!apiRef.current.isRowSelectable(id)) {
return acc;
}
acc[id] = true;
return acc;
}, {});
}, [
apiRef,
rootProps.pagination,
rootProps.checkboxSelectionVisibleOnly,
paginatedVisibleRowIds,
Expand Down
11 changes: 11 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 @@ -671,6 +671,17 @@ describe('<DataGrid /> - Row selection', () => {
);
}).not.toErrorDev();
});

it('should set the "Select all" checkbox to selected state on clicking even when some rows are not selectable', () => {
render(
<TestDataGridSelection
checkboxSelection
isRowSelectable={({ id }) => Number(id) % 2 === 0}
/>,
);
fireEvent.click(getColumnHeaderCell(0).querySelector('input')!);
expect(getColumnHeaderCell(0).querySelector('input')).to.have.property('checked', true);
});
});

describe('prop: rows', () => {
Expand Down
Loading