material-react-table 0.7.2 → 0.7.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.
@@ -7,5 +7,5 @@ interface Props {
7
7
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
8
8
  tableInstance: MRT_TableInstance;
9
9
  }
10
- export declare const MRT_FilterTypeMenu: FC<Props>;
10
+ export declare const MRT_FilterOptionMenu: FC<Props>;
11
11
  export {};
package/dist/utils.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ColumnDef, Table } from '@tanstack/react-table';
2
- import { MRT_ColumnDef, MRT_FilterType } from '.';
2
+ import { MRT_ColumnDef, MRT_FilterFn } from '.';
3
3
  export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
4
- export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterTypes: {
5
- [key: string]: MRT_FilterType;
4
+ export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
5
+ [key: string]: MRT_FilterFn<{}>;
6
6
  }) => ColumnDef<D>;
7
- export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterTypes: {
8
- [key: string]: MRT_FilterType;
7
+ export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
8
+ [key: string]: MRT_FilterFn<{}>;
9
9
  }) => ColumnDef<D>;
10
- export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "filterFn" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterTypes" | "filter" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
10
+ export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.2",
2
+ "version": "0.7.5",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "scripts": {
30
30
  "analyze": "size-limit --why",
31
- "build": "tsdx build && size-limit && rm -rf material-react-table-docs/node_modules/material-react-table/dist && cp -r dist material-react-table-docs/node_modules/material-react-table/ && cp -r src material-react-table-docs/node_modules/material-react-table/ && cp -r package.json material-react-table-docs/node_modules/material-react-table/package.json",
31
+ "build": "tsdx build && size-limit && rm -rf material-react-table-docs/node_modules/material-react-table/dist && cp -r dist material-react-table-docs/node_modules/material-react-table/ && cp -r src material-react-table-docs/node_modules/material-react-table/ && cp -r package.json material-react-table-docs/node_modules/material-react-table/package.json",
32
32
  "build-storybook": "build-storybook",
33
33
  "format": "prettier -w .",
34
34
  "lint": "eslint .",
@@ -59,7 +59,7 @@
59
59
  "@emotion/react": "^11.9.0",
60
60
  "@emotion/styled": "^11.8.1",
61
61
  "@etchteam/storybook-addon-status": "^4.2.1",
62
- "@faker-js/faker": "^6.1.2",
62
+ "@faker-js/faker": "^6.2.0",
63
63
  "@mui/icons-material": "^5.6.2",
64
64
  "@mui/material": "^5.6.2",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
@@ -75,7 +75,7 @@
75
75
  "@types/react": "^17.0.41",
76
76
  "@types/react-dom": "^17.0.14",
77
77
  "babel-loader": "^8.2.5",
78
- "eslint": "^8.13.0",
78
+ "eslint": "^8.14.0",
79
79
  "eslint-plugin-react-hooks": "^4.4.0",
80
80
  "husky": "^7.0.4",
81
81
  "prettier": "^2.6.2",
@@ -86,7 +86,7 @@
86
86
  "storybook-addon-paddings": "^4.3.0",
87
87
  "storybook-dark-mode": "^1.0.9",
88
88
  "tsdx": "^0.14.1",
89
- "tslib": "^2.3.1",
89
+ "tslib": "^2.4.0",
90
90
  "typescript": "^4.6.3"
91
91
  },
92
92
  "peerDependencies": {
@@ -97,7 +97,7 @@
97
97
  "react": ">=16.8"
98
98
  },
99
99
  "dependencies": {
100
- "@tanstack/react-table": "^8.0.0-alpha.45",
100
+ "@tanstack/react-table": "^8.0.0-alpha.47",
101
101
  "match-sorter": "^6.3.1"
102
102
  }
103
103
  }
@@ -31,7 +31,8 @@ import {
31
31
  Column,
32
32
  ColumnDef,
33
33
  DefaultGenerics,
34
- FilterType,
34
+ FilterFn,
35
+ FilterFnOption,
35
36
  Header,
36
37
  HeaderGroup,
37
38
  Options,
@@ -44,20 +45,21 @@ import {
44
45
  } from '@tanstack/react-table';
45
46
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
46
47
  import { MRT_Default_Icons, MRT_Icons } from './icons';
47
- import { MRT_FILTER_TYPE } from './enums';
48
+ import { MRT_FILTER_OPTION } from './enums';
48
49
  import { MRT_TableRoot } from './table/MRT_TableRoot';
49
50
 
50
51
  export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
51
52
  Omit<
52
53
  Options<D>,
53
- 'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
54
+ 'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn' | 'filterFns'
54
55
  >
55
56
  > & {
56
57
  columns: MRT_ColumnDef<D>[];
57
58
  data: D[];
59
+ expandRowsFn?: (dataRow: D) => D[];
60
+ filterFns?: MRT_FILTER_OPTION | FilterFn<D> | string | number | symbol;
58
61
  initialState?: Partial<MRT_TableState<D>>;
59
62
  state?: Partial<MRT_TableState<D>>;
60
- expandRowsFn?: (dataRow: D) => D[];
61
63
  };
62
64
 
63
65
  export interface MRT_RowModel<D extends Record<string, any> = {}> {
@@ -96,16 +98,16 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
96
98
  options: MaterialReactTableProps<D> & {
97
99
  icons: MRT_Icons;
98
100
  idPrefix: string;
99
- filterTypes: { [key in MRT_FILTER_TYPE]: any };
100
101
  localization: MRT_Localization;
101
102
  };
103
+ setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell<D> | null>>;
102
104
  setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
103
- setCurrentFilterTypes: Dispatch<
105
+ setCurrentFilterFns: Dispatch<
104
106
  SetStateAction<{
105
- [key: string]: MRT_FilterType;
107
+ [key: string]: MRT_FilterFn<D>;
106
108
  }>
107
109
  >;
108
- setCurrentGlobalFilterType: Dispatch<SetStateAction<MRT_FILTER_TYPE>>;
110
+ setCurrentGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterFn<D>>>;
109
111
  setIsDensePadding: Dispatch<SetStateAction<boolean>>;
110
112
  setIsFullScreen: Dispatch<SetStateAction<boolean>>;
111
113
  setShowFilters: Dispatch<SetStateAction<boolean>>;
@@ -116,9 +118,10 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
116
118
  TableState,
117
119
  'pagination'
118
120
  > & {
121
+ currentEditingCell: MRT_Cell<D> | null;
119
122
  currentEditingRow: MRT_Row<D> | null;
120
- currentFilterTypes: Record<string, string | Function>;
121
- currentGlobalFilterType: Record<string, string | Function>;
123
+ currentFilterFns: Record<string, string | Function>;
124
+ currentGlobalFilterFn: Record<string, string | Function>;
122
125
  isDensePadding: boolean;
123
126
  isFullScreen: boolean;
124
127
  showFilters: boolean;
@@ -128,23 +131,19 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
128
131
 
129
132
  export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
130
133
  ColumnDef<D>,
131
- 'header' | 'footer' | 'columns'
134
+ 'header' | 'footer' | 'columns' | 'filterFn'
132
135
  > & {
133
136
  Edit?: ({
134
137
  cell,
135
138
  tableInstance,
136
- }: // onChange,
137
- {
139
+ }: {
138
140
  cell: MRT_Cell<D>;
139
141
  tableInstance: MRT_TableInstance<D>;
140
- // onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
141
142
  }) => ReactNode;
142
143
  Filter?: ({
143
- // onChange,
144
144
  header,
145
145
  tableInstance,
146
146
  }: {
147
- // onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
148
147
  header: MRT_Header<D>;
149
148
  tableInstance: MRT_TableInstance<D>;
150
149
  }) => ReactNode;
@@ -174,8 +173,8 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
174
173
  enableClickToCopy?: boolean;
175
174
  enableColumnActions?: boolean;
176
175
  enableEditing?: boolean;
177
- enabledColumnFilterTypes?: (MRT_FILTER_TYPE | string)[];
178
- filter?: MRT_FilterType | string | FilterType<D>;
176
+ enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
177
+ filterFn?: MRT_FilterFn;
179
178
  filterSelectOptions?: (string | { text: string; value: string })[];
180
179
  footer?: string;
181
180
  header: string;
@@ -261,9 +260,11 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
261
260
  tableInstance: MRT_TableInstance<D>;
262
261
  }) => void;
263
262
  onColumnFilterValueChange?: ({
263
+ column,
264
264
  event,
265
265
  filterValue,
266
266
  }: {
267
+ column: MRT_Column<D>;
267
268
  event: ChangeEvent<HTMLInputElement>;
268
269
  filterValue: any;
269
270
  }) => void;
@@ -318,10 +319,17 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
318
319
  row: MRT_Row<D>;
319
320
  };
320
321
 
321
- export type MRT_FilterType = MRT_FILTER_TYPE | Function;
322
+ export type MRT_FilterFn<D extends Record<string, any> = {}> =
323
+ | FilterFn<D>
324
+ | FilterFnOption<D>
325
+ | MRT_FILTER_OPTION
326
+ | number
327
+ | string
328
+ | symbol;
322
329
 
323
330
  export type MaterialReactTableProps<D extends Record<string, any> = {}> =
324
331
  MRT_TableOptions<D> & {
332
+ editingMode?: 'table' | 'row' | 'cell';
325
333
  enableClickToCopy?: boolean;
326
334
  enableColumnActions?: boolean;
327
335
  enableDensePaddingToggle?: boolean;
@@ -329,6 +337,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
329
337
  enableExpandAll?: boolean;
330
338
  enableFullScreenToggle?: boolean;
331
339
  enablePagination?: boolean;
340
+ enablePersistentState?: boolean;
332
341
  enableRowActions?: boolean;
333
342
  enableRowNumbers?: boolean;
334
343
  enableSelectAll?: boolean;
@@ -338,8 +347,8 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
338
347
  enableToolbarBottom?: boolean;
339
348
  enableToolbarInternalActions?: boolean;
340
349
  enableToolbarTop?: boolean;
341
- enabledGlobalFilterTypes?: (MRT_FILTER_TYPE | string)[];
342
- filterTypes?: { [key in MRT_FILTER_TYPE]: any };
350
+ enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
351
+ enabledGlobalFilterOptions?: (MRT_FILTER_OPTION | string)[];
343
352
  icons?: Partial<MRT_Icons>;
344
353
  idPrefix?: string;
345
354
  isLoading?: boolean;
@@ -557,6 +566,33 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
557
566
  tableInstance: MRT_TableInstance<D>;
558
567
  event: MouseEvent<HTMLTableCellElement>;
559
568
  }) => void;
569
+ onCellEditBlur?: ({
570
+ cell,
571
+ event,
572
+ tableInstance,
573
+ }: {
574
+ event: FocusEvent<HTMLInputElement>;
575
+ cell: MRT_Cell<D>;
576
+ tableInstance: MRT_TableInstance<D>;
577
+ }) => void;
578
+ onCellEditChange?: ({
579
+ cell,
580
+ event,
581
+ tableInstance,
582
+ }: {
583
+ event: ChangeEvent<HTMLInputElement>;
584
+ cell: MRT_Cell<D>;
585
+ tableInstance: MRT_TableInstance<D>;
586
+ }) => void;
587
+ onColumnFilterValueChange?: ({
588
+ column,
589
+ event,
590
+ filterValue,
591
+ }: {
592
+ column: MRT_Column<D>;
593
+ event: ChangeEvent<HTMLInputElement>;
594
+ filterValue: any;
595
+ }) => void;
560
596
  onDetailPanelClick?: ({
561
597
  event,
562
598
  row,
@@ -662,6 +698,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
662
698
  showGlobalFilter: boolean;
663
699
  tableInstance: MRT_TableInstance<D>;
664
700
  }) => void;
701
+ persistentStateMode?: 'localStorage' | 'sessionStorage';
665
702
  positionActionsColumn?: 'first' | 'last';
666
703
  positionPagination?: 'bottom' | 'top' | 'both';
667
704
  positionToolbarActions?: 'bottom' | 'top';
@@ -723,7 +760,9 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
723
760
 
724
761
  export default <D extends Record<string, any> = {}>({
725
762
  autoResetExpanded = false,
763
+ autoResetSorting = false,
726
764
  columnResizeMode = 'onEnd',
765
+ editingMode = 'row',
727
766
  enableColumnActions = true,
728
767
  enableColumnFilters = true,
729
768
  enableColumnResizing = false,
@@ -745,6 +784,7 @@ export default <D extends Record<string, any> = {}>({
745
784
  enableToolbarTop = true,
746
785
  icons,
747
786
  localization,
787
+ persistentStateMode = 'sessionStorage',
748
788
  positionActionsColumn = 'first',
749
789
  positionPagination = 'bottom',
750
790
  positionToolbarActions = 'top',
@@ -753,7 +793,9 @@ export default <D extends Record<string, any> = {}>({
753
793
  }: MaterialReactTableProps<D>) => (
754
794
  <MRT_TableRoot
755
795
  autoResetExpanded={autoResetExpanded}
796
+ autoResetSorting={autoResetSorting}
756
797
  columnResizeMode={columnResizeMode}
798
+ editingMode={editingMode}
757
799
  enableColumnActions={enableColumnActions}
758
800
  enableColumnResizing={enableColumnResizing}
759
801
  enableColumnFilters={enableColumnFilters}
@@ -775,6 +817,7 @@ export default <D extends Record<string, any> = {}>({
775
817
  enableToolbarTop={enableToolbarTop}
776
818
  icons={{ ...MRT_Default_Icons, ...icons }}
777
819
  localization={{ ...MRT_DefaultLocalization_EN, ...localization }}
820
+ persistentStateMode={persistentStateMode}
778
821
  positionActionsColumn={positionActionsColumn}
779
822
  positionPagination={positionPagination}
780
823
  positionToolbarActions={positionToolbarActions}
@@ -14,17 +14,20 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
14
14
  getIsSomeColumnsPinned,
15
15
  getState,
16
16
  options: {
17
+ editingMode,
17
18
  enableClickToCopy,
18
- enablePinning,
19
19
  enableEditing,
20
+ enablePinning,
21
+ idPrefix,
20
22
  isLoading,
21
23
  muiTableBodyCellProps,
22
24
  muiTableBodyCellSkeletonProps,
23
25
  onCellClick,
24
26
  },
27
+ setCurrentEditingCell,
25
28
  } = tableInstance;
26
29
 
27
- const { currentEditingRow, isDensePadding } = getState();
30
+ const { currentEditingCell, currentEditingRow, isDensePadding } = getState();
28
31
 
29
32
  const { column, row } = cell;
30
33
 
@@ -53,13 +56,43 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
53
56
  [column.columnDefType, column.getWidth()],
54
57
  );
55
58
 
59
+ const isEditable =
60
+ (enableEditing || column.enableEditing) && column.enableEditing !== false;
61
+
62
+ const isEditing =
63
+ isEditable &&
64
+ (editingMode === 'table' ||
65
+ currentEditingRow?.id === row.id ||
66
+ currentEditingCell?.id === cell.id);
67
+
68
+ const handleDoubleClick = (_event: MouseEvent<HTMLTableCellElement>) => {
69
+ if (
70
+ (enableEditing || column.enableEditing) &&
71
+ column.enableEditing !== false &&
72
+ editingMode === 'cell'
73
+ ) {
74
+ setCurrentEditingCell(cell);
75
+ setTimeout(() => {
76
+ const textField = document.getElementById(
77
+ `mrt-${idPrefix}-edit-cell-text-field-${cell.id}`,
78
+ ) as HTMLInputElement;
79
+ if (textField) {
80
+ textField.focus();
81
+ textField.select();
82
+ }
83
+ }, 200);
84
+ }
85
+ };
86
+
56
87
  return (
57
88
  <TableCell
58
89
  onClick={(event: MouseEvent<HTMLTableCellElement>) =>
59
90
  onCellClick?.({ event, cell, tableInstance })
60
91
  }
92
+ onDoubleClick={handleDoubleClick}
61
93
  {...tableCellProps}
62
94
  sx={{
95
+ cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
63
96
  maxWidth: `min(${column.getWidth()}px, fit-content)`,
64
97
  minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
65
98
  p: isDensePadding
@@ -97,9 +130,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
97
130
  column.id !==
98
131
  row.groupingColumnId) ? null : cell.getIsAggregated() ? (
99
132
  cell.renderAggregatedCell()
100
- ) : enableEditing &&
101
- column.enableEditing !== false &&
102
- currentEditingRow?.id === row.id ? (
133
+ ) : isEditing ? (
103
134
  <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
104
135
  ) : (enableClickToCopy || column.enableClickToCopy) &&
105
136
  column.enableClickToCopy !== false ? (
@@ -56,6 +56,7 @@ export const MRT_CopyButton: FC<Props> = ({
56
56
  backgroundColor: 'transparent',
57
57
  border: 'none',
58
58
  color: 'inherit',
59
+ cursor: 'copy',
59
60
  fontFamily: 'inherit',
60
61
  fontSize: 'inherit',
61
62
  letterSpacing: 'inherit',
package/src/enums.ts CHANGED
@@ -1,4 +1,4 @@
1
- export enum MRT_FILTER_TYPE {
1
+ export enum MRT_FILTER_OPTION {
2
2
  BEST_MATCH = 'bestMatch',
3
3
  BEST_MATCH_FIRST = 'bestMatchFirst',
4
4
  CONTAINS = 'contains',
@@ -60,20 +60,18 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
60
60
  : localization.sortedByColumnAsc.replace('{column}', column.header)
61
61
  : localization.unsorted;
62
62
 
63
- const filterType = getState()?.currentFilterTypes?.[header.id];
63
+ const filterFn = getState()?.currentFilterFns?.[header.id];
64
64
 
65
65
  const filterTooltip = !!column.getColumnFilterValue()
66
66
  ? localization.filteringByColumn
67
67
  .replace('{column}', String(column.header))
68
68
  .replace(
69
69
  '{filterType}',
70
- filterType instanceof Function
70
+ filterFn instanceof Function
71
71
  ? ''
72
72
  : // @ts-ignore
73
73
  localization[
74
- `filter${
75
- filterType.charAt(0).toUpperCase() + filterType.slice(1)
76
- }`
74
+ `filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
77
75
  ],
78
76
  )
79
77
  .replace('{filterValue}', column.getColumnFilterValue() as string)
@@ -16,7 +16,14 @@ interface Props {
16
16
  export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
17
17
  const {
18
18
  getState,
19
- options: { enableEditing, muiTableBodyCellEditTextFieldProps },
19
+ options: {
20
+ idPrefix,
21
+ enableEditing,
22
+ muiTableBodyCellEditTextFieldProps,
23
+ onCellEditBlur,
24
+ onCellEditChange,
25
+ },
26
+ setCurrentEditingCell,
20
27
  setCurrentEditingRow,
21
28
  } = tableInstance;
22
29
 
@@ -27,6 +34,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
27
34
  const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
28
35
  setValue(event.target.value);
29
36
  column.onCellEditChange?.({ event, cell, tableInstance });
37
+ onCellEditChange?.({ event, cell, tableInstance });
30
38
  };
31
39
 
32
40
  const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
@@ -34,7 +42,9 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
34
42
  row.values[column.id] = value;
35
43
  setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
36
44
  }
45
+ setCurrentEditingCell(null);
37
46
  column.onCellEditBlur?.({ event, cell, tableInstance });
47
+ onCellEditBlur?.({ event, cell, tableInstance });
38
48
  };
39
49
 
40
50
  const mTableBodyCellEditTextFieldProps =
@@ -58,6 +68,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
58
68
 
59
69
  return (
60
70
  <TextField
71
+ id={`mrt-${idPrefix}-edit-cell-text-field-${cell.id}`}
61
72
  margin="dense"
62
73
  onBlur={handleBlur}
63
74
  onChange={handleChange}
@@ -16,8 +16,8 @@ import {
16
16
  Tooltip,
17
17
  } from '@mui/material';
18
18
  import type { MRT_Header, MRT_TableInstance } from '..';
19
- import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
20
- import { MRT_FILTER_TYPE } from '../enums';
19
+ import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
20
+ import { MRT_FILTER_OPTION } from '../enums';
21
21
 
22
22
  interface Props {
23
23
  header: MRT_Header;
@@ -33,12 +33,12 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
33
33
  localization,
34
34
  muiTableHeadCellFilterTextFieldProps,
35
35
  },
36
- setCurrentFilterTypes,
36
+ setCurrentFilterFns,
37
37
  } = tableInstance;
38
38
 
39
39
  const { column } = header;
40
40
 
41
- const { currentFilterTypes } = getState();
41
+ const { currentFilterFns } = getState();
42
42
 
43
43
  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
44
44
 
@@ -82,9 +82,9 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
82
82
  const handleClearFilterChip = () => {
83
83
  setFilterValue('');
84
84
  column.setColumnFilterValue(undefined);
85
- setCurrentFilterTypes((prev) => ({
85
+ setCurrentFilterFns((prev) => ({
86
86
  ...prev,
87
- [header.id]: MRT_FILTER_TYPE.BEST_MATCH,
87
+ [header.id]: MRT_FILTER_OPTION.BEST_MATCH,
88
88
  }));
89
89
  };
90
90
 
@@ -93,16 +93,16 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
93
93
  }
94
94
 
95
95
  const filterId = `mrt-${idPrefix}-${header.id}-filter-text-field`;
96
- const filterType = currentFilterTypes?.[header.id];
96
+ const filterFn = currentFilterFns?.[header.id];
97
97
  const isSelectFilter = !!column.filterSelectOptions;
98
98
  const filterChipLabel =
99
- !(filterType instanceof Function) &&
100
- [MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(
101
- filterType as MRT_FILTER_TYPE,
99
+ !(filterFn instanceof Function) &&
100
+ [MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(
101
+ filterFn as MRT_FILTER_OPTION,
102
102
  )
103
103
  ? //@ts-ignore
104
104
  localization[
105
- `filter${filterType.charAt(0).toUpperCase() + filterType.slice(1)}`
105
+ `filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
106
106
  ]
107
107
  : '';
108
108
  const filterPlaceholder = localization.filterByColumn?.replace(
@@ -125,14 +125,14 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
125
125
  }}
126
126
  helperText={
127
127
  <label htmlFor={filterId}>
128
- {filterType instanceof Function
128
+ {filterFn instanceof Function
129
129
  ? localization.filterMode.replace(
130
130
  '{filterType}',
131
131
  // @ts-ignore
132
132
  localization[
133
133
  `filter${
134
- filterType.name.charAt(0).toUpperCase() +
135
- filterType.name.slice(1)
134
+ filterFn.name.charAt(0).toUpperCase() +
135
+ filterFn.name.slice(1)
136
136
  }`
137
137
  ] ?? '',
138
138
  ) ?? ''
@@ -141,7 +141,7 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
141
141
  // @ts-ignore
142
142
  localization[
143
143
  `filter${
144
- filterType.charAt(0).toUpperCase() + filterType.slice(1)
144
+ filterFn.charAt(0).toUpperCase() + filterFn.slice(1)
145
145
  }`
146
146
  ],
147
147
  )}
@@ -248,7 +248,7 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
248
248
  );
249
249
  })}
250
250
  </TextField>
251
- <MRT_FilterTypeMenu
251
+ <MRT_FilterOptionMenu
252
252
  anchorEl={anchorEl}
253
253
  header={header}
254
254
  setAnchorEl={setAnchorEl}
@@ -13,7 +13,7 @@ import {
13
13
  TextField,
14
14
  Tooltip,
15
15
  } from '@mui/material';
16
- import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
16
+ import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
17
17
  import { MRT_TableInstance } from '..';
18
18
 
19
19
  interface Props {
@@ -105,7 +105,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
105
105
  {...textFieldProps}
106
106
  sx={{ justifySelf: 'end', ...textFieldProps?.sx }}
107
107
  />
108
- <MRT_FilterTypeMenu
108
+ <MRT_FilterOptionMenu
109
109
  anchorEl={anchorEl}
110
110
  setAnchorEl={setAnchorEl}
111
111
  tableInstance={tableInstance}
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useState } from 'react';
2
2
  import { Box, IconButton, ListItemIcon, Menu, MenuItem } from '@mui/material';
3
3
  import type { MRT_Header, MRT_TableInstance } from '..';
4
- import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
4
+ import { MRT_FilterOptionMenu } from './MRT_FilterOptionMenu';
5
5
  import { MRT_ShowHideColumnsMenu } from './MRT_ShowHideColumnsMenu';
6
6
 
7
7
  export const commonMenuItemStyles = {
@@ -240,7 +240,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
240
240
  </IconButton>
241
241
  )}
242
242
  </MenuItem>,
243
- <MRT_FilterTypeMenu
243
+ <MRT_FilterOptionMenu
244
244
  anchorEl={filterMenuAnchorEl}
245
245
  header={header}
246
246
  key={2}