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/dist/index.esm.js +19 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/inputs/MRT_SelectCheckbox.tsx +2 -2
- package/src/utils/row.utils.ts +23 -6
package/dist/index.js
CHANGED
@@ -492,11 +492,12 @@ const getIsRowSelected = ({ row, table, }) => {
|
|
492
492
|
};
|
493
493
|
const getMRT_RowSelectionHandler = () => ({ event, row, staticRowIndex = 0, table, }) => {
|
494
494
|
var _a;
|
495
|
-
const { getState, options: { enableBatchRowSelection, enableRowPinning, rowPinningDisplayMode, }, refs: { lastSelectedRowId: lastSelectedRowId }, } = table;
|
495
|
+
const { getState, options: { enableBatchRowSelection, enableRowPinning, manualPagination, rowPinningDisplayMode, }, refs: { lastSelectedRowId: lastSelectedRowId }, } = table;
|
496
496
|
const { pagination: { pageIndex, pageSize }, } = getState();
|
497
|
-
const
|
497
|
+
const paginationOffset = manualPagination ? 0 : pageSize * pageIndex;
|
498
|
+
const isCurrentRowChecked = getIsRowSelected({ row, table });
|
498
499
|
const isStickySelection = enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'));
|
499
|
-
// toggle
|
500
|
+
// toggle selection of this row
|
500
501
|
row.getToggleSelectedHandler()(event);
|
501
502
|
// if shift key is pressed, select all rows between last selected and this one
|
502
503
|
if (enableBatchRowSelection &&
|
@@ -505,22 +506,31 @@ const getMRT_RowSelectionHandler = () => ({ event, row, staticRowIndex = 0, tabl
|
|
505
506
|
const rows = getMRT_Rows(table, undefined, true);
|
506
507
|
const lastIndex = rows.findIndex((r) => r.id === lastSelectedRowId.current);
|
507
508
|
if (lastIndex !== -1) {
|
508
|
-
const
|
509
|
+
const isLastIndexChecked = getIsRowSelected({
|
510
|
+
row: rows === null || rows === void 0 ? void 0 : rows[lastIndex],
|
511
|
+
table,
|
512
|
+
});
|
513
|
+
const currentIndex = staticRowIndex + paginationOffset;
|
509
514
|
const [start, end] = lastIndex < currentIndex
|
510
515
|
? [lastIndex, currentIndex]
|
511
516
|
: [currentIndex, lastIndex];
|
512
|
-
|
513
|
-
|
517
|
+
// toggle selection of all rows between last selected and this one
|
518
|
+
// but only if the last selected row is not the same as the current one
|
519
|
+
if (isCurrentRowChecked !== isLastIndexChecked) {
|
520
|
+
for (let i = start; i <= end; i++) {
|
521
|
+
rows[i].toggleSelected(!isCurrentRowChecked);
|
522
|
+
}
|
514
523
|
}
|
515
524
|
}
|
516
525
|
}
|
526
|
+
// record the last selected row id
|
517
527
|
lastSelectedRowId.current = row.id;
|
518
528
|
// if all sub rows were selected, unselect them
|
519
529
|
if (row.getCanSelectSubRows() && row.getIsAllSubRowsSelected()) {
|
520
530
|
(_a = row.subRows) === null || _a === void 0 ? void 0 : _a.forEach((r) => r.toggleSelected(false));
|
521
531
|
}
|
522
532
|
if (isStickySelection) {
|
523
|
-
row.pin(!row.getIsPinned() &&
|
533
|
+
row.pin(!row.getIsPinned() && isCurrentRowChecked
|
524
534
|
? (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('bottom'))
|
525
535
|
? 'bottom'
|
526
536
|
: 'top'
|
@@ -1117,8 +1127,8 @@ const MRT_SelectCheckbox = (_a) => {
|
|
1117
1127
|
}, 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 });
|
1118
1128
|
return (jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, getCommonTooltipProps(), { title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : (selectAll
|
1119
1129
|
? localization.toggleSelectAll
|
1120
|
-
: localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsxRuntime.jsx(Radio__default["default"], Object.assign({}, commonProps))) : (jsxRuntime.jsx(Checkbox__default["default"], Object.assign({ indeterminate: selectAll
|
1121
|
-
? table.getIsSomeRowsSelected()
|
1130
|
+
: localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsxRuntime.jsx(Radio__default["default"], Object.assign({}, commonProps))) : (jsxRuntime.jsx(Checkbox__default["default"], Object.assign({ indeterminate: !isChecked && selectAll
|
1131
|
+
? table.getIsSomeRowsSelected()
|
1122
1132
|
: (row === null || row === void 0 ? void 0 : row.getIsSomeSelected()) && row.getCanSelectSubRows() }, commonProps))) })));
|
1123
1133
|
};
|
1124
1134
|
|