material-react-table 1.1.1 → 1.2.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 CHANGED
@@ -242,6 +242,7 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
242
242
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
243
243
  searchInputRef: MutableRefObject<HTMLInputElement>;
244
244
  tableContainerRef: MutableRefObject<HTMLDivElement>;
245
+ tableHeadCellRefs: MutableRefObject<Record<string, HTMLTableCellElement>>;
245
246
  tablePaperRef: MutableRefObject<HTMLDivElement>;
246
247
  topToolbarRef: MutableRefObject<HTMLDivElement>;
247
248
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.1",
2
+ "version": "1.2.1",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -93,7 +93,7 @@
93
93
  "@emotion/styled": ">=11",
94
94
  "@mui/icons-material": ">=5",
95
95
  "@mui/material": ">=5",
96
- "react": ">=16.8"
96
+ "react": ">=17.0"
97
97
  },
98
98
  "dependencies": {
99
99
  "@tanstack/match-sorter-utils": "8.1.1",
@@ -199,6 +199,7 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
199
199
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
200
200
  searchInputRef: MutableRefObject<HTMLInputElement>;
201
201
  tableContainerRef: MutableRefObject<HTMLDivElement>;
202
+ tableHeadCellRefs: MutableRefObject<Record<string, HTMLTableCellElement>>;
202
203
  tablePaperRef: MutableRefObject<HTMLDivElement>;
203
204
  topToolbarRef: MutableRefObject<HTMLDivElement>;
204
205
  };
@@ -10,12 +10,14 @@ interface Props {
10
10
  export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
11
11
  const {
12
12
  getVisibleLeafColumns,
13
+ getState,
13
14
  options: {
14
15
  muiTableBodyRowProps,
15
16
  muiTableDetailPanelProps,
16
17
  renderDetailPanel,
17
18
  },
18
19
  } = table;
20
+ const { isLoading } = getState();
19
21
 
20
22
  const tableRowProps =
21
23
  muiTableBodyRowProps instanceof Function
@@ -44,7 +46,11 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
44
46
  })}
45
47
  >
46
48
  {renderDetailPanel && (
47
- <Collapse in={row.getIsExpanded()}>
49
+ <Collapse
50
+ in={!isLoading && row.getIsExpanded()}
51
+ mountOnEnter
52
+ unmountOnExit
53
+ >
48
54
  {renderDetailPanel({ row, table })}
49
55
  </Collapse>
50
56
  )}
@@ -43,7 +43,7 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
43
43
  onDragEnd={onDragEnd}
44
44
  sx={(theme) => ({
45
45
  cursor: 'grab',
46
- m: 0,
46
+ m: '0 -0.1rem',
47
47
  opacity: 0.5,
48
48
  p: '2px',
49
49
  transition: 'all 150ms ease-in-out',
@@ -26,6 +26,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
26
26
  enableMultiSort,
27
27
  muiTableHeadCellProps,
28
28
  },
29
+ refs: { tableHeadCellRefs },
29
30
  setHoveredColumn,
30
31
  } = table;
31
32
  const {
@@ -54,6 +55,27 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
54
55
  ...mcTableHeadCellProps,
55
56
  };
56
57
 
58
+ const showColumnActions =
59
+ (enableColumnActions || columnDef.enableColumnActions) &&
60
+ columnDef.enableColumnActions !== false;
61
+
62
+ const showDragHandle =
63
+ enableColumnDragging !== false &&
64
+ columnDef.enableColumnDragging !== false &&
65
+ (enableColumnDragging ||
66
+ (enableColumnOrdering && columnDef.enableColumnOrdering !== false) ||
67
+ (enableGrouping &&
68
+ columnDef.enableGrouping !== false &&
69
+ !grouping.includes(column.id)));
70
+
71
+ const headerPL = useMemo(() => {
72
+ let pl = 0;
73
+ if (column.getCanSort()) pl++;
74
+ if (showColumnActions) pl += 1.75;
75
+ if (showDragHandle) pl += 1.25;
76
+ return pl;
77
+ }, [showColumnActions, showDragHandle]);
78
+
57
79
  const draggingBorder = useMemo(
58
80
  () =>
59
81
  draggingColumn?.id === column.id
@@ -83,22 +105,25 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
83
105
  }
84
106
  };
85
107
 
86
- const headerElement = ((columnDef?.Header instanceof Function
87
- ? columnDef?.Header?.({
88
- column,
89
- header,
90
- table,
91
- })
92
- : columnDef?.Header) ?? columnDef.header) as ReactNode;
93
-
94
- const tableHeadCellRef = React.useRef<HTMLTableCellElement>(null);
108
+ const headerElement =
109
+ columnDef?.Header instanceof Function
110
+ ? columnDef?.Header?.({
111
+ column,
112
+ header,
113
+ table,
114
+ })
115
+ : columnDef?.Header ?? (columnDef.header as ReactNode);
95
116
 
96
117
  return (
97
118
  <TableCell
98
119
  align={columnDefType === 'group' ? 'center' : 'left'}
99
120
  colSpan={header.colSpan}
100
121
  onDragEnter={handleDragEnter}
101
- ref={tableHeadCellRef}
122
+ ref={(node) => {
123
+ if (node) {
124
+ tableHeadCellRefs.current[column.id] = node as HTMLTableCellElement;
125
+ }
126
+ }}
102
127
  {...tableCellProps}
103
128
  sx={(theme: Theme) => ({
104
129
  fontWeight: 'bold',
@@ -145,23 +170,24 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
145
170
  >
146
171
  {header.isPlaceholder ? null : (
147
172
  <Box
173
+ className="Mui-TableHeadCell-Content"
148
174
  sx={{
149
175
  alignItems: 'flex-start',
150
176
  display: 'flex',
151
177
  flexDirection:
152
178
  tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
153
179
  justifyContent:
154
- tableCellProps?.align === 'right'
155
- ? 'flex-start'
156
- : columnDefType === 'group' ||
157
- tableCellProps?.align === 'center'
180
+ columnDefType === 'group' || tableCellProps?.align === 'center'
158
181
  ? 'center'
159
- : 'space-between',
182
+ : column.getCanResize()
183
+ ? 'space-between'
184
+ : 'flex-start',
160
185
  position: 'relative',
161
186
  width: '100%',
162
187
  }}
163
188
  >
164
189
  <Box
190
+ className="Mui-TableHeadCell-Content-Labels"
165
191
  onClick={column.getToggleSortingHandler()}
166
192
  sx={{
167
193
  alignItems: 'center',
@@ -172,17 +198,25 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
172
198
  display: 'flex',
173
199
  flexDirection:
174
200
  tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
175
- flexWrap: 'nowrap',
176
- m: tableCellProps?.align === 'center' ? 'auto' : undefined,
201
+ overflow: 'hidden',
177
202
  pl:
178
- tableCellProps?.align === 'center' && column.getCanSort()
179
- ? '1rem'
203
+ tableCellProps?.align === 'center'
204
+ ? `${headerPL}rem`
180
205
  : undefined,
181
- whiteSpace:
182
- (columnDef.header?.length ?? 0) < 24 ? 'nowrap' : 'normal',
183
206
  }}
184
207
  >
185
- {headerElement}
208
+ <Box
209
+ className="Mui-TableHeadCell-Content-Wrapper"
210
+ sx={{
211
+ overflow: 'hidden',
212
+ textOverflow: 'ellipsis',
213
+ whiteSpace:
214
+ (columnDef.header?.length ?? 0) < 20 ? 'nowrap' : 'normal',
215
+ }}
216
+ title={columnDef.header}
217
+ >
218
+ {headerElement}
219
+ </Box>
186
220
  {column.getCanSort() && (
187
221
  <MRT_TableHeadCellSortLabel
188
222
  header={header}
@@ -195,28 +229,25 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
195
229
  )}
196
230
  </Box>
197
231
  {columnDefType !== 'group' && (
198
- <Box sx={{ whiteSpace: 'nowrap' }}>
199
- {enableColumnDragging !== false &&
200
- columnDef.enableColumnDragging !== false &&
201
- (enableColumnDragging ||
202
- (enableColumnOrdering &&
203
- columnDef.enableColumnOrdering !== false) ||
204
- (enableGrouping &&
205
- columnDef.enableGrouping !== false &&
206
- !grouping.includes(column.id))) && (
207
- <MRT_TableHeadCellGrabHandle
208
- column={column}
209
- table={table}
210
- tableHeadCellRef={tableHeadCellRef}
211
- />
212
- )}
213
- {(enableColumnActions || columnDef.enableColumnActions) &&
214
- columnDef.enableColumnActions !== false && (
215
- <MRT_TableHeadCellColumnActionsButton
216
- header={header}
217
- table={table}
218
- />
219
- )}
232
+ <Box
233
+ className="Mui-TableHeadCell-Content-Actions"
234
+ sx={{ whiteSpace: 'nowrap' }}
235
+ >
236
+ {showDragHandle && (
237
+ <MRT_TableHeadCellGrabHandle
238
+ column={column}
239
+ table={table}
240
+ tableHeadCellRef={{
241
+ current: tableHeadCellRefs.current[column.id],
242
+ }}
243
+ />
244
+ )}
245
+ {showColumnActions && (
246
+ <MRT_TableHeadCellColumnActionsButton
247
+ header={header}
248
+ table={table}
249
+ />
250
+ )}
220
251
  </Box>
221
252
  )}
222
253
  {column.getCanResize() && (
@@ -1,5 +1,5 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
- import { Grow, IconButton, Tooltip } from '@mui/material';
2
+ import { Box, Grow, IconButton, Tooltip } from '@mui/material';
3
3
  import { MRT_Header, MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
@@ -56,7 +56,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
56
56
  (!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
57
57
  }
58
58
  >
59
- <span>
59
+ <Box component="span" sx={{ flex: '0 0' }}>
60
60
  <Tooltip arrow placement="top" title={filterTooltip}>
61
61
  <IconButton
62
62
  disableRipple
@@ -75,7 +75,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
75
75
  <FilterAltIcon />
76
76
  </IconButton>
77
77
  </Tooltip>
78
- </span>
78
+ </Box>
79
79
  </Grow>
80
80
  );
81
81
  };
@@ -49,10 +49,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({ header, table }) => {
49
49
  borderRadius: '2px',
50
50
  borderWidth: '2px',
51
51
  height:
52
- showColumnFilters && columnDefType === 'data'
53
- ? '3.5rem'
54
- : '1.75rem',
55
- opacity: 0.8,
52
+ showColumnFilters && columnDefType === 'data' ? '3.5rem' : '1.5rem',
56
53
  touchAction: 'none',
57
54
  transition: column.getIsResizing()
58
55
  ? undefined
@@ -36,6 +36,7 @@ export const MRT_TableHeadCellSortLabel: FC<Props> = ({
36
36
  : undefined
37
37
  }
38
38
  sx={{
39
+ flex: '0 0',
39
40
  width: '2ch',
40
41
  transform:
41
42
  tableCellProps?.align !== 'right'
@@ -38,6 +38,7 @@ export const MRT_FilterTextField: FC<Props> = ({
38
38
  columnFilterModeOptions,
39
39
  icons: { FilterListIcon, CloseIcon },
40
40
  localization,
41
+ manualFiltering,
41
42
  muiTableHeadCellFilterTextFieldProps,
42
43
  },
43
44
  refs: { filterInputRefs },
@@ -132,7 +133,7 @@ export const MRT_FilterTextField: FC<Props> = ({
132
133
  column.setFilterValue(value ?? undefined);
133
134
  }
134
135
  },
135
- isTextboxFilter ? 200 : 1,
136
+ isTextboxFilter ? (manualFiltering ? 400 : 200) : 1,
136
137
  ),
137
138
  [],
138
139
  );
@@ -32,6 +32,7 @@ export const MRT_GlobalFilterTextField = <
32
32
  enableGlobalFilterModes,
33
33
  icons: { SearchIcon, CloseIcon },
34
34
  localization,
35
+ manualFiltering,
35
36
  muiSearchTextFieldProps,
36
37
  },
37
38
  refs: { searchInputRef },
@@ -47,9 +48,12 @@ export const MRT_GlobalFilterTextField = <
47
48
  const [searchValue, setSearchValue] = useState(globalFilter ?? '');
48
49
 
49
50
  const handleChangeDebounced = useCallback(
50
- debounce((event: ChangeEvent<HTMLInputElement>) => {
51
- setGlobalFilter(event.target.value ?? undefined);
52
- }, 250),
51
+ debounce(
52
+ (event: ChangeEvent<HTMLInputElement>) => {
53
+ setGlobalFilter(event.target.value ?? undefined);
54
+ },
55
+ manualFiltering ? 500 : 250,
56
+ ),
53
57
  [],
54
58
  );
55
59
 
@@ -46,6 +46,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
46
46
  const filterInputRefs = useRef<Record<string, HTMLInputElement>>({});
47
47
  const searchInputRef = useRef<HTMLInputElement>(null);
48
48
  const tableContainerRef = useRef<HTMLDivElement>(null);
49
+ const tableHeadCellRefs = useRef<Record<string, HTMLTableCellElement>>({});
49
50
  const tablePaperRef = useRef<HTMLDivElement>(null);
50
51
  const topToolbarRef = useRef<HTMLDivElement>(null);
51
52
 
@@ -294,6 +295,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
294
295
  filterInputRefs,
295
296
  searchInputRef,
296
297
  tableContainerRef,
298
+ tableHeadCellRefs,
297
299
  tablePaperRef,
298
300
  topToolbarRef,
299
301
  },