material-react-table 2.11.0 → 2.11.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.esm.js CHANGED
@@ -402,11 +402,12 @@ const getIsRowSelected = ({ row, table, }) => {
402
402
  };
403
403
  const getMRT_RowSelectionHandler = () => ({ event, row, staticRowIndex = 0, table, }) => {
404
404
  var _a;
405
- const { getState, options: { enableBatchRowSelection, enableRowPinning, rowPinningDisplayMode, }, refs: { lastSelectedRowId: lastSelectedRowId }, } = table;
405
+ const { getState, options: { enableBatchRowSelection, enableRowPinning, manualPagination, rowPinningDisplayMode, }, refs: { lastSelectedRowId: lastSelectedRowId }, } = table;
406
406
  const { pagination: { pageIndex, pageSize }, } = getState();
407
- const isChecked = getIsRowSelected({ row, table });
407
+ const paginationOffset = manualPagination ? 0 : pageSize * pageIndex;
408
+ const isCurrentRowChecked = getIsRowSelected({ row, table });
408
409
  const isStickySelection = enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'));
409
- // toggle selected of this row
410
+ // toggle selection of this row
410
411
  row.getToggleSelectedHandler()(event);
411
412
  // if shift key is pressed, select all rows between last selected and this one
412
413
  if (enableBatchRowSelection &&
@@ -415,22 +416,31 @@ const getMRT_RowSelectionHandler = () => ({ event, row, staticRowIndex = 0, tabl
415
416
  const rows = getMRT_Rows(table, undefined, true);
416
417
  const lastIndex = rows.findIndex((r) => r.id === lastSelectedRowId.current);
417
418
  if (lastIndex !== -1) {
418
- const currentIndex = staticRowIndex + pageSize * pageIndex;
419
+ const isLastIndexChecked = getIsRowSelected({
420
+ row: rows === null || rows === void 0 ? void 0 : rows[lastIndex],
421
+ table,
422
+ });
423
+ const currentIndex = staticRowIndex + paginationOffset;
419
424
  const [start, end] = lastIndex < currentIndex
420
425
  ? [lastIndex, currentIndex]
421
426
  : [currentIndex, lastIndex];
422
- for (let i = start; i <= end; i++) {
423
- rows[i].toggleSelected(!isChecked);
427
+ // toggle selection of all rows between last selected and this one
428
+ // but only if the last selected row is not the same as the current one
429
+ if (isCurrentRowChecked !== isLastIndexChecked) {
430
+ for (let i = start; i <= end; i++) {
431
+ rows[i].toggleSelected(!isCurrentRowChecked);
432
+ }
424
433
  }
425
434
  }
426
435
  }
436
+ // record the last selected row id
427
437
  lastSelectedRowId.current = row.id;
428
438
  // if all sub rows were selected, unselect them
429
439
  if (row.getCanSelectSubRows() && row.getIsAllSubRowsSelected()) {
430
440
  (_a = row.subRows) === null || _a === void 0 ? void 0 : _a.forEach((r) => r.toggleSelected(false));
431
441
  }
432
442
  if (isStickySelection) {
433
- row.pin(!row.getIsPinned() && isChecked
443
+ row.pin(!row.getIsPinned() && isCurrentRowChecked
434
444
  ? (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('bottom'))
435
445
  ? 'bottom'
436
446
  : 'top'
@@ -1027,8 +1037,8 @@ const MRT_SelectCheckbox = (_a) => {
1027
1037
  }, sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.5rem', m: density !== 'compact' ? '-0.4rem' : undefined, width: density === 'compact' ? '1.75rem' : '2.5rem', zIndex: 0 }, parseFromValuesOrFunc(checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx, theme))), title: undefined });
1028
1038
  return (jsx(Tooltip, Object.assign({}, getCommonTooltipProps(), { title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : (selectAll
1029
1039
  ? localization.toggleSelectAll
1030
- : localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsx(Radio, Object.assign({}, commonProps))) : (jsx(Checkbox, Object.assign({ indeterminate: selectAll
1031
- ? table.getIsSomeRowsSelected() && !allRowsSelected
1040
+ : localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsx(Radio, Object.assign({}, commonProps))) : (jsx(Checkbox, Object.assign({ indeterminate: !isChecked && selectAll
1041
+ ? table.getIsSomeRowsSelected()
1032
1042
  : (row === null || row === void 0 ? void 0 : row.getIsSomeSelected()) && row.getCanSelectSubRows() }, commonProps))) })));
1033
1043
  };
1034
1044