material-react-table 3.0.0 → 3.0.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.d.ts CHANGED
@@ -1076,7 +1076,7 @@ interface MRT_TableOptions<TData extends MRT_RowData> extends Omit<Partial<Table
1076
1076
  row: MRT_Row<TData>;
1077
1077
  table: MRT_TableInstance<TData>;
1078
1078
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
1079
- }) => void;
1079
+ }) => Promise<void> | void;
1080
1080
  onDensityChange?: OnChangeFn<MRT_DensityState>;
1081
1081
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
1082
1082
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
package/dist/index.esm.js CHANGED
@@ -50,7 +50,6 @@ import ViewColumnIcon from '@mui/icons-material/ViewColumn';
50
50
  import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
51
51
  import { defaultRangeExtractor, useVirtualizer } from '@tanstack/react-virtual';
52
52
  import Paper from '@mui/material/Paper';
53
- import FocusTrap from '@mui/material/Unstable_TrapFocus/FocusTrap';
54
53
  import TableContainer from '@mui/material/TableContainer';
55
54
  import Table from '@mui/material/Table';
56
55
  import TableBody from '@mui/material/TableBody';
@@ -437,6 +436,8 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
437
436
  var _a, _b, _c, _d, _e, _f, _g, _h;
438
437
  if (!table.options.enableKeyboardShortcuts)
439
438
  return;
439
+ if (event.isPropagationStopped())
440
+ return;
440
441
  const currentCell = event.currentTarget;
441
442
  if (cellValue && isWinCtrlMacMeta(event) && event.key === 'c') {
442
443
  navigator.clipboard.writeText(cellValue);
@@ -925,7 +926,7 @@ const MRT_RowActionMenu = (_a) => {
925
926
  const menuItems = useMemo(() => {
926
927
  const items = [];
927
928
  const editItem = parseFromValuesOrFunc(enableEditing, row) &&
928
- ['modal', 'row'].includes(editDisplayMode) && (jsx(MRT_ActionMenuItem, { icon: jsx(EditIcon, {}), label: localization.edit, onClick: handleEdit, table: table }));
929
+ ['modal', 'row'].includes(editDisplayMode) && (jsx(MRT_ActionMenuItem, { icon: jsx(EditIcon, {}), label: localization.edit, onClick: handleEdit, table: table }, 'edit'));
929
930
  if (editItem)
930
931
  items.push(editItem);
931
932
  const rowActionMenuItems = renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 : renderRowActionMenuItems({
@@ -2102,7 +2103,7 @@ const MRT_EditCellTextField = (_a) => {
2102
2103
  : {})), textFieldProps.InputProps), { sx: (theme) => {
2103
2104
  var _a;
2104
2105
  return (Object.assign({ mb: 0 }, parseFromValuesOrFunc((_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.InputProps) === null || _a === void 0 ? void 0 : _a.sx, theme)));
2105
- } }), SelectProps: Object.assign({ MenuProps: { disableScrollLock: true } }, textFieldProps.SelectProps), inputProps: Object.assign({ autoComplete: 'new-password' }, textFieldProps.inputProps), onBlur: handleBlur, onChange: handleChange, onClick: (e) => {
2106
+ } }), SelectProps: Object.assign({ MenuProps: { disableScrollLock: true } }, textFieldProps.SelectProps), inputProps: Object.assign({ autoComplete: 'off' }, textFieldProps.inputProps), onBlur: handleBlur, onChange: handleChange, onClick: (e) => {
2106
2107
  var _a;
2107
2108
  e.stopPropagation();
2108
2109
  (_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.onClick) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, e);
@@ -2245,13 +2246,13 @@ const MRT_TableBodyCell = (_a) => {
2245
2246
  };
2246
2247
  const handleKeyDown = (event) => {
2247
2248
  var _a;
2249
+ (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
2248
2250
  cellKeyboardShortcuts({
2249
2251
  cell,
2250
2252
  cellValue: cell.getValue(),
2251
2253
  event,
2252
2254
  table,
2253
2255
  });
2254
- (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
2255
2256
  };
2256
2257
  return (jsx(TableCell, Object.assign({ align: theme.direction === 'rtl' ? 'right' : 'left', "data-index": staticColumnIndex, "data-pinned": !!isColumnPinned || undefined, tabIndex: enableKeyboardShortcuts ? 0 : undefined }, tableCellProps, { onKeyDown: handleKeyDown, onContextMenu: handleContextMenu, onDoubleClick: handleDoubleClick, onDragEnter: handleDragEnter, onDragOver: handleDragOver, sx: (theme) => (Object.assign(Object.assign({ '&:hover': {
2257
2258
  outline: (actionCell === null || actionCell === void 0 ? void 0 : actionCell.id) === cell.id ||
@@ -2526,12 +2527,12 @@ const MRT_TableFooterCell = (_a) => {
2526
2527
  const tableCellProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTableFooterCellProps, args)), parseFromValuesOrFunc(columnDef.muiTableFooterCellProps, args)), rest);
2527
2528
  const handleKeyDown = (event) => {
2528
2529
  var _a;
2530
+ (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
2529
2531
  cellKeyboardShortcuts({
2530
2532
  event,
2531
2533
  cellValue: footer.column.columnDef.footer,
2532
2534
  table,
2533
2535
  });
2534
- (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
2535
2536
  };
2536
2537
  return (jsx(TableCell, Object.assign({ align: columnDefType === 'group'
2537
2538
  ? 'center'
@@ -3138,7 +3139,7 @@ const MRT_FilterTextField = (_a) => {
3138
3139
  localization[`filter${((_k = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _k === void 0 ? void 0 : _k.toUpperCase()) +
3139
3140
  (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]) })) : null, inputProps: {
3140
3141
  'aria-label': filterPlaceholder,
3141
- autoComplete: 'new-password', // disable autocomplete and autofill
3142
+ autoComplete: 'off',
3142
3143
  disabled: !!filterChipLabel,
3143
3144
  sx: {
3144
3145
  textOverflow: 'ellipsis',
@@ -3181,15 +3182,21 @@ const MRT_FilterTextField = (_a) => {
3181
3182
  } }))) : (filterVariant === null || filterVariant === void 0 ? void 0 : filterVariant.startsWith('date')) ? (jsx(DatePicker, Object.assign({}, commonDatePickerProps, datePickerProps, { slotProps: {
3182
3183
  field: Object.assign({ clearable: true, onClear: () => handleClear() }, (_q = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _q === void 0 ? void 0 : _q.field),
3183
3184
  textField: Object.assign(Object.assign({}, commonTextFieldProps), (_r = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _r === void 0 ? void 0 : _r.textField),
3184
- } }))) : isAutocompleteFilter ? (jsx(Autocomplete, Object.assign({ freeSolo: true, getOptionLabel: (option) => getValueAndLabel(option).label, onChange: (_e, newValue) => handleAutocompleteChange(newValue), options: (_s = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option) => getValueAndLabel(option))) !== null && _s !== void 0 ? _s : [] }, autocompleteProps, { renderInput: (builtinTextFieldProps) => {
3185
+ } }))) : isAutocompleteFilter ? (jsx(Autocomplete, Object.assign({ freeSolo: true, getOptionLabel: (option) => getValueAndLabel(option).label,
3186
+ // @ts-ignore
3187
+ onChange: (_e, newValue) => handleAutocompleteChange(newValue), options: (_s = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option) => getValueAndLabel(option))) !== null && _s !== void 0 ? _s : [] }, autocompleteProps, { renderInput: (builtinTextFieldProps) => {
3185
3188
  var _a;
3186
3189
  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() })));
3187
3190
  }, value: autocompleteValue }))) : (jsx(TextField, Object.assign({ select: isSelectFilter || isMultiSelectFilter }, commonTextFieldProps, { SelectProps: Object.assign({ MenuProps: { disableScrollLock: true }, displayEmpty: true, multiple: isMultiSelectFilter, renderValue: isMultiSelectFilter
3188
- ? (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) => {
3191
+ ? (selected) => !Array.isArray(selected) || selected.length === 0 ? (jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder })) : (jsx(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: '2px' }, children: selected.map((value) => {
3189
3192
  const selectedValue = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.find((option) => getValueAndLabel(option).value === value);
3190
3193
  return (jsx(Chip, { label: getValueAndLabel(selectedValue).label }, value));
3191
3194
  }) }))
3192
- : undefined }, commonTextFieldProps.SelectProps), onChange: handleTextFieldChange, onClick: (e) => e.stopPropagation(), value: filterValue !== null && filterValue !== void 0 ? filterValue : '', children: (isSelectFilter || isMultiSelectFilter) && [
3195
+ : undefined }, commonTextFieldProps.SelectProps), onChange: handleTextFieldChange, onClick: (e) => e.stopPropagation(), value: isMultiSelectFilter
3196
+ ? Array.isArray(filterValue)
3197
+ ? filterValue
3198
+ : []
3199
+ : '', children: (isSelectFilter || isMultiSelectFilter) && [
3193
3200
  jsx(MenuItem, { disabled: true, divider: true, hidden: true, value: "", children: jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder }) }, "p"),
3194
3201
  ...[
3195
3202
  (_t = textFieldProps.children) !== null && _t !== void 0 ? _t : dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option, index) => {
@@ -3538,13 +3545,13 @@ const MRT_TableHeadCell = (_a) => {
3538
3545
  };
3539
3546
  const handleKeyDown = (event) => {
3540
3547
  var _a;
3548
+ (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
3541
3549
  cellKeyboardShortcuts({
3542
3550
  event,
3543
3551
  cellValue: header.column.columnDef.header,
3544
3552
  table,
3545
3553
  header,
3546
3554
  });
3547
- (_a = tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(tableCellProps, event);
3548
3555
  };
3549
3556
  const HeaderElement = (_b = parseFromValuesOrFunc(columnDef.Header, {
3550
3557
  column,
@@ -4250,7 +4257,7 @@ const MRT_GlobalFilterTextField = (_a) => {
4250
4257
  }
4251
4258
  isMounted.current = true;
4252
4259
  }, [globalFilter]);
4253
- return (jsxs(Collapse, { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsx(TextField, Object.assign({ inputProps: Object.assign({ autoComplete: 'new-password' }, textFieldProps.inputProps), onChange: handleChange, placeholder: localization.search, size: "small", value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "outlined" }, textFieldProps, { InputProps: Object.assign(Object.assign({ endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(Tooltip, { title: (_b = localization.clearSearch) !== null && _b !== void 0 ? _b : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsx(CloseIcon, {}) }) }) }) })), startAdornment: enableGlobalFilterModes ? (jsx(InputAdornment, { position: "start", children: jsx(Tooltip, { title: localization.changeSearchMode, children: jsx(IconButton, { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(SearchIcon, {}) }) }) })) : (jsx(SearchIcon, { style: { marginRight: '4px' } })) }, textFieldProps.InputProps), { sx: (theme) => {
4260
+ return (jsxs(Collapse, { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsx(TextField, Object.assign({ inputProps: Object.assign({ autoComplete: 'off' }, textFieldProps.inputProps), onChange: handleChange, placeholder: localization.search, size: "small", value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "outlined" }, textFieldProps, { InputProps: Object.assign(Object.assign({ endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(Tooltip, { title: (_b = localization.clearSearch) !== null && _b !== void 0 ? _b : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsx(CloseIcon, {}) }) }) }) })), startAdornment: enableGlobalFilterModes ? (jsx(InputAdornment, { position: "start", children: jsx(Tooltip, { title: localization.changeSearchMode, children: jsx(IconButton, { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(SearchIcon, {}) }) }) })) : (jsx(SearchIcon, { style: { marginRight: '4px' } })) }, textFieldProps.InputProps), { sx: (theme) => {
4254
4261
  var _a;
4255
4262
  return (Object.assign({ mb: 0 }, parseFromValuesOrFunc((_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.InputProps) === null || _a === void 0 ? void 0 : _a.sx, theme)));
4256
4263
  } }), inputRef: (inputRef) => {
@@ -4314,30 +4321,30 @@ const MRT_TablePaper = (_a) => {
4314
4321
  const { isFullScreen } = getState();
4315
4322
  const paperProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTablePaperProps, { table })), rest);
4316
4323
  const theme = useTheme();
4317
- return (jsx(FocusTrap, { disableEnforceFocus: true, open: isFullScreen, children: jsxs(Paper, Object.assign({ elevation: 2, onKeyDown: (e) => e.key === 'Escape' && table.setIsFullScreen(false) }, paperProps, { ref: (ref) => {
4318
- tablePaperRef.current = ref;
4319
- if (paperProps === null || paperProps === void 0 ? void 0 : paperProps.ref) {
4320
- //@ts-ignore
4321
- paperProps.ref.current = ref;
4322
- }
4323
- }, style: Object.assign(Object.assign({}, (isFullScreen
4324
- ? {
4325
- bottom: 0,
4326
- height: '100dvh',
4327
- left: 0,
4328
- margin: 0,
4329
- maxHeight: '100dvh',
4330
- maxWidth: '100dvw',
4331
- padding: 0,
4332
- position: 'fixed',
4333
- right: 0,
4334
- top: 0,
4335
- width: '100dvw',
4336
- zIndex: theme.zIndex.modal,
4337
- }
4338
- : {})), paperProps === null || paperProps === void 0 ? void 0 : paperProps.style), sx: (theme) => (Object.assign({ backgroundColor: baseBackgroundColor, backgroundImage: 'unset', overflow: 'hidden', transition: 'all 100ms ease-in-out' }, parseFromValuesOrFunc(paperProps === null || paperProps === void 0 ? void 0 : paperProps.sx, theme))), children: [enableTopToolbar &&
4339
- ((_b = parseFromValuesOrFunc(renderTopToolbar, { table })) !== null && _b !== void 0 ? _b : (jsx(MRT_TopToolbar, { table: table }))), jsx(MRT_TableContainer, { table: table }), enableBottomToolbar &&
4340
- ((_c = parseFromValuesOrFunc(renderBottomToolbar, { table })) !== null && _c !== void 0 ? _c : (jsx(MRT_BottomToolbar, { table: table })))] })) }));
4324
+ return (jsxs(Paper, Object.assign({ elevation: 2, onKeyDown: (e) => e.key === 'Escape' && table.setIsFullScreen(false) }, paperProps, { ref: (ref) => {
4325
+ tablePaperRef.current = ref;
4326
+ if (paperProps === null || paperProps === void 0 ? void 0 : paperProps.ref) {
4327
+ //@ts-ignore
4328
+ paperProps.ref.current = ref;
4329
+ }
4330
+ }, style: Object.assign(Object.assign({}, (isFullScreen
4331
+ ? {
4332
+ bottom: 0,
4333
+ height: '100dvh',
4334
+ left: 0,
4335
+ margin: 0,
4336
+ maxHeight: '100dvh',
4337
+ maxWidth: '100dvw',
4338
+ padding: 0,
4339
+ position: 'fixed',
4340
+ right: 0,
4341
+ top: 0,
4342
+ width: '100dvw',
4343
+ zIndex: theme.zIndex.modal,
4344
+ }
4345
+ : {})), paperProps === null || paperProps === void 0 ? void 0 : paperProps.style), sx: (theme) => (Object.assign({ backgroundColor: baseBackgroundColor, backgroundImage: 'unset', overflow: 'hidden', transition: 'all 100ms ease-in-out' }, parseFromValuesOrFunc(paperProps === null || paperProps === void 0 ? void 0 : paperProps.sx, theme))), children: [enableTopToolbar &&
4346
+ ((_b = parseFromValuesOrFunc(renderTopToolbar, { table })) !== null && _b !== void 0 ? _b : (jsx(MRT_TopToolbar, { table: table }))), jsx(MRT_TableContainer, { table: table }), enableBottomToolbar &&
4347
+ ((_c = parseFromValuesOrFunc(renderBottomToolbar, { table })) !== null && _c !== void 0 ? _c : (jsx(MRT_BottomToolbar, { table: table })))] })));
4341
4348
  };
4342
4349
 
4343
4350
  const isTableInstanceProp = (props) => props.table !== undefined;