material-react-table 2.11.0 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.11.0",
2
+ "version": "2.11.1",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -129,8 +129,8 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
129
129
  ) : (
130
130
  <Checkbox
131
131
  indeterminate={
132
- selectAll
133
- ? table.getIsSomeRowsSelected() && !allRowsSelected
132
+ !isChecked && selectAll
133
+ ? table.getIsSomeRowsSelected()
134
134
  : row?.getIsSomeSelected() && row.getCanSelectSubRows()
135
135
  }
136
136
  {...commonProps}
@@ -152,6 +152,7 @@ export const getMRT_RowSelectionHandler =
152
152
  options: {
153
153
  enableBatchRowSelection,
154
154
  enableRowPinning,
155
+ manualPagination,
155
156
  rowPinningDisplayMode,
156
157
  },
157
158
  refs: { lastSelectedRowId: lastSelectedRowId },
@@ -160,12 +161,14 @@ export const getMRT_RowSelectionHandler =
160
161
  pagination: { pageIndex, pageSize },
161
162
  } = getState();
162
163
 
163
- const isChecked = getIsRowSelected({ row, table });
164
+ const paginationOffset = manualPagination ? 0 : pageSize * pageIndex;
165
+
166
+ const isCurrentRowChecked = getIsRowSelected({ row, table });
164
167
 
165
168
  const isStickySelection =
166
169
  enableRowPinning && rowPinningDisplayMode?.includes('select');
167
170
 
168
- // toggle selected of this row
171
+ // toggle selection of this row
169
172
  row.getToggleSelectedHandler()(event);
170
173
 
171
174
  // if shift key is pressed, select all rows between last selected and this one
@@ -175,20 +178,34 @@ export const getMRT_RowSelectionHandler =
175
178
  lastSelectedRowId.current !== null
176
179
  ) {
177
180
  const rows = getMRT_Rows(table, undefined, true);
181
+
178
182
  const lastIndex = rows.findIndex(
179
183
  (r) => r.id === lastSelectedRowId.current,
180
184
  );
185
+
181
186
  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;
183
193
  const [start, end] =
184
194
  lastIndex < currentIndex
185
195
  ? [lastIndex, currentIndex]
186
196
  : [currentIndex, lastIndex];
187
- for (let i = start; i <= end; i++) {
188
- rows[i].toggleSelected(!isChecked);
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) {
201
+ for (let i = start; i <= end; i++) {
202
+ rows[i].toggleSelected(!isCurrentRowChecked);
203
+ }
189
204
  }
190
205
  }
191
206
  }
207
+
208
+ // record the last selected row id
192
209
  lastSelectedRowId.current = row.id;
193
210
 
194
211
  // if all sub rows were selected, unselect them
@@ -198,7 +215,7 @@ export const getMRT_RowSelectionHandler =
198
215
 
199
216
  if (isStickySelection) {
200
217
  row.pin(
201
- !row.getIsPinned() && isChecked
218
+ !row.getIsPinned() && isCurrentRowChecked
202
219
  ? rowPinningDisplayMode?.includes('bottom')
203
220
  ? 'bottom'
204
221
  : 'top'