material-react-table 2.13.2 → 3.0.0-beta.0
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/README.md +5 -5
- package/dist/index.d.ts +53 -15
- package/dist/index.esm.js +170 -57
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +170 -56
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/components/body/MRT_TableBodyCell.tsx +15 -1
- package/src/components/body/MRT_TableBodyRow.tsx +3 -2
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +5 -1
- package/src/components/footer/MRT_TableFooter.tsx +17 -2
- package/src/components/footer/MRT_TableFooterCell.tsx +14 -1
- package/src/components/head/MRT_TableHeadCell.tsx +11 -0
- package/src/components/menus/MRT_RowActionMenu.tsx +26 -16
- package/src/fns/filterFns.ts +43 -35
- package/src/hooks/useMRT_TableOptions.ts +2 -0
- package/src/types.ts +49 -18
- package/src/utils/cell.utils.ts +75 -0
- package/src/utils/style.utils.ts +5 -0
- package/src/utils/utils.ts +1 -1
package/src/types.ts
CHANGED
@@ -89,10 +89,6 @@ export type Xor<A, B> =
|
|
89
89
|
export type DropdownOption =
|
90
90
|
| {
|
91
91
|
label?: string;
|
92
|
-
/**
|
93
|
-
* @deprecated use `label` instead
|
94
|
-
*/
|
95
|
-
text?: string;
|
96
92
|
value: any;
|
97
93
|
}
|
98
94
|
| string;
|
@@ -138,13 +134,6 @@ export type MRT_RowVirtualizer<
|
|
138
134
|
virtualRows: MRT_VirtualItem[];
|
139
135
|
};
|
140
136
|
|
141
|
-
/**
|
142
|
-
* @deprecated use `MRT_ColumnVirtualizer` or `MRT_RowVirtualizer` instead
|
143
|
-
*/
|
144
|
-
export type MRT_Virtualizer<_TScrollElement = any, _TItemElement = any> =
|
145
|
-
| MRT_ColumnVirtualizer
|
146
|
-
| MRT_RowVirtualizer;
|
147
|
-
|
148
137
|
export type MRT_ColumnHelper<TData extends MRT_RowData> = {
|
149
138
|
accessor: <
|
150
139
|
TAccessor extends AccessorFn<TData> | DeepKeys<TData>,
|
@@ -257,6 +246,7 @@ export interface MRT_Localization {
|
|
257
246
|
|
258
247
|
export interface MRT_Theme {
|
259
248
|
baseBackgroundColor: string;
|
249
|
+
cellNavigationOutlineColor: string;
|
260
250
|
draggingBorderColor: string;
|
261
251
|
matchHighlightColor: string;
|
262
252
|
menuBackgroundColor: string;
|
@@ -281,6 +271,7 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
|
|
281
271
|
| 'getColumn'
|
282
272
|
| 'getExpandedRowModel'
|
283
273
|
| 'getFlatHeaders'
|
274
|
+
| 'getFooterGroups'
|
284
275
|
| 'getHeaderGroups'
|
285
276
|
| 'getLeafHeaders'
|
286
277
|
| 'getLeftLeafColumns'
|
@@ -303,6 +294,7 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
|
|
303
294
|
getColumn: (columnId: string) => MRT_Column<TData>;
|
304
295
|
getExpandedRowModel: () => MRT_RowModel<TData>;
|
305
296
|
getFlatHeaders: () => MRT_Header<TData>[];
|
297
|
+
getFooterGroups: () => MRT_HeaderGroup<TData>[];
|
306
298
|
getHeaderGroups: () => MRT_HeaderGroup<TData>[];
|
307
299
|
getLeafHeaders: () => MRT_Header<TData>[];
|
308
300
|
getLeftLeafColumns: () => MRT_Column<TData>[];
|
@@ -821,9 +813,7 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
821
813
|
columnFilterModeOptions?: Array<
|
822
814
|
LiteralUnion<string & MRT_FilterOption>
|
823
815
|
> | null;
|
824
|
-
columnVirtualizerInstanceRef?: MutableRefObject<
|
825
|
-
MRT_ColumnVirtualizer | MRT_Virtualizer | null
|
826
|
-
>;
|
816
|
+
columnVirtualizerInstanceRef?: MutableRefObject<MRT_ColumnVirtualizer | null>;
|
827
817
|
columnVirtualizerOptions?:
|
828
818
|
| ((props: {
|
829
819
|
table: MRT_TableInstance<TData>;
|
@@ -880,6 +870,7 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
880
870
|
enableFullScreenToggle?: boolean;
|
881
871
|
enableGlobalFilterModes?: boolean;
|
882
872
|
enableGlobalFilterRankedResults?: boolean;
|
873
|
+
enableCellNavigation?: boolean;
|
883
874
|
enablePagination?: boolean;
|
884
875
|
enableRowActions?: boolean;
|
885
876
|
enableRowDragging?: boolean;
|
@@ -931,18 +922,27 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
931
922
|
table: MRT_TableInstance<TData>;
|
932
923
|
}) => CircularProgressProps & { Component?: ReactNode })
|
933
924
|
| (CircularProgressProps & { Component?: ReactNode });
|
925
|
+
/**
|
926
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
927
|
+
*/
|
934
928
|
muiColumnActionsButtonProps?:
|
935
929
|
| ((props: {
|
936
930
|
column: MRT_Column<TData>;
|
937
931
|
table: MRT_TableInstance<TData>;
|
938
932
|
}) => IconButtonProps)
|
939
933
|
| IconButtonProps;
|
934
|
+
/**
|
935
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
936
|
+
*/
|
940
937
|
muiColumnDragHandleProps?:
|
941
938
|
| ((props: {
|
942
939
|
column: MRT_Column<TData>;
|
943
940
|
table: MRT_TableInstance<TData>;
|
944
941
|
}) => IconButtonProps)
|
945
942
|
| IconButtonProps;
|
943
|
+
/**
|
944
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
945
|
+
*/
|
946
946
|
muiCopyButtonProps?:
|
947
947
|
| ((props: {
|
948
948
|
cell: MRT_Cell<TData>;
|
@@ -969,6 +969,9 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
969
969
|
table: MRT_TableInstance<TData>;
|
970
970
|
}) => DialogProps)
|
971
971
|
| DialogProps;
|
972
|
+
/**
|
973
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
974
|
+
*/
|
972
975
|
muiEditTextFieldProps?:
|
973
976
|
| ((props: {
|
974
977
|
cell: MRT_Cell<TData>;
|
@@ -987,18 +990,27 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
987
990
|
table: MRT_TableInstance<TData>;
|
988
991
|
}) => IconButtonProps)
|
989
992
|
| IconButtonProps;
|
993
|
+
/**
|
994
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
995
|
+
*/
|
990
996
|
muiFilterAutocompleteProps?:
|
991
997
|
| ((props: {
|
992
998
|
column: MRT_Column<TData>;
|
993
999
|
table: MRT_TableInstance<TData>;
|
994
1000
|
}) => AutocompleteProps<any, any, any, any>)
|
995
1001
|
| AutocompleteProps<any, any, any, any>;
|
1002
|
+
/**
|
1003
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1004
|
+
*/
|
996
1005
|
muiFilterCheckboxProps?:
|
997
1006
|
| ((props: {
|
998
1007
|
column: MRT_Column<TData>;
|
999
1008
|
table: MRT_TableInstance<TData>;
|
1000
1009
|
}) => CheckboxProps)
|
1001
1010
|
| CheckboxProps;
|
1011
|
+
/**
|
1012
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1013
|
+
*/
|
1002
1014
|
muiFilterDatePickerProps?:
|
1003
1015
|
| ((props: {
|
1004
1016
|
column: MRT_Column<TData>;
|
@@ -1006,6 +1018,9 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1006
1018
|
table: MRT_TableInstance<TData>;
|
1007
1019
|
}) => DatePickerProps<never>)
|
1008
1020
|
| DatePickerProps<never>;
|
1021
|
+
/**
|
1022
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1023
|
+
*/
|
1009
1024
|
muiFilterDateTimePickerProps?:
|
1010
1025
|
| ((props: {
|
1011
1026
|
column: MRT_Column<TData>;
|
@@ -1013,12 +1028,18 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1013
1028
|
table: MRT_TableInstance<TData>;
|
1014
1029
|
}) => DateTimePickerProps<never>)
|
1015
1030
|
| DateTimePickerProps<never>;
|
1031
|
+
/**
|
1032
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1033
|
+
*/
|
1016
1034
|
muiFilterSliderProps?:
|
1017
1035
|
| ((props: {
|
1018
1036
|
column: MRT_Column<TData>;
|
1019
1037
|
table: MRT_TableInstance<TData>;
|
1020
1038
|
}) => SliderProps)
|
1021
1039
|
| SliderProps;
|
1040
|
+
/**
|
1041
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1042
|
+
*/
|
1022
1043
|
muiFilterTextFieldProps?:
|
1023
1044
|
| ((props: {
|
1024
1045
|
column: MRT_Column<TData>;
|
@@ -1026,6 +1047,9 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1026
1047
|
table: MRT_TableInstance<TData>;
|
1027
1048
|
}) => TextFieldProps)
|
1028
1049
|
| TextFieldProps;
|
1050
|
+
/**
|
1051
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1052
|
+
*/
|
1029
1053
|
muiFilterTimePickerProps?:
|
1030
1054
|
| ((props: {
|
1031
1055
|
column: MRT_Column<TData>;
|
@@ -1075,6 +1099,9 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1075
1099
|
table: MRT_TableInstance<TData>;
|
1076
1100
|
}) => CheckboxProps | RadioProps)
|
1077
1101
|
| (CheckboxProps | RadioProps);
|
1102
|
+
/**
|
1103
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1104
|
+
*/
|
1078
1105
|
muiSkeletonProps?:
|
1079
1106
|
| ((props: {
|
1080
1107
|
cell: MRT_Cell<TData>;
|
@@ -1083,6 +1110,9 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1083
1110
|
table: MRT_TableInstance<TData>;
|
1084
1111
|
}) => SkeletonProps)
|
1085
1112
|
| SkeletonProps;
|
1113
|
+
/**
|
1114
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1115
|
+
*/
|
1086
1116
|
muiTableBodyCellProps?:
|
1087
1117
|
| ((props: {
|
1088
1118
|
cell: MRT_Cell<TData>;
|
@@ -1120,6 +1150,9 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1120
1150
|
table: MRT_TableInstance<TData>;
|
1121
1151
|
}) => TableRowProps)
|
1122
1152
|
| TableRowProps;
|
1153
|
+
/**
|
1154
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1155
|
+
*/
|
1123
1156
|
muiTableHeadCellProps?:
|
1124
1157
|
| ((props: {
|
1125
1158
|
column: MRT_Column<TData>;
|
@@ -1252,7 +1285,7 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1252
1285
|
row: MRT_Row<TData>;
|
1253
1286
|
staticRowIndex?: number;
|
1254
1287
|
table: MRT_TableInstance<TData>;
|
1255
|
-
}) => ReactNode[];
|
1288
|
+
}) => ReactNode[] | undefined;
|
1256
1289
|
renderRowActions?: (props: {
|
1257
1290
|
cell: MRT_Cell<TData>;
|
1258
1291
|
row: MRT_Row<TData>;
|
@@ -1282,9 +1315,7 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1282
1315
|
| 'sticky'
|
1283
1316
|
| 'top'
|
1284
1317
|
| 'top-and-bottom';
|
1285
|
-
rowVirtualizerInstanceRef?: MutableRefObject<
|
1286
|
-
MRT_RowVirtualizer | MRT_Virtualizer | null
|
1287
|
-
>;
|
1318
|
+
rowVirtualizerInstanceRef?: MutableRefObject<MRT_RowVirtualizer | null>;
|
1288
1319
|
rowVirtualizerOptions?:
|
1289
1320
|
| ((props: {
|
1290
1321
|
table: MRT_TableInstance<TData>;
|
package/src/utils/cell.utils.ts
CHANGED
@@ -48,3 +48,78 @@ export const openEditingCell = <TData extends MRT_RowData>({
|
|
48
48
|
});
|
49
49
|
}
|
50
50
|
};
|
51
|
+
|
52
|
+
export const cellNavigation = (
|
53
|
+
e: React.KeyboardEvent<HTMLTableCellElement>,
|
54
|
+
) => {
|
55
|
+
if (
|
56
|
+
['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(
|
57
|
+
e.key,
|
58
|
+
)
|
59
|
+
) {
|
60
|
+
e.preventDefault();
|
61
|
+
const currentCell = e.currentTarget;
|
62
|
+
const currentRow = currentCell.closest('tr');
|
63
|
+
|
64
|
+
const tableElement = currentCell.closest('table');
|
65
|
+
const allCells = Array.from(tableElement?.querySelectorAll('th, td') || []);
|
66
|
+
const currentCellIndex = allCells.indexOf(currentCell);
|
67
|
+
|
68
|
+
const currentIndex = parseInt(
|
69
|
+
currentCell.getAttribute('data-index') || '0',
|
70
|
+
);
|
71
|
+
let nextCell: HTMLElement | undefined = undefined;
|
72
|
+
|
73
|
+
//home/end first or last cell in row
|
74
|
+
const findEdgeCell = (rowIndex: 'c' | 'f' | 'l', edge: 'f' | 'l') => {
|
75
|
+
const row =
|
76
|
+
rowIndex === 'c'
|
77
|
+
? currentRow
|
78
|
+
: rowIndex === 'f'
|
79
|
+
? currentCell.closest('table')?.querySelector('tr')
|
80
|
+
: currentCell.closest('table')?.lastElementChild?.lastElementChild;
|
81
|
+
const rowCells = Array.from(row?.children || []);
|
82
|
+
const targetCell =
|
83
|
+
edge === 'f' ? rowCells[0] : rowCells[rowCells.length - 1];
|
84
|
+
return targetCell as HTMLElement;
|
85
|
+
};
|
86
|
+
|
87
|
+
const findAdjacentCell = (
|
88
|
+
columnIndex: number,
|
89
|
+
searchDirection: 'f' | 'b',
|
90
|
+
) => {
|
91
|
+
const searchArray =
|
92
|
+
searchDirection === 'f'
|
93
|
+
? allCells.slice(currentCellIndex + 1)
|
94
|
+
: allCells.slice(0, currentCellIndex).reverse();
|
95
|
+
return searchArray.find((cell) =>
|
96
|
+
cell.matches(`[data-index="${columnIndex}"]`),
|
97
|
+
) as HTMLElement | undefined;
|
98
|
+
};
|
99
|
+
|
100
|
+
switch (e.key) {
|
101
|
+
case 'ArrowRight':
|
102
|
+
nextCell = findAdjacentCell(currentIndex + 1, 'f');
|
103
|
+
break;
|
104
|
+
case 'ArrowLeft':
|
105
|
+
nextCell = findAdjacentCell(currentIndex - 1, 'b');
|
106
|
+
break;
|
107
|
+
case 'ArrowUp':
|
108
|
+
nextCell = findAdjacentCell(currentIndex, 'b');
|
109
|
+
break;
|
110
|
+
case 'ArrowDown':
|
111
|
+
nextCell = findAdjacentCell(currentIndex, 'f');
|
112
|
+
break;
|
113
|
+
case 'Home':
|
114
|
+
nextCell = findEdgeCell(e.ctrlKey ? 'f' : 'c', 'f');
|
115
|
+
break;
|
116
|
+
case 'End':
|
117
|
+
nextCell = findEdgeCell(e.ctrlKey ? 'l' : 'c', 'l');
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
|
121
|
+
if (nextCell) {
|
122
|
+
nextCell.focus();
|
123
|
+
}
|
124
|
+
}
|
125
|
+
};
|
package/src/utils/style.utils.ts
CHANGED
@@ -27,6 +27,7 @@ export const getMRTTheme = <TData extends MRT_RowData>(
|
|
27
27
|
: muiTheme.palette.background.default);
|
28
28
|
return {
|
29
29
|
baseBackgroundColor,
|
30
|
+
cellNavigationOutlineColor: muiTheme.palette.primary.main,
|
30
31
|
draggingBorderColor: muiTheme.palette.primary.main,
|
31
32
|
matchHighlightColor:
|
32
33
|
muiTheme.palette.mode === 'dark'
|
@@ -170,6 +171,10 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
|
|
170
171
|
: columnDefType !== 'group' && isColumnPinned
|
171
172
|
? 1
|
172
173
|
: 0,
|
174
|
+
'&:focus-visible': {
|
175
|
+
outline: `2px solid ${table.options.mrtTheme.cellNavigationOutlineColor}`,
|
176
|
+
outlineOffset: '-2px',
|
177
|
+
},
|
173
178
|
...pinnedStyles,
|
174
179
|
...widthStyles,
|
175
180
|
...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
|