material-react-table 0.38.1 → 0.38.4

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.
Files changed (46) hide show
  1. package/dist/cjs/MaterialReactTable.d.ts +1 -0
  2. package/dist/cjs/body/MRT_EditRowModal.d.ts +1 -0
  3. package/dist/cjs/body/MRT_TableBodyRow.d.ts +1 -0
  4. package/dist/cjs/buttons/MRT_ColumnPinningButtons.d.ts +1 -0
  5. package/dist/cjs/buttons/MRT_EditActionButtons.d.ts +1 -0
  6. package/dist/cjs/buttons/MRT_FullScreenToggleButton.d.ts +1 -0
  7. package/dist/cjs/buttons/MRT_ShowHideColumnsButton.d.ts +1 -0
  8. package/dist/cjs/buttons/MRT_ToggleDensePaddingButton.d.ts +1 -0
  9. package/dist/cjs/buttons/MRT_ToggleFiltersButton.d.ts +1 -0
  10. package/dist/cjs/buttons/MRT_ToggleGlobalFilterButton.d.ts +1 -0
  11. package/dist/cjs/index.js +55 -24
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/inputs/MRT_EditCellTextField.d.ts +1 -0
  14. package/dist/cjs/inputs/MRT_GlobalFilterTextField.d.ts +1 -0
  15. package/dist/cjs/menus/MRT_FilterOptionMenu.d.ts +1 -0
  16. package/dist/cjs/menus/MRT_ShowHideColumnsMenu.d.ts +1 -0
  17. package/dist/cjs/table/MRT_TableRoot.d.ts +1 -0
  18. package/dist/esm/MaterialReactTable.d.ts +1 -0
  19. package/dist/esm/body/MRT_EditRowModal.d.ts +1 -0
  20. package/dist/esm/body/MRT_TableBodyRow.d.ts +1 -0
  21. package/dist/esm/buttons/MRT_ColumnPinningButtons.d.ts +1 -0
  22. package/dist/esm/buttons/MRT_EditActionButtons.d.ts +1 -0
  23. package/dist/esm/buttons/MRT_FullScreenToggleButton.d.ts +1 -0
  24. package/dist/esm/buttons/MRT_ShowHideColumnsButton.d.ts +1 -0
  25. package/dist/esm/buttons/MRT_ToggleDensePaddingButton.d.ts +1 -0
  26. package/dist/esm/buttons/MRT_ToggleFiltersButton.d.ts +1 -0
  27. package/dist/esm/buttons/MRT_ToggleGlobalFilterButton.d.ts +1 -0
  28. package/dist/esm/inputs/MRT_EditCellTextField.d.ts +1 -0
  29. package/dist/esm/inputs/MRT_GlobalFilterTextField.d.ts +1 -0
  30. package/dist/esm/material-react-table.esm.js +55 -24
  31. package/dist/esm/material-react-table.esm.js.map +1 -1
  32. package/dist/esm/menus/MRT_FilterOptionMenu.d.ts +1 -0
  33. package/dist/esm/menus/MRT_ShowHideColumnsMenu.d.ts +1 -0
  34. package/dist/esm/table/MRT_TableRoot.d.ts +1 -0
  35. package/dist/index.d.ts +2 -0
  36. package/package.json +2 -2
  37. package/src/MaterialReactTable.tsx +1 -0
  38. package/src/body/MRT_TableBody.tsx +1 -0
  39. package/src/body/MRT_TableBodyCellValue.tsx +10 -11
  40. package/src/body/MRT_TableBodyRow.tsx +14 -3
  41. package/src/buttons/MRT_ExpandAllButton.tsx +5 -3
  42. package/src/buttons/MRT_GrabHandleButton.tsx +5 -3
  43. package/src/footer/MRT_TableFooter.tsx +22 -2
  44. package/src/head/MRT_TableHeadRow.tsx +3 -1
  45. package/src/inputs/MRT_EditCellTextField.tsx +35 -23
  46. package/src/table/MRT_TablePaper.tsx +5 -3
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { MRT_Header, MRT_TableInstance } from '..';
2
3
  import { MRT_Localization } from '../localization';
3
4
  export declare const internalFilterOptions: (localization: MRT_Localization) => {
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { MRT_TableInstance } from '..';
2
3
  interface Props<TData extends Record<string, any> = {}> {
3
4
  anchorEl: HTMLElement | null;
@@ -1,2 +1,3 @@
1
+ /// <reference types="react" />
1
2
  import type { MaterialReactTableProps } from '..';
2
3
  export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => JSX.Element;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { MutableRefObject, Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
2
3
  import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
3
4
  import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
@@ -479,6 +480,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
479
480
  enableRowSelection?: boolean | ((row: MRT_Row<TData>) => boolean);
480
481
  enableRowVirtualization?: boolean;
481
482
  enableSelectAll?: boolean;
483
+ enableStickyFooter?: boolean;
482
484
  enableStickyHeader?: boolean;
483
485
  enableTableFooter?: boolean;
484
486
  enableTableHead?: boolean;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.38.1",
2
+ "version": "0.38.4",
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.",
@@ -78,7 +78,7 @@
78
78
  "react": "^18.2.0",
79
79
  "react-dom": "^18.2.0",
80
80
  "react-is": "^18.2.0",
81
- "rollup": "^2.78.0",
81
+ "rollup": "^2.78.1",
82
82
  "rollup-plugin-dts": "^4.2.2",
83
83
  "rollup-plugin-peer-deps-external": "^2.2.4",
84
84
  "size-limit": "^8.0.1",
@@ -488,6 +488,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
488
488
  enableRowSelection?: boolean | ((row: MRT_Row<TData>) => boolean);
489
489
  enableRowVirtualization?: boolean;
490
490
  enableSelectAll?: boolean;
491
+ enableStickyFooter?: boolean;
491
492
  enableStickyHeader?: boolean;
492
493
  enableTableFooter?: boolean;
493
494
  enableTableHead?: boolean;
@@ -124,6 +124,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
124
124
  enableRowVirtualization ? rowOrVirtualRow.index : rowIndex
125
125
  }
126
126
  table={table}
127
+ virtualRow={enableRowVirtualization ? rowOrVirtualRow : null}
127
128
  />
128
129
  );
129
130
  },
@@ -12,8 +12,8 @@ export const MRT_TableBodyCellValue: FC<Props> = ({ cell, table }) => {
12
12
 
13
13
  return (
14
14
  <>
15
- {cell.getIsAggregated() && column.columnDef.aggregationFn
16
- ? columnDef.AggregatedCell?.({
15
+ {cell.getIsAggregated() && columnDef.AggregatedCell
16
+ ? columnDef.AggregatedCell({
17
17
  cell,
18
18
  column,
19
19
  row,
@@ -21,15 +21,14 @@ export const MRT_TableBodyCellValue: FC<Props> = ({ cell, table }) => {
21
21
  })
22
22
  : row.getIsGrouped() && !cell.getIsGrouped()
23
23
  ? null
24
- : (cell.getIsGrouped() &&
25
- columnDef.GroupedCell?.({
26
- cell,
27
- column,
28
- row,
29
- table,
30
- })) ||
31
- (columnDef?.Cell?.({ cell, column, row, table }) ??
32
- cell.renderValue())}
24
+ : cell.getIsGrouped() && columnDef.GroupedCell
25
+ ? columnDef.GroupedCell({
26
+ cell,
27
+ column,
28
+ row,
29
+ table,
30
+ })
31
+ : columnDef?.Cell?.({ cell, column, row, table }) ?? cell.renderValue()}
33
32
  </>
34
33
  );
35
34
  };
@@ -8,9 +8,15 @@ interface Props {
8
8
  row: MRT_Row;
9
9
  rowIndex: number;
10
10
  table: MRT_TableInstance;
11
+ virtualRow?: any;
11
12
  }
12
13
 
13
- export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
14
+ export const MRT_TableBodyRow: FC<Props> = ({
15
+ row,
16
+ rowIndex,
17
+ table,
18
+ virtualRow,
19
+ }) => {
14
20
  const theme = useTheme();
15
21
  const {
16
22
  getIsSomeColumnsPinned,
@@ -31,7 +37,7 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
31
37
  }
32
38
  };
33
39
 
34
- const rowRef = useRef<HTMLTableRowElement>(null);
40
+ const rowRef = useRef<HTMLTableRowElement | null>(null);
35
41
 
36
42
  const draggingBorder =
37
43
  draggingRow?.id === row.id
@@ -52,7 +58,12 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
52
58
  onDragEnter={handleDragEnter}
53
59
  hover
54
60
  selected={row.getIsSelected()}
55
- ref={rowRef}
61
+ ref={(node) => {
62
+ rowRef.current = node;
63
+ if (virtualRow?.measureRef) {
64
+ virtualRow.measureRef = node;
65
+ }
66
+ }}
56
67
  {...tableRowProps}
57
68
  sx={(theme) => ({
58
69
  backgroundColor: lighten(theme.palette.background.default, 0.06),
@@ -40,12 +40,14 @@ export const MRT_ExpandAllButton: FC<Props> = ({ table }) => {
40
40
  disabled={!getCanSomeRowsExpand() && !renderDetailPanel}
41
41
  onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
42
42
  {...iconButtonProps}
43
- sx={{
43
+ sx={(theme) => ({
44
44
  height: density === 'compact' ? '1.75rem' : '2.25rem',
45
45
  width: density === 'compact' ? '1.75rem' : '2.25rem',
46
46
  mt: density !== 'compact' ? '-0.25rem' : undefined,
47
- ...iconButtonProps?.sx,
48
- }}
47
+ ...(iconButtonProps?.sx instanceof Function
48
+ ? iconButtonProps?.sx(theme)
49
+ : (iconButtonProps?.sx as any)),
50
+ })}
49
51
  >
50
52
  <KeyboardDoubleArrowDownIcon
51
53
  style={{
@@ -37,7 +37,7 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
37
37
  onDragEnd={onDragEnd}
38
38
  size="small"
39
39
  {...iconButtonProps}
40
- sx={{
40
+ sx={(theme) => ({
41
41
  cursor: 'grab',
42
42
  m: 0,
43
43
  opacity: 0.5,
@@ -50,8 +50,10 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
50
50
  '&:active': {
51
51
  cursor: 'grabbing',
52
52
  },
53
- ...iconButtonProps?.sx,
54
- }}
53
+ ...(iconButtonProps?.sx instanceof Function
54
+ ? iconButtonProps?.sx(theme)
55
+ : (iconButtonProps?.sx as any)),
56
+ })}
55
57
  >
56
58
  <DragHandleIcon />
57
59
  </IconButton>
@@ -10,16 +10,36 @@ interface Props {
10
10
  export const MRT_TableFooter: FC<Props> = ({ table }) => {
11
11
  const {
12
12
  getFooterGroups,
13
- options: { muiTableFooterProps },
13
+ getState,
14
+ options: { enableStickyFooter, muiTableFooterProps },
14
15
  } = table;
16
+ const { isFullScreen } = getState();
15
17
 
16
18
  const tableFooterProps =
17
19
  muiTableFooterProps instanceof Function
18
20
  ? muiTableFooterProps({ table })
19
21
  : muiTableFooterProps;
20
22
 
23
+ const stickFooter =
24
+ (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
25
+
21
26
  return (
22
- <TableFooter {...tableFooterProps}>
27
+ <TableFooter
28
+ {...tableFooterProps}
29
+ sx={(theme) => ({
30
+ position: stickFooter ? 'sticky' : undefined,
31
+ bottom: stickFooter ? 0 : undefined,
32
+ opacity: stickFooter ? 0.95 : undefined,
33
+ outline: stickFooter
34
+ ? theme.palette.mode === 'light'
35
+ ? `1px solid ${theme.palette.grey[300]}`
36
+ : `1px solid ${theme.palette.grey[700]}`
37
+ : undefined,
38
+ ...(tableFooterProps?.sx instanceof Function
39
+ ? tableFooterProps?.sx(theme)
40
+ : (tableFooterProps?.sx as any)),
41
+ })}
42
+ >
23
43
  {getFooterGroups().map((footerGroup) => (
24
44
  <MRT_TableFooterRow
25
45
  footerGroup={footerGroup as any}
@@ -24,7 +24,9 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, table }) => {
24
24
  sx={(theme) => ({
25
25
  boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
26
26
  backgroundColor: lighten(theme.palette.background.default, 0.04),
27
- ...(tableRowProps?.sx as any),
27
+ ...(tableRowProps?.sx instanceof Function
28
+ ? tableRowProps?.sx(theme)
29
+ : (tableRowProps?.sx as any)),
28
30
  })}
29
31
  >
30
32
  {headerGroup.headers.map((header: MRT_Header, index) => (
@@ -1,4 +1,10 @@
1
- import React, { ChangeEvent, FocusEvent, MouseEvent, useState } from 'react';
1
+ import React, {
2
+ ChangeEvent,
3
+ FocusEvent,
4
+ KeyboardEvent,
5
+ MouseEvent,
6
+ useState,
7
+ } from 'react';
2
8
  import { TextField, TextFieldProps } from '@mui/material';
3
9
  import type { MRT_Cell, MRT_TableInstance } from '..';
4
10
 
@@ -46,31 +52,36 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
46
52
  ...mcTableBodyCellEditTextFieldProps,
47
53
  };
48
54
 
49
- const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
50
- textFieldProps.onChange?.(event);
51
- setValue(event.target.value);
52
- if (textFieldProps?.select && editingRow) {
55
+ const saveRow = (newValue: string) => {
56
+ if (editingRow) {
53
57
  setEditingRow({
54
58
  ...editingRow,
55
- _valuesCache: {
56
- ...editingRow._valuesCache,
57
- [column.id]: event.target.value,
58
- },
59
+ _valuesCache: { ...editingRow._valuesCache, [column.id]: newValue },
59
60
  });
60
61
  }
61
62
  };
62
63
 
64
+ const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
65
+ textFieldProps.onChange?.(event);
66
+ setValue(event.target.value);
67
+ if (textFieldProps?.select) {
68
+ saveRow(event.target.value);
69
+ }
70
+ };
71
+
63
72
  const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
64
73
  textFieldProps.onBlur?.(event);
65
- if (editingRow) {
66
- setEditingRow({
67
- ...editingRow,
68
- _valuesCache: { ...editingRow._valuesCache, [column.id]: value },
69
- });
70
- }
74
+ saveRow(value);
71
75
  setEditingCell(null);
72
76
  };
73
77
 
78
+ const handleEnterKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
79
+ textFieldProps.onKeyDown?.(event);
80
+ if (event.key === 'Enter') {
81
+ editInputRefs.current[column.id]?.blur();
82
+ }
83
+ };
84
+
74
85
  if (columnDef.Edit) {
75
86
  return <>{columnDef.Edit?.({ cell, column, row, table })}</>;
76
87
  }
@@ -79,14 +90,6 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
79
90
  <TextField
80
91
  disabled={columnDef.enableEditing === false}
81
92
  fullWidth
82
- label={showLabel ? column.columnDef.header : undefined}
83
- margin="none"
84
- name={column.id}
85
- onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
86
- placeholder={columnDef.header}
87
- value={value}
88
- variant="standard"
89
- {...textFieldProps}
90
93
  inputRef={(inputRef) => {
91
94
  if (inputRef) {
92
95
  editInputRefs.current[column.id] = inputRef;
@@ -95,8 +98,17 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
95
98
  }
96
99
  }
97
100
  }}
101
+ label={showLabel ? column.columnDef.header : undefined}
102
+ margin="none"
103
+ name={column.id}
104
+ onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
105
+ placeholder={columnDef.header}
106
+ value={value}
107
+ variant="standard"
108
+ {...textFieldProps}
98
109
  onBlur={handleBlur}
99
110
  onChange={handleChange}
111
+ onKeyDown={handleEnterKeyDown}
100
112
  />
101
113
  );
102
114
  };
@@ -35,10 +35,12 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
35
35
  <Paper
36
36
  elevation={2}
37
37
  {...tablePaperProps}
38
- sx={{
38
+ sx={(theme) => ({
39
39
  transition: 'all 0.2s ease-in-out',
40
- ...tablePaperProps?.sx,
41
- }}
40
+ ...(tablePaperProps?.sx instanceof Function
41
+ ? tablePaperProps?.sx(theme)
42
+ : (tablePaperProps?.sx as any)),
43
+ })}
42
44
  style={{
43
45
  ...tablePaperProps?.style,
44
46
  height: isFullScreen ? '100vh' : undefined,