material-react-table 2.0.3 → 2.0.5

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.js CHANGED
@@ -517,7 +517,7 @@ const MRT_TableBodyCellValue = ({ cell, table, }) => {
517
517
  allowedTypes.includes(typeof renderedCellValue) &&
518
518
  ((filterValue &&
519
519
  allowedTypes.includes(typeof filterValue) &&
520
- columnDef.filterVariant === 'text') ||
520
+ ['autocomplete', 'text'].includes(columnDef.filterVariant)) ||
521
521
  (globalFilter &&
522
522
  allowedTypes.includes(typeof globalFilter) &&
523
523
  column.getCanGlobalFilter()))) {
@@ -1076,19 +1076,18 @@ const MRT_TableBody = (_a) => {
1076
1076
  const virtualRows = rowVirtualizer
1077
1077
  ? rowVirtualizer.getVirtualItems()
1078
1078
  : undefined;
1079
+ const commonRowProps = {
1080
+ columnVirtualizer,
1081
+ numRows: rows.length,
1082
+ table,
1083
+ virtualColumns,
1084
+ virtualPaddingLeft,
1085
+ virtualPaddingRight,
1086
+ };
1079
1087
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) &&
1080
1088
  getIsSomeRowsPinned('top') && (jsxRuntime.jsx(TableBody__default["default"], Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'sticky', top: tableHeadHeight - 1, zIndex: 1 }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: getTopRows().map((row, rowIndex) => {
1081
- const props = {
1082
- columnVirtualizer,
1083
- measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
1084
- numRows: rows.length,
1085
- row,
1086
- rowIndex,
1087
- table,
1088
- virtualColumns,
1089
- virtualPaddingLeft,
1090
- virtualPaddingRight,
1091
- };
1089
+ const props = Object.assign(Object.assign({}, commonRowProps), { row,
1090
+ rowIndex });
1092
1091
  return memoMode === 'rows' ? (jsxRuntime.jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsxRuntime.jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1093
1092
  }) }))), jsxRuntime.jsxs(TableBody__default["default"], Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, height: rowVirtualizer
1094
1093
  ? `${rowVirtualizer.getTotalSize()}px`
@@ -1109,36 +1108,16 @@ const MRT_TableBody = (_a) => {
1109
1108
  const row = rowVirtualizer
1110
1109
  ? rows[rowOrVirtualRow.index]
1111
1110
  : rowOrVirtualRow;
1112
- const props = {
1113
- columnVirtualizer,
1114
- measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
1115
- numRows: rows.length,
1116
- pinnedRowIds,
1117
- row,
1118
- rowIndex: rowVirtualizer ? rowOrVirtualRow.index : rowIndex,
1119
- table,
1120
- virtualColumns,
1121
- virtualPaddingLeft,
1122
- virtualPaddingRight,
1123
- virtualRow: rowVirtualizer
1111
+ const props = Object.assign(Object.assign({}, commonRowProps), { measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement, pinnedRowIds,
1112
+ row, rowIndex: rowVirtualizer ? rowOrVirtualRow.index : rowIndex, virtualRow: rowVirtualizer
1124
1113
  ? rowOrVirtualRow
1125
- : undefined,
1126
- };
1127
- return memoMode === 'rows' ? (jsxRuntime.jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsxRuntime.jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1114
+ : undefined });
1115
+ return memoMode === 'rows' ? (jsxRuntime.jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), `${row.id}${row.index}`)) : (jsxRuntime.jsx(MRT_TableBodyRow, Object.assign({}, props), `${row.id}${row.index}`));
1128
1116
  }) })))] })), !(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) &&
1129
1117
  getIsSomeRowsPinned('bottom') && (jsxRuntime.jsx(TableBody__default["default"], Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ bottom: tableFooterHeight - 1, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'sticky', zIndex: 1 }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: getBottomRows().map((row, rowIndex) => {
1130
- const props = {
1131
- columnVirtualizer,
1132
- measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
1133
- numRows: rows.length,
1134
- row,
1135
- rowIndex,
1136
- table,
1137
- virtualColumns,
1138
- virtualPaddingLeft,
1139
- virtualPaddingRight,
1140
- };
1141
- return memoMode === 'rows' ? (jsxRuntime.jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsxRuntime.jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1118
+ const props = Object.assign(Object.assign({}, commonRowProps), { row,
1119
+ rowIndex });
1120
+ return memoMode === 'rows' ? (jsxRuntime.jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), `${row.id}`)) : (jsxRuntime.jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
1142
1121
  }) })))] }));
1143
1122
  };
1144
1123
  const Memo_MRT_TableBody = react.memo(MRT_TableBody, (prev, next) => prev.table.options.data === next.table.options.data);
@@ -1759,7 +1738,7 @@ const MRT_FilterTextField = (_a) => {
1759
1738
  localization[`filter${((_l = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _l === void 0 ? void 0 : _l.toUpperCase()) +
1760
1739
  (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]) })) : null, inputProps: {
1761
1740
  'aria-label': filterPlaceholder,
1762
- autoComplete: 'new-password',
1741
+ autoComplete: 'new-password', // disable autocomplete and autofill
1763
1742
  disabled: !!filterChipLabel,
1764
1743
  sx: {
1765
1744
  textOverflow: 'ellipsis',
@@ -2041,11 +2020,14 @@ const MRT_TableHeadCellSortLabel = (_a) => {
2041
2020
  : column.getNextSortingOrder() === 'desc'
2042
2021
  ? localization.sortByColumnDesc.replace('{column}', columnDef.header)
2043
2022
  : localization.sortByColumnAsc.replace('{column}', columnDef.header);
2023
+ const direction = isSorted
2024
+ ? column.getIsSorted()
2025
+ : undefined;
2044
2026
  return (jsxRuntime.jsx(Tooltip__default["default"], { placement: "top", title: sortTooltip, children: jsxRuntime.jsx(Badge__default["default"], { badgeContent: sorting.length > 1 ? column.getSortIndex() + 1 : 0, overlap: "circular", children: jsxRuntime.jsx(TableSortLabel__default["default"], Object.assign({ IconComponent: !isSorted
2045
- ? (props) => (jsxRuntime.jsx(SyncAltIcon, Object.assign({}, props, { style: {
2027
+ ? (props) => (jsxRuntime.jsx(SyncAltIcon, Object.assign({}, props, { direction: direction, style: {
2046
2028
  transform: 'rotate(-90deg) scaleX(0.9) translateX(-1px)',
2047
2029
  } })))
2048
- : ArrowDownwardIcon, active: true, "aria-label": sortTooltip, direction: isSorted ? column.getIsSorted() : undefined, onClick: (e) => {
2030
+ : ArrowDownwardIcon, active: true, "aria-label": sortTooltip, direction: direction, onClick: (e) => {
2049
2031
  var _a;
2050
2032
  e.stopPropagation();
2051
2033
  (_a = header.column.getToggleSortingHandler()) === null || _a === void 0 ? void 0 : _a(e);
@@ -2243,8 +2225,8 @@ const MRT_TablePagination = (_a) => {
2243
2225
  const showFirstLastPageButtons = numberOfPages > 2;
2244
2226
  const firstRowIndex = pageIndex * pageSize;
2245
2227
  const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
2246
- const _b = paginationProps !== null && paginationProps !== void 0 ? paginationProps : {}, { rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true } = _b, _rest = __rest(_b, ["rowsPerPageOptions", "showFirstButton", "showLastButton", "showRowsPerPage"]);
2247
- return (jsxRuntime.jsxs(Box__default["default"], { sx: {
2228
+ const _b = paginationProps !== null && paginationProps !== void 0 ? paginationProps : {}, { SelectProps, rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true } = _b, _rest = __rest(_b, ["SelectProps", "rowsPerPageOptions", "showFirstButton", "showLastButton", "showRowsPerPage"]);
2229
+ return (jsxRuntime.jsxs(Box__default["default"], { className: "MuiTablePagination-root", sx: {
2248
2230
  alignItems: 'center',
2249
2231
  display: 'flex',
2250
2232
  flexWrap: 'wrap',
@@ -2260,7 +2242,12 @@ const MRT_TablePagination = (_a) => {
2260
2242
  px: '8px',
2261
2243
  py: '12px',
2262
2244
  zIndex: 2,
2263
- }, children: [showRowsPerPage && (jsxRuntime.jsxs(Box__default["default"], { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsxRuntime.jsx(InputLabel__default["default"], { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsxRuntime.jsx(Select__default["default"], { disableUnderline: true, id: "mrt-rows-per-page", inputProps: { 'aria-label': localization.rowsPerPage }, label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard", children: rowsPerPageOptions.map((value) => (jsxRuntime.jsx(MenuItem__default["default"], { sx: { m: 0 }, value: value, children: value }, value))) })] })), paginationDisplayMode === 'pages' ? (jsxRuntime.jsx(Pagination__default["default"], Object.assign({ count: numberOfPages, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsxRuntime.jsx(PaginationItem__default["default"], Object.assign({ slots: {
2245
+ }, children: [showRowsPerPage && (jsxRuntime.jsxs(Box__default["default"], { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsxRuntime.jsx(InputLabel__default["default"], { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsxRuntime.jsx(Select__default["default"], Object.assign({ disableUnderline: true, id: "mrt-rows-per-page", inputProps: { 'aria-label': localization.rowsPerPage }, label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard" }, SelectProps, { children: rowsPerPageOptions.map((option) => {
2246
+ var _a;
2247
+ const value = typeof option !== 'number' ? option.value : option;
2248
+ const label = typeof option !== 'number' ? option.label : `${option}`;
2249
+ return ((_a = SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.children) !== null && _a !== void 0 ? _a : ((SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.native) ? (jsxRuntime.jsx("option", { value: value, children: label }, value)) : (jsxRuntime.jsx(MenuItem__default["default"], { sx: { m: 0 }, value: value, children: label }, value))));
2250
+ }) }))] })), paginationDisplayMode === 'pages' ? (jsxRuntime.jsx(Pagination__default["default"], Object.assign({ count: numberOfPages, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsxRuntime.jsx(PaginationItem__default["default"], Object.assign({ slots: {
2264
2251
  first: FirstPageIcon,
2265
2252
  last: LastPageIcon,
2266
2253
  next: ChevronRightIcon,
@@ -2305,10 +2292,10 @@ const MRT_GlobalFilterTextField = (_a) => {
2305
2292
  }
2306
2293
  isMounted.current = true;
2307
2294
  }, [globalFilter]);
2308
- return (jsxRuntime.jsxs(Collapse__default["default"], { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsxRuntime.jsx(TextField__default["default"], Object.assign({ InputProps: Object.assign(Object.assign({ endAdornment: (jsxRuntime.jsx(InputAdornment__default["default"], { position: "end", children: jsxRuntime.jsx(Tooltip__default["default"], { title: (_b = localization.clearSearch) !== null && _b !== void 0 ? _b : '', children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsxRuntime.jsx(CloseIcon, {}) }) }) }) })), startAdornment: enableGlobalFilterModes ? (jsxRuntime.jsx(InputAdornment__default["default"], { position: "start", children: jsxRuntime.jsx(Tooltip__default["default"], { title: localization.changeSearchMode, children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsxRuntime.jsx(SearchIcon, {}) }) }) })) : (jsxRuntime.jsx(SearchIcon, { style: { marginRight: '4px' } })) }, textFieldProps.InputProps), { sx: (theme) => {
2295
+ return (jsxRuntime.jsxs(Collapse__default["default"], { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsxRuntime.jsx(TextField__default["default"], 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: (jsxRuntime.jsx(InputAdornment__default["default"], { position: "end", children: jsxRuntime.jsx(Tooltip__default["default"], { title: (_b = localization.clearSearch) !== null && _b !== void 0 ? _b : '', children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsxRuntime.jsx(CloseIcon, {}) }) }) }) })), startAdornment: enableGlobalFilterModes ? (jsxRuntime.jsx(InputAdornment__default["default"], { position: "start", children: jsxRuntime.jsx(Tooltip__default["default"], { title: localization.changeSearchMode, children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsxRuntime.jsx(SearchIcon, {}) }) }) })) : (jsxRuntime.jsx(SearchIcon, { style: { marginRight: '4px' } })) }, textFieldProps.InputProps), { sx: (theme) => {
2309
2296
  var _a;
2310
2297
  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)));
2311
- } }), 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, { inputRef: (inputRef) => {
2298
+ } }), inputRef: (inputRef) => {
2312
2299
  searchInputRef.current = inputRef;
2313
2300
  if (textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.inputRef) {
2314
2301
  textFieldProps.inputRef = inputRef;