material-react-table 1.13.0 → 1.14.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.
@@ -70,6 +70,7 @@ export const MRT_ColumnActionMenu = ({
70
70
  const { columnDef } = column;
71
71
  const { columnSizing, columnVisibility, density, showColumnFilters } =
72
72
  getState();
73
+ const columnFilterValue = column.getFilterValue();
73
74
 
74
75
  const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
75
76
  useState<null | HTMLElement>(null);
@@ -144,85 +145,68 @@ export const MRT_ColumnActionMenu = ({
144
145
  (allowedColumnFilterOptions === undefined ||
145
146
  !!allowedColumnFilterOptions?.length);
146
147
 
147
- return (
148
- <Menu
149
- anchorEl={anchorEl}
150
- open={!!anchorEl}
151
- onClose={() => setAnchorEl(null)}
152
- MenuListProps={{
153
- dense: density === 'compact',
154
- }}
155
- >
156
- {columnDef.renderColumnActionsMenuItems?.({
157
- closeMenu: () => setAnchorEl(null),
158
- column,
159
- table,
160
- }) ??
161
- renderColumnActionsMenuItems?.({
162
- closeMenu: () => setAnchorEl(null),
163
- column,
164
- table,
165
- }) ??
166
- (enableSorting &&
167
- column.getCanSort() &&
168
- [
169
- enableSortingRemoval !== false && (
170
- <MenuItem
171
- disabled={!column.getIsSorted()}
172
- key={0}
173
- onClick={handleClearSort}
174
- sx={commonMenuItemStyles}
175
- >
176
- <Box sx={commonListItemStyles}>
177
- <ListItemIcon>
178
- <ClearAllIcon />
179
- </ListItemIcon>
180
- {localization.clearSort}
181
- </Box>
182
- </MenuItem>
183
- ),
148
+ const internalColumnMenuItems = [
149
+ ...(enableSorting && column.getCanSort()
150
+ ? [
151
+ enableSortingRemoval !== false && (
184
152
  <MenuItem
185
- disabled={column.getIsSorted() === 'asc'}
186
- key={1}
187
- onClick={handleSortAsc}
153
+ disabled={!column.getIsSorted()}
154
+ key={0}
155
+ onClick={handleClearSort}
188
156
  sx={commonMenuItemStyles}
189
157
  >
190
158
  <Box sx={commonListItemStyles}>
191
159
  <ListItemIcon>
192
- <SortIcon
193
- style={{ transform: 'rotate(180deg) scaleX(-1)' }}
194
- />
160
+ <ClearAllIcon />
195
161
  </ListItemIcon>
196
- {localization.sortByColumnAsc?.replace(
197
- '{column}',
198
- String(columnDef.header),
199
- )}
162
+ {localization.clearSort}
200
163
  </Box>
201
- </MenuItem>,
202
- <MenuItem
203
- divider={enableColumnFilters || enableGrouping || enableHiding}
204
- key={2}
205
- disabled={column.getIsSorted() === 'desc'}
206
- onClick={handleSortDesc}
207
- sx={commonMenuItemStyles}
208
- >
209
- <Box sx={commonListItemStyles}>
210
- <ListItemIcon>
211
- <SortIcon />
212
- </ListItemIcon>
213
- {localization.sortByColumnDesc?.replace(
214
- '{column}',
215
- String(columnDef.header),
216
- )}
217
- </Box>
218
- </MenuItem>,
219
- ].filter(Boolean))}
220
- {enableColumnFilters &&
221
- column.getCanFilter() &&
222
- [
164
+ </MenuItem>
165
+ ),
223
166
  <MenuItem
224
- disabled={!column.getFilterValue()}
225
- key={0}
167
+ disabled={column.getIsSorted() === 'asc'}
168
+ key={1}
169
+ onClick={handleSortAsc}
170
+ sx={commonMenuItemStyles}
171
+ >
172
+ <Box sx={commonListItemStyles}>
173
+ <ListItemIcon>
174
+ <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
175
+ </ListItemIcon>
176
+ {localization.sortByColumnAsc?.replace(
177
+ '{column}',
178
+ String(columnDef.header),
179
+ )}
180
+ </Box>
181
+ </MenuItem>,
182
+ <MenuItem
183
+ divider={enableColumnFilters || enableGrouping || enableHiding}
184
+ key={2}
185
+ disabled={column.getIsSorted() === 'desc'}
186
+ onClick={handleSortDesc}
187
+ sx={commonMenuItemStyles}
188
+ >
189
+ <Box sx={commonListItemStyles}>
190
+ <ListItemIcon>
191
+ <SortIcon />
192
+ </ListItemIcon>
193
+ {localization.sortByColumnDesc?.replace(
194
+ '{column}',
195
+ String(columnDef.header),
196
+ )}
197
+ </Box>
198
+ </MenuItem>,
199
+ ]
200
+ : []),
201
+ ...(enableColumnFilters && column.getCanFilter()
202
+ ? [
203
+ <MenuItem
204
+ disabled={
205
+ !columnFilterValue ||
206
+ (Array.isArray(columnFilterValue) &&
207
+ !columnFilterValue.filter((value) => value).length)
208
+ }
209
+ key={3}
226
210
  onClick={handleClearFilter}
227
211
  sx={commonMenuItemStyles}
228
212
  >
@@ -236,7 +220,7 @@ export const MRT_ColumnActionMenu = ({
236
220
  <MenuItem
237
221
  disabled={showColumnFilters && !enableColumnFilterModes}
238
222
  divider={enableGrouping || enableHiding}
239
- key={1}
223
+ key={4}
240
224
  onClick={
241
225
  showColumnFilters
242
226
  ? handleOpenFilterModeMenu
@@ -268,18 +252,19 @@ export const MRT_ColumnActionMenu = ({
268
252
  <MRT_FilterOptionMenu
269
253
  anchorEl={filterMenuAnchorEl}
270
254
  header={header}
271
- key={2}
255
+ key={5}
272
256
  onSelect={handleFilterByColumn}
273
257
  setAnchorEl={setFilterMenuAnchorEl}
274
258
  table={table}
275
259
  />
276
260
  ),
277
- ].filter(Boolean)}
278
- {enableGrouping &&
279
- column.getCanGroup() && [
261
+ ]
262
+ : []),
263
+ ...(enableGrouping && column.getCanGroup()
264
+ ? [
280
265
  <MenuItem
281
266
  divider={enablePinning}
282
- key={0}
267
+ key={6}
283
268
  onClick={handleGroupByColumn}
284
269
  sx={commonMenuItemStyles}
285
270
  >
@@ -292,12 +277,13 @@ export const MRT_ColumnActionMenu = ({
292
277
  ]?.replace('{column}', String(columnDef.header))}
293
278
  </Box>
294
279
  </MenuItem>,
295
- ]}
296
- {enablePinning &&
297
- column.getCanPin() && [
280
+ ]
281
+ : []),
282
+ ...(enablePinning && column.getCanPin()
283
+ ? [
298
284
  <MenuItem
299
285
  disabled={column.getIsPinned() === 'left' || !column.getCanPin()}
300
- key={0}
286
+ key={7}
301
287
  onClick={() => handlePinColumn('left')}
302
288
  sx={commonMenuItemStyles}
303
289
  >
@@ -310,7 +296,7 @@ export const MRT_ColumnActionMenu = ({
310
296
  </MenuItem>,
311
297
  <MenuItem
312
298
  disabled={column.getIsPinned() === 'right' || !column.getCanPin()}
313
- key={1}
299
+ key={8}
314
300
  onClick={() => handlePinColumn('right')}
315
301
  sx={commonMenuItemStyles}
316
302
  >
@@ -324,7 +310,7 @@ export const MRT_ColumnActionMenu = ({
324
310
  <MenuItem
325
311
  disabled={!column.getIsPinned()}
326
312
  divider={enableHiding}
327
- key={2}
313
+ key={9}
328
314
  onClick={() => handlePinColumn(false)}
329
315
  sx={commonMenuItemStyles}
330
316
  >
@@ -335,12 +321,13 @@ export const MRT_ColumnActionMenu = ({
335
321
  {localization.unpin}
336
322
  </Box>
337
323
  </MenuItem>,
338
- ]}
339
- {enableColumnResizing &&
340
- column.getCanResize() && [
324
+ ]
325
+ : []),
326
+ ...(enableColumnResizing && column.getCanResize()
327
+ ? [
341
328
  <MenuItem
342
329
  disabled={!columnSizing[column.id]}
343
- key={0}
330
+ key={10}
344
331
  onClick={handleResetColumnSize}
345
332
  sx={commonMenuItemStyles}
346
333
  >
@@ -351,44 +338,71 @@ export const MRT_ColumnActionMenu = ({
351
338
  {localization.resetColumnSize}
352
339
  </Box>
353
340
  </MenuItem>,
354
- ]}
355
- {enableHiding && [
356
- <MenuItem
357
- disabled={!column.getCanHide()}
358
- key={0}
359
- onClick={handleHideColumn}
360
- sx={commonMenuItemStyles}
361
- >
362
- <Box sx={commonListItemStyles}>
363
- <ListItemIcon>
364
- <VisibilityOffIcon />
365
- </ListItemIcon>
366
- {localization.hideColumn?.replace(
367
- '{column}',
368
- String(columnDef.header),
369
- )}
370
- </Box>
371
- </MenuItem>,
372
- <MenuItem
373
- disabled={
374
- !Object.values(columnVisibility).filter((visible) => !visible)
375
- .length
376
- }
377
- key={1}
378
- onClick={handleShowAllColumns}
379
- sx={commonMenuItemStyles}
380
- >
381
- <Box sx={commonListItemStyles}>
382
- <ListItemIcon>
383
- <ViewColumnIcon />
384
- </ListItemIcon>
385
- {localization.showAllColumns?.replace(
386
- '{column}',
387
- String(columnDef.header),
388
- )}
389
- </Box>
390
- </MenuItem>,
391
- ]}
341
+ ]
342
+ : []),
343
+ ...(enableHiding
344
+ ? [
345
+ <MenuItem
346
+ disabled={!column.getCanHide()}
347
+ key={11}
348
+ onClick={handleHideColumn}
349
+ sx={commonMenuItemStyles}
350
+ >
351
+ <Box sx={commonListItemStyles}>
352
+ <ListItemIcon>
353
+ <VisibilityOffIcon />
354
+ </ListItemIcon>
355
+ {localization.hideColumn?.replace(
356
+ '{column}',
357
+ String(columnDef.header),
358
+ )}
359
+ </Box>
360
+ </MenuItem>,
361
+ <MenuItem
362
+ disabled={
363
+ !Object.values(columnVisibility).filter((visible) => !visible)
364
+ .length
365
+ }
366
+ key={12}
367
+ onClick={handleShowAllColumns}
368
+ sx={commonMenuItemStyles}
369
+ >
370
+ <Box sx={commonListItemStyles}>
371
+ <ListItemIcon>
372
+ <ViewColumnIcon />
373
+ </ListItemIcon>
374
+ {localization.showAllColumns?.replace(
375
+ '{column}',
376
+ String(columnDef.header),
377
+ )}
378
+ </Box>
379
+ </MenuItem>,
380
+ ]
381
+ : []),
382
+ ].filter(Boolean);
383
+
384
+ return (
385
+ <Menu
386
+ anchorEl={anchorEl}
387
+ open={!!anchorEl}
388
+ onClose={() => setAnchorEl(null)}
389
+ MenuListProps={{
390
+ dense: density === 'compact',
391
+ }}
392
+ >
393
+ {columnDef.renderColumnActionsMenuItems?.({
394
+ closeMenu: () => setAnchorEl(null),
395
+ column,
396
+ internalColumnMenuItems,
397
+ table,
398
+ }) ??
399
+ renderColumnActionsMenuItems?.({
400
+ closeMenu: () => setAnchorEl(null),
401
+ column,
402
+ internalColumnMenuItems,
403
+ table,
404
+ }) ??
405
+ internalColumnMenuItems}
392
406
  </Menu>
393
407
  );
394
408
  };
package/src/types.ts CHANGED
@@ -485,6 +485,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> =
485
485
  renderColumnActionsMenuItems?: (props: {
486
486
  closeMenu: () => void;
487
487
  column: MRT_Column<TData>;
488
+ internalColumnMenuItems: ReactNode[];
488
489
  table: MRT_TableInstance<TData>;
489
490
  }) => ReactNode[];
490
491
  renderColumnFilterModeMenuItems?: (props: {
@@ -914,6 +915,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
914
915
  renderColumnActionsMenuItems?: (props: {
915
916
  column: MRT_Column<TData>;
916
917
  closeMenu: () => void;
918
+ internalColumnMenuItems: ReactNode[];
917
919
  table: MRT_TableInstance<TData>;
918
920
  }) => ReactNode[];
919
921
  renderColumnFilterModeMenuItems?: (props: {