material-react-table 2.5.0 → 2.5.2

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 CHANGED
@@ -768,6 +768,8 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, pinnedRo
768
768
  const { density, draggingColumn, draggingRow, editingCell, editingRow, hoveredRow, isFullScreen, rowPinning, } = getState();
769
769
  const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer !== null && columnVirtualizer !== void 0 ? columnVirtualizer : {};
770
770
  const isPinned = enableRowPinning && row.getIsPinned();
771
+ const isDraggingRow = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id;
772
+ const isHoveredRow = (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id;
771
773
  const tableRowProps = parseFromValuesOrFunc(muiTableBodyRowProps, {
772
774
  row,
773
775
  staticRowIndex: rowIndex,
@@ -801,7 +803,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, pinnedRo
801
803
  };
802
804
  const rowRef = useRef(null);
803
805
  const { baseBackgroundColor, pinnedRowBackgroundColor, selectedRowBackgroundColor, } = getMRTTheme(table, theme);
804
- return (jsxs(Fragment, { children: [jsxs(TableRow, Object.assign({ "data-index": rowIndex, "data-pinned": !!isPinned || undefined, "data-selected": row.getIsSelected() || undefined, onDragEnter: handleDragEnter, ref: (node) => {
806
+ return (jsxs(Fragment, { children: [jsxs(TableRow, Object.assign({ "data-index": rowIndex, "data-pinned": !!isPinned || undefined, "data-selected": row.getIsSelected() || row.getIsAllSubRowsSelected() || undefined, onDragEnter: handleDragEnter, ref: (node) => {
805
807
  if (node) {
806
808
  rowRef.current = node;
807
809
  measureElement === null || measureElement === void 0 ? void 0 : measureElement(node);
@@ -819,11 +821,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, pinnedRo
819
821
  }, backgroundColor: `${baseBackgroundColor} !important`, bottom: !virtualRow && bottomPinnedIndex !== undefined && isPinned
820
822
  ? `${bottomPinnedIndex * rowHeight +
821
823
  (enableStickyFooter ? tableFooterHeight - 1 : 0)}px`
822
- : undefined, boxSizing: 'border-box', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, opacity: isPinned
823
- ? 0.97
824
- : (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
825
- ? 0.5
826
- : 1, position: virtualRow
824
+ : undefined, boxSizing: 'border-box', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, opacity: isPinned ? 0.97 : isDraggingRow || isHoveredRow ? 0.5 : 1, position: virtualRow
827
825
  ? 'absolute'
828
826
  : (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) && isPinned
829
827
  ? 'sticky'
@@ -846,7 +844,9 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, pinnedRo
846
844
  : cellOrVirtualCell;
847
845
  const props = {
848
846
  cell,
849
- measureElement: columnVirtualizer === null || columnVirtualizer === void 0 ? void 0 : columnVirtualizer.measureElement,
847
+ measureElement: !isDraggingRow && !isHoveredRow
848
+ ? columnVirtualizer === null || columnVirtualizer === void 0 ? void 0 : columnVirtualizer.measureElement
849
+ : undefined,
850
850
  numRows,
851
851
  rowIndex,
852
852
  rowRef,
@@ -959,7 +959,12 @@ const MRT_TableBodyRowGrabHandle = (_a) => {
959
959
  const handleDragStart = (event) => {
960
960
  var _a;
961
961
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
962
- event.dataTransfer.setDragImage(rowRef.current, 0, 0);
962
+ try {
963
+ event.dataTransfer.setDragImage(rowRef.current, 0, 0);
964
+ }
965
+ catch (e) {
966
+ console.error(e);
967
+ }
963
968
  table.setDraggingRow(row);
964
969
  };
965
970
  const handleDragEnd = (event) => {
@@ -1256,6 +1261,10 @@ const MRT_FilterOptionMenu = (_a) => {
1256
1261
  column.setFilterValue('');
1257
1262
  setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue('');
1258
1263
  }
1264
+ else if (currentFilterValue === ' ' &&
1265
+ emptyModes.includes(prevFilterMode)) {
1266
+ column.setFilterValue(undefined);
1267
+ }
1259
1268
  else {
1260
1269
  column.setFilterValue(currentFilterValue); // perform new filter render
1261
1270
  }
@@ -1518,7 +1527,9 @@ const MRT_SelectCheckbox = (_a) => {
1518
1527
  table.setRowPinning({ bottom: [], top: [] });
1519
1528
  }
1520
1529
  };
1521
- const commonProps = Object.assign(Object.assign({ checked: selectAll
1530
+ const commonProps = Object.assign(Object.assign({ 'aria-label': selectAll
1531
+ ? localization.toggleSelectAll
1532
+ : localization.toggleSelectRow, checked: selectAll
1522
1533
  ? allRowsSelected
1523
1534
  : (row === null || row === void 0 ? void 0 : row.getIsSelected()) || (row === null || row === void 0 ? void 0 : row.getIsAllSubRowsSelected()), disabled: isLoading || (row && !row.getCanSelect()) || (row === null || row === void 0 ? void 0 : row.id) === 'mrt-row-create', inputProps: {
1524
1535
  'aria-label': selectAll
@@ -2693,7 +2704,7 @@ const MRT_FilterTextField = (_a) => {
2693
2704
  if (textFieldProps.inputRef) {
2694
2705
  textFieldProps.inputRef = inputRef;
2695
2706
  }
2696
- }, margin: 'none', onClick: (e) => e.stopPropagation(), placeholder: filterChipLabel || isSelectFilter || isMultiSelectFilter
2707
+ }, margin: 'none', placeholder: filterChipLabel || isSelectFilter || isMultiSelectFilter
2697
2708
  ? undefined
2698
2709
  : filterPlaceholder, variant: 'standard' }, textFieldProps), { sx: (theme) => (Object.assign({ minWidth: isDateFilter
2699
2710
  ? '160px'
@@ -2721,13 +2732,13 @@ const MRT_FilterTextField = (_a) => {
2721
2732
  textField: Object.assign(Object.assign({}, commonTextFieldProps), (_s = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _s === void 0 ? void 0 : _s.textField),
2722
2733
  } }))) : isAutocompleteFilter ? (jsx(Autocomplete, Object.assign({ freeSolo: true, getOptionLabel: (option) => getValueAndLabel(option).label, onChange: (_e, newValue) => handleChange(getValueAndLabel(newValue).value), options: (_t = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option) => getValueAndLabel(option))) !== null && _t !== void 0 ? _t : [] }, autocompleteProps, { renderInput: (builtinTextFieldProps) => {
2723
2734
  var _a;
2724
- return (jsx(TextField, Object.assign({}, builtinTextFieldProps, commonTextFieldProps, { InputProps: Object.assign(Object.assign({}, builtinTextFieldProps.InputProps), { startAdornment: (_a = commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.InputProps) === null || _a === void 0 ? void 0 : _a.startAdornment }), inputProps: Object.assign(Object.assign({}, builtinTextFieldProps.inputProps), commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.inputProps), onChange: handleTextFieldChange })));
2735
+ return (jsx(TextField, Object.assign({}, builtinTextFieldProps, commonTextFieldProps, { InputProps: Object.assign(Object.assign({}, builtinTextFieldProps.InputProps), { startAdornment: (_a = commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.InputProps) === null || _a === void 0 ? void 0 : _a.startAdornment }), inputProps: Object.assign(Object.assign({}, builtinTextFieldProps.inputProps), commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.inputProps), onChange: handleTextFieldChange, onClick: (e) => e.stopPropagation() })));
2725
2736
  }, value: filterValue }))) : (jsx(TextField, Object.assign({ select: isSelectFilter || isMultiSelectFilter }, commonTextFieldProps, { SelectProps: Object.assign({ displayEmpty: true, multiple: isMultiSelectFilter, renderValue: isMultiSelectFilter
2726
2737
  ? (selected) => !(selected === null || selected === void 0 ? void 0 : selected.length) ? (jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder })) : (jsx(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: '2px' }, children: selected === null || selected === void 0 ? void 0 : selected.map((value) => {
2727
2738
  const selectedValue = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.find((option) => getValueAndLabel(option).value === value);
2728
2739
  return (jsx(Chip, { label: getValueAndLabel(selectedValue).label }, value));
2729
2740
  }) }))
2730
- : undefined }, commonTextFieldProps.SelectProps), onChange: handleTextFieldChange, value: filterValue !== null && filterValue !== void 0 ? filterValue : '', children: (isSelectFilter || isMultiSelectFilter) && [
2741
+ : undefined }, commonTextFieldProps.SelectProps), onChange: handleTextFieldChange, onClick: (e) => e.stopPropagation(), value: filterValue !== null && filterValue !== void 0 ? filterValue : '', children: (isSelectFilter || isMultiSelectFilter) && [
2731
2742
  jsx(MenuItem, { disabled: true, divider: true, hidden: true, value: "", children: jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder }) }, "p"),
2732
2743
  ...[
2733
2744
  (_u = textFieldProps.children) !== null && _u !== void 0 ? _u : dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option, index) => {
@@ -2811,7 +2822,7 @@ const MRT_FilterRangeSlider = (_a) => {
2811
2822
  }
2812
2823
  },
2813
2824
  },
2814
- }, sx: (theme) => (Object.assign({ m: 'auto', mt: !showChangeModeButton ? '10px' : '6px', px: '4px', width: 'calc(100% - 8px)' }, parseFromValuesOrFunc(sliderProps === null || sliderProps === void 0 ? void 0 : sliderProps.sx, theme))) })), showChangeModeButton ? (jsx(FormHelperText, { sx: {
2825
+ }, sx: (theme) => (Object.assign({ m: 'auto', minWidth: `${column.getSize() - 50}px`, mt: !showChangeModeButton ? '10px' : '6px', px: '4px', width: 'calc(100% - 8px)' }, parseFromValuesOrFunc(sliderProps === null || sliderProps === void 0 ? void 0 : sliderProps.sx, theme))) })), showChangeModeButton ? (jsx(FormHelperText, { sx: {
2815
2826
  fontSize: '0.75rem',
2816
2827
  lineHeight: '0.8rem',
2817
2828
  m: '-3px -6px',
@@ -2882,7 +2893,7 @@ const MRT_TableHeadCellFilterLabel = (_a) => {
2882
2893
  //@ts-ignore
2883
2894
  event.stopPropagation();
2884
2895
  setAnchorEl(null);
2885
- }, onKeyDown: (event) => event.key === 'Enter' && setAnchorEl(null), open: !!anchorEl, transformOrigin: {
2896
+ }, onKeyDown: (event) => event.key === 'Enter' && setAnchorEl(null), open: !!anchorEl, slotProps: { paper: { sx: { overflow: 'visible' } } }, transformOrigin: {
2886
2897
  horizontal: 'center',
2887
2898
  vertical: 'bottom',
2888
2899
  }, children: jsx(Box, { sx: { p: '1rem' }, children: jsx(MRT_TableHeadCellFilterContainer, { header: header, table: table }) }) })] }));
@@ -2901,7 +2912,12 @@ const MRT_TableHeadCellGrabHandle = (_a) => {
2901
2912
  var _a;
2902
2913
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
2903
2914
  setDraggingColumn(column);
2904
- event.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
2915
+ try {
2916
+ event.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
2917
+ }
2918
+ catch (e) {
2919
+ console.error(e);
2920
+ }
2905
2921
  };
2906
2922
  const handleDragEnd = (event) => {
2907
2923
  var _a;
@@ -3266,16 +3282,17 @@ const MRT_GlobalFilterTextField = (_a) => {
3266
3282
  const MRT_ToolbarAlertBanner = (_a) => {
3267
3283
  var _b, _c, _d;
3268
3284
  var { stackAlertBanner, table } = _a, rest = __rest(_a, ["stackAlertBanner", "table"]);
3269
- const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { enableRowSelection, enableSelectAll, localization, muiToolbarAlertBannerChipProps, muiToolbarAlertBannerProps, positionToolbarAlertBanner, renderToolbarAlertBannerContent, rowCount, }, refs: { tablePaperRef }, } = table;
3270
- const { density, grouping, showAlertBanner } = getState();
3285
+ const { getPrePaginationRowModel, getState, options: { enableRowSelection, enableSelectAll, localization, muiToolbarAlertBannerChipProps, muiToolbarAlertBannerProps, positionToolbarAlertBanner, renderToolbarAlertBannerContent, rowCount, }, refs: { tablePaperRef }, } = table;
3286
+ const { density, grouping, rowSelection, showAlertBanner } = getState();
3271
3287
  const alertProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiToolbarAlertBannerProps, {
3272
3288
  table,
3273
3289
  })), rest);
3274
3290
  const chipProps = parseFromValuesOrFunc(muiToolbarAlertBannerChipProps, {
3275
3291
  table,
3276
3292
  });
3277
- const selectedAlert = getSelectedRowModel().rows.length > 0
3278
- ? (_c = (_b = localization.selectedCountOfRowCountRowsSelected) === null || _b === void 0 ? void 0 : _b.replace('{selectedCount}', getSelectedRowModel().rows.length.toString())) === null || _c === void 0 ? void 0 : _c.replace('{rowCount}', (rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length).toString())
3293
+ const selectedRowCount = useMemo(() => Object.values(rowSelection).filter(Boolean).length, [rowSelection]);
3294
+ const selectedAlert = selectedRowCount > 0
3295
+ ? (_c = (_b = localization.selectedCountOfRowCountRowsSelected) === null || _b === void 0 ? void 0 : _b.replace('{selectedCount}', selectedRowCount.toLocaleString())) === null || _c === void 0 ? void 0 : _c.replace('{rowCount}', (rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length).toString())
3279
3296
  : null;
3280
3297
  const groupedAlert = grouping.length > 0 ? (jsxs("span", { children: [localization.groupedBy, ' ', grouping.map((columnId, index) => (jsxs(Fragment$1, { children: [index > 0 ? localization.thenBy : '', jsx(Chip, Object.assign({ label: table.getColumn(columnId).columnDef.header, onDelete: () => table.getColumn(columnId).toggleGrouping() }, chipProps))] }, `${index}-${columnId}`)))] })) : null;
3281
3298
  return (jsx(Collapse, { in: showAlertBanner || !!selectedAlert || !!groupedAlert, timeout: stackAlertBanner ? 200 : 0, children: jsx(Alert, Object.assign({ color: "info", icon: false }, alertProps, { sx: (theme) => {
@@ -3395,7 +3412,12 @@ const MRT_ShowHideColumnsMenuItems = (_a) => {
3395
3412
  const [isDragging, setIsDragging] = useState(false);
3396
3413
  const handleDragStart = (e) => {
3397
3414
  setIsDragging(true);
3398
- e.dataTransfer.setDragImage(menuItemRef.current, 0, 0);
3415
+ try {
3416
+ e.dataTransfer.setDragImage(menuItemRef.current, 0, 0);
3417
+ }
3418
+ catch (e) {
3419
+ console.error(e);
3420
+ }
3399
3421
  };
3400
3422
  const handleDragEnd = (_e) => {
3401
3423
  setIsDragging(false);