material-react-table 3.0.0-beta.0 → 3.0.0-beta.1
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 +19 -4
- package/dist/index.esm.js +224 -166
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +224 -166
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/components/body/MRT_TableBodyCell.tsx +8 -3
- package/src/components/footer/MRT_TableFooterCell.tsx +7 -3
- package/src/components/head/MRT_TableHeadCell.tsx +8 -3
- package/src/components/inputs/MRT_FilterTextField.tsx +4 -0
- package/src/components/menus/MRT_ActionMenuItem.tsx +1 -0
- package/src/types.ts +9 -3
- package/src/utils/cell.utils.ts +77 -15
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"version": "3.0.0-beta.
|
2
|
+
"version": "3.0.0-beta.1",
|
3
3
|
"license": "MIT",
|
4
4
|
"name": "material-react-table",
|
5
5
|
"description": "A fully featured Material UI V6 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
|
@@ -35,11 +35,11 @@
|
|
35
35
|
"size-limit": [
|
36
36
|
{
|
37
37
|
"path": "dist/index.js",
|
38
|
-
"limit": "
|
38
|
+
"limit": "55 KB"
|
39
39
|
},
|
40
40
|
{
|
41
41
|
"path": "dist/index.esm.js",
|
42
|
-
"limit": "
|
42
|
+
"limit": "51 KB"
|
43
43
|
}
|
44
44
|
],
|
45
45
|
"engines": {
|
@@ -78,11 +78,11 @@
|
|
78
78
|
"@storybook/preview-api": "^8.2.9",
|
79
79
|
"@storybook/react": "^8.2.9",
|
80
80
|
"@storybook/react-vite": "^8.2.9",
|
81
|
-
"@types/node": "^22.5.
|
81
|
+
"@types/node": "^22.5.2",
|
82
82
|
"@types/react": "^18.3.5",
|
83
83
|
"@types/react-dom": "^18.3.0",
|
84
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
85
|
-
"@typescript-eslint/parser": "^8.
|
84
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
85
|
+
"@typescript-eslint/parser": "^8.4.0",
|
86
86
|
"@vitejs/plugin-react": "^4.3.1",
|
87
87
|
"eslint": "^9.9.1",
|
88
88
|
"eslint-plugin-mui-path-imports": "^0.0.15",
|
@@ -232,11 +232,16 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
|
|
232
232
|
}
|
233
233
|
};
|
234
234
|
|
235
|
-
const handleKeyDown = (
|
235
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLTableCellElement>) => {
|
236
236
|
if (enableCellNavigation) {
|
237
|
-
cellNavigation(
|
237
|
+
cellNavigation({
|
238
|
+
cell,
|
239
|
+
cellValue: cell.getValue<string>(),
|
240
|
+
event,
|
241
|
+
table,
|
242
|
+
});
|
238
243
|
}
|
239
|
-
tableCellProps?.onKeyDown?.(
|
244
|
+
tableCellProps?.onKeyDown?.(event);
|
240
245
|
};
|
241
246
|
|
242
247
|
return (
|
@@ -48,11 +48,15 @@ export const MRT_TableFooterCell = <TData extends MRT_RowData>({
|
|
48
48
|
...rest,
|
49
49
|
};
|
50
50
|
|
51
|
-
const handleKeyDown = (
|
51
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLTableCellElement>) => {
|
52
52
|
if (enableCellNavigation) {
|
53
|
-
cellNavigation(
|
53
|
+
cellNavigation({
|
54
|
+
event,
|
55
|
+
cellValue: footer.column.columnDef.footer,
|
56
|
+
table,
|
57
|
+
});
|
54
58
|
}
|
55
|
-
tableCellProps?.onKeyDown?.(
|
59
|
+
tableCellProps?.onKeyDown?.(event);
|
56
60
|
};
|
57
61
|
|
58
62
|
return (
|
@@ -149,11 +149,16 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
|
|
149
149
|
}
|
150
150
|
};
|
151
151
|
|
152
|
-
const handleKeyDown = (
|
152
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLTableCellElement>) => {
|
153
153
|
if (enableCellNavigation) {
|
154
|
-
cellNavigation(
|
154
|
+
cellNavigation({
|
155
|
+
event,
|
156
|
+
cellValue: header.column.columnDef.header,
|
157
|
+
table,
|
158
|
+
header,
|
159
|
+
});
|
155
160
|
}
|
156
|
-
tableCellProps?.onKeyDown?.(
|
161
|
+
tableCellProps?.onKeyDown?.(event);
|
157
162
|
};
|
158
163
|
|
159
164
|
const HeaderElement =
|
@@ -338,6 +338,10 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
338
338
|
: filterPlaceholder,
|
339
339
|
variant: 'standard',
|
340
340
|
...textFieldProps,
|
341
|
+
onKeyDown: (e) => {
|
342
|
+
e.stopPropagation();
|
343
|
+
textFieldProps.onKeyDown?.(e);
|
344
|
+
},
|
341
345
|
sx: (theme) => ({
|
342
346
|
minWidth: isDateFilter
|
343
347
|
? '160px'
|
package/src/types.ts
CHANGED
@@ -1099,9 +1099,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1099
1099
|
table: MRT_TableInstance<TData>;
|
1100
1100
|
}) => CheckboxProps | RadioProps)
|
1101
1101
|
| (CheckboxProps | RadioProps);
|
1102
|
-
/**
|
1103
|
-
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1104
|
-
*/
|
1105
1102
|
muiSkeletonProps?:
|
1106
1103
|
| ((props: {
|
1107
1104
|
cell: MRT_Cell<TData>;
|
@@ -1236,6 +1233,9 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1236
1233
|
renderCaption?:
|
1237
1234
|
| ((props: { table: MRT_TableInstance<TData> }) => ReactNode)
|
1238
1235
|
| ReactNode;
|
1236
|
+
/**
|
1237
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1238
|
+
*/
|
1239
1239
|
renderCellActionMenuItems?: (props: {
|
1240
1240
|
cell: MRT_Cell<TData>;
|
1241
1241
|
closeMenu: () => void;
|
@@ -1246,12 +1246,18 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
|
|
1246
1246
|
staticRowIndex?: number;
|
1247
1247
|
table: MRT_TableInstance<TData>;
|
1248
1248
|
}) => ReactNode[];
|
1249
|
+
/**
|
1250
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1251
|
+
*/
|
1249
1252
|
renderColumnActionsMenuItems?: (props: {
|
1250
1253
|
closeMenu: () => void;
|
1251
1254
|
column: MRT_Column<TData>;
|
1252
1255
|
internalColumnMenuItems: ReactNode[];
|
1253
1256
|
table: MRT_TableInstance<TData>;
|
1254
1257
|
}) => ReactNode[];
|
1258
|
+
/**
|
1259
|
+
* @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
|
1260
|
+
*/
|
1255
1261
|
renderColumnFilterModeMenuItems?: (props: {
|
1256
1262
|
column: MRT_Column<TData>;
|
1257
1263
|
internalFilterOptions: MRT_InternalFilterOption[];
|
package/src/utils/cell.utils.ts
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
import {
|
2
|
+
MRT_Header,
|
2
3
|
type MRT_Cell,
|
3
4
|
type MRT_RowData,
|
4
5
|
type MRT_TableInstance,
|
5
6
|
} from '../types';
|
7
|
+
import {
|
8
|
+
getMRT_RowSelectionHandler,
|
9
|
+
getMRT_SelectAllHandler,
|
10
|
+
} from './row.utils';
|
6
11
|
import { parseFromValuesOrFunc } from './utils';
|
7
12
|
|
8
13
|
export const isCellEditable = <TData extends MRT_RowData>({
|
@@ -49,20 +54,77 @@ export const openEditingCell = <TData extends MRT_RowData>({
|
|
49
54
|
}
|
50
55
|
};
|
51
56
|
|
52
|
-
export const cellNavigation = (
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
export const cellNavigation = <TData extends MRT_RowData = MRT_RowData>({
|
58
|
+
cell,
|
59
|
+
cellElements,
|
60
|
+
cellValue,
|
61
|
+
containerElement,
|
62
|
+
event,
|
63
|
+
header,
|
64
|
+
parentElement,
|
65
|
+
table,
|
66
|
+
}: {
|
67
|
+
cell?: MRT_Cell<TData>;
|
68
|
+
header?: MRT_Header<TData>;
|
69
|
+
cellElements?: Array<HTMLTableCellElement>;
|
70
|
+
cellValue?: string;
|
71
|
+
containerElement?: HTMLTableElement;
|
72
|
+
event: React.KeyboardEvent<HTMLTableCellElement>;
|
73
|
+
parentElement?: HTMLTableRowElement;
|
74
|
+
table: MRT_TableInstance<TData>;
|
75
|
+
}) => {
|
76
|
+
if (cellValue && (event.ctrlKey || event.metaKey) && event.key === 'c') {
|
77
|
+
navigator.clipboard.writeText(cellValue);
|
78
|
+
} else if (['Enter', ' '].includes(event.key)) {
|
79
|
+
if (cell?.column?.id === 'mrt-row-select') {
|
80
|
+
getMRT_RowSelectionHandler({
|
81
|
+
row: cell.row,
|
82
|
+
table,
|
83
|
+
//@ts-ignore
|
84
|
+
staticRowIndex: +event.target.getAttribute('data-index'),
|
85
|
+
})(event as any);
|
86
|
+
} else if (
|
87
|
+
header?.column?.id === 'mrt-row-select' &&
|
88
|
+
table.options.enableSelectAll
|
89
|
+
) {
|
90
|
+
getMRT_SelectAllHandler({
|
91
|
+
table,
|
92
|
+
})(event as any);
|
93
|
+
} else if (
|
94
|
+
cell?.column?.id === 'mrt-row-expand' &&
|
95
|
+
(cell.row.getCanExpand() ||
|
96
|
+
table.options.renderDetailPanel?.({ row: cell.row, table }))
|
97
|
+
) {
|
98
|
+
cell.row.toggleExpanded();
|
99
|
+
} else if (
|
100
|
+
header?.column?.id === 'mrt-row-expand' &&
|
101
|
+
table.options.enableExpandAll
|
102
|
+
) {
|
103
|
+
table.toggleAllRowsExpanded();
|
104
|
+
} else if (header?.column?.getCanSort()) {
|
105
|
+
header.column.toggleSorting();
|
106
|
+
} else if (cell?.column.id === 'mrt-row-pin') {
|
107
|
+
cell.row.getIsPinned()
|
108
|
+
? cell.row.pin(false)
|
109
|
+
: cell.row.pin(
|
110
|
+
table.options.rowPinningDisplayMode?.includes('bottom')
|
111
|
+
? 'bottom'
|
112
|
+
: 'top',
|
113
|
+
);
|
114
|
+
}
|
115
|
+
} else if (
|
56
116
|
['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(
|
57
|
-
|
117
|
+
event.key,
|
58
118
|
)
|
59
119
|
) {
|
60
|
-
|
61
|
-
const currentCell =
|
62
|
-
const currentRow = currentCell.closest('tr');
|
120
|
+
event.preventDefault();
|
121
|
+
const currentCell = event.currentTarget;
|
122
|
+
const currentRow = parentElement || currentCell.closest('tr');
|
63
123
|
|
64
|
-
const tableElement = currentCell.closest('table');
|
65
|
-
const allCells =
|
124
|
+
const tableElement = containerElement || currentCell.closest('table');
|
125
|
+
const allCells =
|
126
|
+
cellElements ||
|
127
|
+
Array.from(tableElement?.querySelectorAll('th, td') || []);
|
66
128
|
const currentCellIndex = allCells.indexOf(currentCell);
|
67
129
|
|
68
130
|
const currentIndex = parseInt(
|
@@ -76,8 +138,8 @@ export const cellNavigation = (
|
|
76
138
|
rowIndex === 'c'
|
77
139
|
? currentRow
|
78
140
|
: rowIndex === 'f'
|
79
|
-
?
|
80
|
-
:
|
141
|
+
? tableElement?.querySelector('tr')
|
142
|
+
: tableElement?.lastElementChild?.lastElementChild;
|
81
143
|
const rowCells = Array.from(row?.children || []);
|
82
144
|
const targetCell =
|
83
145
|
edge === 'f' ? rowCells[0] : rowCells[rowCells.length - 1];
|
@@ -97,7 +159,7 @@ export const cellNavigation = (
|
|
97
159
|
) as HTMLElement | undefined;
|
98
160
|
};
|
99
161
|
|
100
|
-
switch (
|
162
|
+
switch (event.key) {
|
101
163
|
case 'ArrowRight':
|
102
164
|
nextCell = findAdjacentCell(currentIndex + 1, 'f');
|
103
165
|
break;
|
@@ -111,10 +173,10 @@ export const cellNavigation = (
|
|
111
173
|
nextCell = findAdjacentCell(currentIndex, 'f');
|
112
174
|
break;
|
113
175
|
case 'Home':
|
114
|
-
nextCell = findEdgeCell(
|
176
|
+
nextCell = findEdgeCell(event.ctrlKey ? 'f' : 'c', 'f');
|
115
177
|
break;
|
116
178
|
case 'End':
|
117
|
-
nextCell = findEdgeCell(
|
179
|
+
nextCell = findEdgeCell(event.ctrlKey ? 'l' : 'c', 'l');
|
118
180
|
break;
|
119
181
|
}
|
120
182
|
|