Skip to content

Commit 401d1ed

Browse files
committed
release v2.11.1 - batch select bug fix
1 parent 87b2cc8 commit 401d1ed

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

apps/material-react-table-docs/pages/changelog.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import Head from 'next/head';
1212

1313
### Version 2
1414

15+
#### Version 2.11.1 - 2024-02-05
16+
17+
- Fixed bug where new batch row selection feature did not account for `manualPagination`
18+
- Fixed bug where parent selected checkbox should not be indeterminate when the row itself is selected
19+
1520
#### Version 2.11.0 - 2024-02-05
1621

1722
- Added new `enableBatchRowSelection` table option that is enabled by default that allows users to select multiple rows at once by holding down the shift key and clicking on a row
@@ -235,8 +240,8 @@ See the old [V1 Changelog](https://v1.material-react-table.com/changelog)
235240

236241
## Roadmap
237242

238-
### Version 2 Roadmap (2023)
243+
### Version 2 Roadmap (2024)
239244

240-
Material React Table V2 was a big release months in the making that mostly focussed on the new `useMaterialReactTable` hook and paradigms. New features will be added and many bug fixes around virtualization compatibility with advanced features will be prioritized first.
245+
Most large
241246

242247
A lighter weight `useMaterialReactTableLight` hook is also being considered in the near future that will be a bit more bare-bones and tree-shakable. All features will be opt-in and will not be enabled by default.

packages/material-react-table/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.11.0",
2+
"version": "2.11.1",
33
"license": "MIT",
44
"name": "material-react-table",
55
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",

packages/material-react-table/src/components/inputs/MRT_SelectCheckbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
129129
) : (
130130
<Checkbox
131131
indeterminate={
132-
selectAll
133-
? table.getIsSomeRowsSelected() && !allRowsSelected
132+
!isChecked && selectAll
133+
? table.getIsSomeRowsSelected()
134134
: row?.getIsSomeSelected() && row.getCanSelectSubRows()
135135
}
136136
{...commonProps}

packages/material-react-table/src/utils/row.utils.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export const getMRT_RowSelectionHandler =
152152
options: {
153153
enableBatchRowSelection,
154154
enableRowPinning,
155+
manualPagination,
155156
rowPinningDisplayMode,
156157
},
157158
refs: { lastSelectedRowId: lastSelectedRowId },
@@ -160,12 +161,14 @@ export const getMRT_RowSelectionHandler =
160161
pagination: { pageIndex, pageSize },
161162
} = getState();
162163

163-
const isChecked = getIsRowSelected({ row, table });
164+
const paginationOffset = manualPagination ? 0 : pageSize * pageIndex;
165+
166+
const isCurrentRowChecked = getIsRowSelected({ row, table });
164167

165168
const isStickySelection =
166169
enableRowPinning && rowPinningDisplayMode?.includes('select');
167170

168-
// toggle selected of this row
171+
// toggle selection of this row
169172
row.getToggleSelectedHandler()(event);
170173

171174
// if shift key is pressed, select all rows between last selected and this one
@@ -175,24 +178,34 @@ export const getMRT_RowSelectionHandler =
175178
lastSelectedRowId.current !== null
176179
) {
177180
const rows = getMRT_Rows(table, undefined, true);
181+
178182
const lastIndex = rows.findIndex(
179183
(r) => r.id === lastSelectedRowId.current,
180184
);
185+
181186
if (lastIndex !== -1) {
182-
const currentIndex = staticRowIndex + pageSize * pageIndex;
187+
const isLastIndexChecked = getIsRowSelected({
188+
row: rows?.[lastIndex],
189+
table,
190+
});
191+
192+
const currentIndex = staticRowIndex + paginationOffset;
183193
const [start, end] =
184194
lastIndex < currentIndex
185195
? [lastIndex, currentIndex]
186196
: [currentIndex, lastIndex];
187-
if (
188-
rows[currentIndex].getIsSelected() !== rows[lastIndex].getIsSelected()
189-
) {
197+
198+
// toggle selection of all rows between last selected and this one
199+
// but only if the last selected row is not the same as the current one
200+
if (isCurrentRowChecked !== isLastIndexChecked) {
190201
for (let i = start; i <= end; i++) {
191-
rows[i].toggleSelected(!isChecked);
202+
rows[i].toggleSelected(!isCurrentRowChecked);
192203
}
193204
}
194205
}
195206
}
207+
208+
// record the last selected row id
196209
lastSelectedRowId.current = row.id;
197210

198211
// if all sub rows were selected, unselect them
@@ -202,7 +215,7 @@ export const getMRT_RowSelectionHandler =
202215

203216
if (isStickySelection) {
204217
row.pin(
205-
!row.getIsPinned() && isChecked
218+
!row.getIsPinned() && isCurrentRowChecked
206219
? rowPinningDisplayMode?.includes('bottom')
207220
? 'bottom'
208221
: 'top'

0 commit comments

Comments
 (0)