material-react-table 3.0.0-alpha.0 → 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 +2 -2
- package/dist/index.d.ts +51 -5
- package/dist/index.esm.js +167 -54
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +167 -53
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- 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 -7
- package/src/utils/cell.utils.ts +75 -0
- package/src/utils/style.utils.ts +5 -0
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),
|