material-react-table 2.0.0-beta.0 → 2.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.
@@ -4,7 +4,7 @@ import { type MRT_Cell, type MRT_TableInstance } from '../types';
4
4
  interface Props<TData extends Record<string, any>> {
5
5
  cell: MRT_Cell<TData>;
6
6
  measureElement?: (element: HTMLTableCellElement) => void;
7
- numRows: number;
7
+ numRows?: number;
8
8
  rowIndex: number;
9
9
  rowRef: RefObject<HTMLTableRowElement>;
10
10
  table: MRT_TableInstance<TData>;
@@ -3,7 +3,7 @@ import { type MRT_Row, type MRT_TableInstance } from '../types';
3
3
  interface Props<TData extends Record<string, any>> {
4
4
  columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
5
5
  measureElement?: (element: HTMLTableRowElement) => void;
6
- numRows: number;
6
+ numRows?: number;
7
7
  pinnedRowIds?: string[];
8
8
  row: MRT_Row<TData>;
9
9
  rowIndex: number;
package/dist/index.d.ts CHANGED
@@ -965,7 +965,7 @@ declare const Memo_MRT_TableBody: <TData extends Record<string, any>>({ columnVi
965
965
  interface Props$R<TData extends Record<string, any>> {
966
966
  cell: MRT_Cell<TData>;
967
967
  measureElement?: (element: HTMLTableCellElement) => void;
968
- numRows: number;
968
+ numRows?: number;
969
969
  rowIndex: number;
970
970
  rowRef: RefObject<HTMLTableRowElement>;
971
971
  table: MRT_TableInstance<TData>;
@@ -983,7 +983,7 @@ declare const MRT_TableBodyCellValue: <TData extends Record<string, any>>({ cell
983
983
  interface Props$P<TData extends Record<string, any>> {
984
984
  columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
985
985
  measureElement?: (element: HTMLTableRowElement) => void;
986
- numRows: number;
986
+ numRows?: number;
987
987
  pinnedRowIds?: string[];
988
988
  row: MRT_Row<TData>;
989
989
  rowIndex: number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.0-beta.0",
2
+ "version": "2.0.0-beta.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.",
@@ -40,6 +40,7 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
40
40
  getState,
41
41
  getTopRows,
42
42
  options: {
43
+ createDisplayMode,
43
44
  enableGlobalFilterRankedResults,
44
45
  enablePagination,
45
46
  enableRowPinning,
@@ -64,6 +65,7 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
64
65
  } = table;
65
66
  const {
66
67
  columnFilters,
68
+ creatingRow,
67
69
  density,
68
70
  draggingRow,
69
71
  expanded,
@@ -222,6 +224,9 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
222
224
  ...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as any),
223
225
  })}
224
226
  >
227
+ {creatingRow && createDisplayMode === 'row' && (
228
+ <MRT_TableBodyRow row={creatingRow} rowIndex={-1} table={table} />
229
+ )}
225
230
  {tableBodyProps?.children ??
226
231
  (!rows.length ? (
227
232
  <tr
@@ -26,7 +26,7 @@ import { type MRT_Cell, type MRT_TableInstance } from '../types';
26
26
  interface Props<TData extends Record<string, any>> {
27
27
  cell: MRT_Cell<TData>;
28
28
  measureElement?: (element: HTMLTableCellElement) => void;
29
- numRows: number;
29
+ numRows?: number;
30
30
  rowIndex: number;
31
31
  rowRef: RefObject<HTMLTableRowElement>;
32
32
  table: MRT_TableInstance<TData>;
@@ -63,6 +63,7 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
63
63
  setHoveredColumn,
64
64
  } = table;
65
65
  const {
66
+ columnSizingInfo,
66
67
  creatingRow,
67
68
  density,
68
69
  draggingColumn,
@@ -118,15 +119,21 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
118
119
  const isHoveredRow = hoveredRow?.id === row.id;
119
120
  const isFirstColumn = getIsFirstColumn(column, table);
120
121
  const isLastColumn = getIsLastColumn(column, table);
121
- const isLastRow = rowIndex === numRows - 1;
122
+ const isLastRow = numRows && rowIndex === numRows - 1;
122
123
 
123
124
  const borderStyle =
124
125
  isDraggingColumn || isDraggingRow
125
126
  ? `1px dashed ${theme.palette.text.secondary} !important`
126
- : isHoveredColumn || isHoveredRow
127
+ : isHoveredColumn ||
128
+ isHoveredRow ||
129
+ columnSizingInfo.isResizingColumn === column.id
127
130
  ? `2px dashed ${theme.palette.primary.main} !important`
128
131
  : undefined;
129
132
 
133
+ if (columnSizingInfo.isResizingColumn === column.id) {
134
+ return { borderRight: borderStyle };
135
+ }
136
+
130
137
  return borderStyle
131
138
  ? {
132
139
  borderBottom:
@@ -148,7 +155,14 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
148
155
  borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined,
149
156
  }
150
157
  : undefined;
151
- }, [draggingColumn, draggingRow, hoveredColumn, hoveredRow, rowIndex]);
158
+ }, [
159
+ columnSizingInfo.isResizingColumn,
160
+ draggingColumn,
161
+ draggingRow,
162
+ hoveredColumn,
163
+ hoveredRow,
164
+ rowIndex,
165
+ ]);
152
166
 
153
167
  const isEditable =
154
168
  parseFromValuesOrFunc(enableEditing, row) &&
@@ -16,7 +16,7 @@ import { type MRT_Cell, type MRT_Row, type MRT_TableInstance } from '../types';
16
16
  interface Props<TData extends Record<string, any>> {
17
17
  columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
18
18
  measureElement?: (element: HTMLTableRowElement) => void;
19
- numRows: number;
19
+ numRows?: number;
20
20
  pinnedRowIds?: string[];
21
21
  row: MRT_Row<TData>;
22
22
  rowIndex: number;
@@ -74,8 +74,7 @@ export const MRT_TableDetailPanel = <TData extends Record<string, any>>({
74
74
  : undefined,
75
75
  borderBottom: !row.getIsExpanded() ? 'none' : undefined,
76
76
  display: layoutMode?.startsWith('grid') ? 'flex' : 'table-cell',
77
- pb: row.getIsExpanded() ? '1rem' : 0,
78
- pt: row.getIsExpanded() ? '1rem' : 0,
77
+ py: row.getIsExpanded() ? '1rem' : 0,
79
78
  transition: 'all 150ms ease-in-out',
80
79
  width: `${table.getTotalSize()}px`,
81
80
  ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
@@ -39,6 +39,7 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
39
39
  setHoveredColumn,
40
40
  } = table;
41
41
  const {
42
+ columnSizingInfo,
42
43
  density,
43
44
  draggingColumn,
44
45
  grouping,
@@ -78,23 +79,30 @@ export const MRT_TableHeadCell = <TData extends Record<string, any>>({
78
79
  return pl;
79
80
  }, [showColumnActions, showDragHandle]);
80
81
 
81
- const draggingBorder = useMemo(
82
- () =>
83
- draggingColumn?.id === column.id
82
+ const draggingBorders = useMemo(() => {
83
+ const borderStyle =
84
+ columnSizingInfo.isResizingColumn === column.id &&
85
+ !header.subHeaders.length
86
+ ? `2px solid ${theme.palette.primary.main} !important`
87
+ : draggingColumn?.id === column.id
84
88
  ? `1px dashed ${theme.palette.text.secondary}`
85
89
  : hoveredColumn?.id === column.id
86
90
  ? `2px dashed ${theme.palette.primary.main}`
87
- : undefined,
88
- [draggingColumn, hoveredColumn],
89
- );
91
+ : undefined;
92
+
93
+ if (columnSizingInfo.isResizingColumn === column.id) {
94
+ return { borderRight: borderStyle };
95
+ }
96
+ const draggingBorders = borderStyle
97
+ ? {
98
+ borderLeft: borderStyle,
99
+ borderRight: borderStyle,
100
+ borderTop: borderStyle,
101
+ }
102
+ : undefined;
90
103
 
91
- const draggingBorders = draggingBorder
92
- ? {
93
- borderLeft: draggingBorder,
94
- borderRight: draggingBorder,
95
- borderTop: draggingBorder,
96
- }
97
- : undefined;
104
+ return draggingBorders;
105
+ }, [draggingColumn, hoveredColumn, columnSizingInfo.isResizingColumn]);
98
106
 
99
107
  const handleDragEnter = (_e: DragEvent) => {
100
108
  if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
@@ -42,13 +42,18 @@ export const MRT_TableHeadCellResizeHandle = <
42
42
  sx={(theme) => ({
43
43
  '&:active > hr': {
44
44
  backgroundColor: theme.palette.info.main,
45
- opacity: 1,
45
+ opacity: header.subHeaders.length ? 1 : 0,
46
46
  },
47
47
  cursor: 'col-resize',
48
- mr: density === 'compact' ? '-0.75rem' : '-1rem',
48
+ mr:
49
+ density === 'compact'
50
+ ? '-12px'
51
+ : density === 'comfortable'
52
+ ? '-20px'
53
+ : '-28px',
49
54
  position: 'absolute',
50
55
  px: '4px',
51
- right: '4px',
56
+ right: '0',
52
57
  })}
53
58
  >
54
59
  <Divider
@@ -100,10 +100,10 @@ export const MRT_EditCellTextField = <TData extends Record<string, any>>({
100
100
  }
101
101
  }}
102
102
  label={
103
- ['custom', 'modal'].includes(
103
+ !['custom', 'modal'].includes(
104
104
  (isCreating ? createDisplayMode : editDisplayMode) as string,
105
105
  )
106
- ? column.columnDef.header
106
+ ? columnDef.header
107
107
  : undefined
108
108
  }
109
109
  margin="none"
@@ -119,6 +119,14 @@ export const MRT_EditCellTextField = <TData extends Record<string, any>>({
119
119
  value={value}
120
120
  variant="standard"
121
121
  {...textFieldProps}
122
+ InputProps={{
123
+ disableUnderline: editDisplayMode === 'table',
124
+ ...textFieldProps.InputProps,
125
+ }}
126
+ inputProps={{
127
+ autoComplete: 'new-password', // disable autocomplete and autofill
128
+ ...textFieldProps.inputProps,
129
+ }}
122
130
  onBlur={handleBlur}
123
131
  onChange={handleChange}
124
132
  onClick={(e) => {
@@ -52,7 +52,7 @@ export const MRT_TablePaper = <TData extends Record<string, any>>({
52
52
  right: 0,
53
53
  top: 0,
54
54
  width: '100vw',
55
- zIndex: 10,
55
+ zIndex: 9999,
56
56
  }
57
57
  : {}),
58
58
  ...tablePaperProps?.style,
@@ -62,8 +62,9 @@ export const MRT_TablePagination = <TData extends Record<string, any> = {}>({
62
62
  sx={{
63
63
  alignItems: 'center',
64
64
  display: 'flex',
65
+ flexWrap: 'wrap',
65
66
  gap: '8px',
66
- justifyContent: 'space-between',
67
+ justifyContent: { md: 'space-between', sm: 'center' },
67
68
  justifySelf: 'flex-end',
68
69
  mt:
69
70
  position === 'top' &&
@@ -83,11 +84,12 @@ export const MRT_TablePagination = <TData extends Record<string, any> = {}>({
83
84
  {localization.rowsPerPage}
84
85
  </InputLabel>
85
86
  <Select
87
+ disableUnderline
86
88
  id="mrt-rows-per-page"
87
89
  inputProps={{ 'aria-label': localization.rowsPerPage }}
88
90
  label={localization.rowsPerPage}
89
91
  onChange={(event) => setPageSize(+event.target.value)}
90
- sx={{ '&::before': { border: 'none' }, mb: 0 }}
92
+ sx={{ mb: 0 }}
91
93
  value={pageSize}
92
94
  variant="standard"
93
95
  >
@@ -122,6 +124,7 @@ export const MRT_TablePagination = <TData extends Record<string, any> = {}>({
122
124
  ) : paginationDisplayMode === 'default' ? (
123
125
  <>
124
126
  <Typography
127
+ align="center"
125
128
  sx={{ mb: 0, minWidth: '10ch', mx: '4px' }}
126
129
  variant="body2"
127
130
  >{`${