material-react-table 1.4.0-beta.0 → 1.4.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.
@@ -266,7 +266,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnD
266
266
  * @example columnDefType: 'display'
267
267
  */
268
268
  columnDefType?: 'data' | 'display' | 'group';
269
- columnFilterModeOptions?: MRT_FilterOption[] | null;
269
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
270
270
  columns?: MRT_ColumnDef<TData>[];
271
271
  enableClickToCopy?: boolean;
272
272
  enableColumnActions?: boolean;
@@ -405,7 +405,7 @@ export type MRT_DisplayColumnIds = 'mrt-row-actions' | 'mrt-row-drag' | 'mrt-row
405
405
  * @link https://www.material-react-table.com/docs/api/props
406
406
  */
407
407
  export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Omit<Partial<TableOptions<TData>>, 'columns' | 'data' | 'defaultColumn' | 'enableRowSelection' | 'expandRowsFn' | 'getRowId' | 'globalFilterFn' | 'initialState' | 'onStateChange' | 'state'> & {
408
- columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
408
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
409
409
  /**
410
410
  * The columns to display in the table. `accessorKey`s or `accessorFn`s must match keys in the `data` prop.
411
411
  *
@@ -5,7 +5,7 @@ interface Props {
5
5
  enableHover?: boolean;
6
6
  numRows: number;
7
7
  rowIndex: number;
8
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
8
+ rowRef: RefObject<HTMLTableRowElement>;
9
9
  table: MRT_TableInstance;
10
10
  }
11
11
  export declare const MRT_TableBodyCell: FC<Props>;
@@ -2,7 +2,7 @@ import { FC, RefObject } from 'react';
2
2
  import { MRT_Cell, MRT_TableInstance } from '..';
3
3
  interface Props {
4
4
  cell: MRT_Cell;
5
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
5
+ rowRef: RefObject<HTMLTableRowElement>;
6
6
  table: MRT_TableInstance;
7
7
  }
8
8
  export declare const MRT_TableBodyRowGrabHandle: FC<Props>;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_FilterOption, MRT_Row, MRT_TableInstance, MRT_TableState, MaterialReactTableProps, MRT_Localization } from '..';
3
3
  export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(props: Omit<Partial<import("@tanstack/react-table").TableOptions<TData>>, "state" | "data" | "onStateChange" | "initialState" | "getRowId" | "columns" | "defaultColumn" | "globalFilterFn" | "enableRowSelection" | "expandRowsFn"> & {
4
- columnFilterModeOptions?: (string | (string & Record<never, never>))[] | null | undefined;
4
+ columnFilterModeOptions?: (string & MRT_FilterOption)[] | null | undefined;
5
5
  columns: MRT_ColumnDef<TData>[];
6
6
  data: TData[];
7
7
  defaultColumn?: Partial<MRT_ColumnDef<TData>> | undefined;
package/dist/index.d.ts CHANGED
@@ -389,7 +389,7 @@ type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnDef<TDat
389
389
  * @example columnDefType: 'display'
390
390
  */
391
391
  columnDefType?: 'data' | 'display' | 'group';
392
- columnFilterModeOptions?: MRT_FilterOption[] | null;
392
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
393
393
  columns?: MRT_ColumnDef<TData>[];
394
394
  enableClickToCopy?: boolean;
395
395
  enableColumnActions?: boolean;
@@ -528,7 +528,7 @@ type MRT_DisplayColumnIds = 'mrt-row-actions' | 'mrt-row-drag' | 'mrt-row-expand
528
528
  * @link https://www.material-react-table.com/docs/api/props
529
529
  */
530
530
  type MaterialReactTableProps<TData extends Record<string, any> = {}> = Omit<Partial<TableOptions<TData>>, 'columns' | 'data' | 'defaultColumn' | 'enableRowSelection' | 'expandRowsFn' | 'getRowId' | 'globalFilterFn' | 'initialState' | 'onStateChange' | 'state'> & {
531
- columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
531
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
532
532
  /**
533
533
  * The columns to display in the table. `accessorKey`s or `accessorFn`s must match keys in the `data` prop.
534
534
  *
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.0-beta.0",
2
+ "version": "1.4.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.",
@@ -361,7 +361,9 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
361
361
  * @example columnDefType: 'display'
362
362
  */
363
363
  columnDefType?: 'data' | 'display' | 'group';
364
- columnFilterModeOptions?: MRT_FilterOption[] | null;
364
+ columnFilterModeOptions?: Array<
365
+ LiteralUnion<string & MRT_FilterOption>
366
+ > | null;
365
367
  columns?: MRT_ColumnDef<TData>[];
366
368
  enableClickToCopy?: boolean;
367
369
  enableColumnActions?: boolean;
@@ -619,7 +621,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
619
621
  | 'onStateChange'
620
622
  | 'state'
621
623
  > & {
622
- columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
624
+ columnFilterModeOptions?: Array<
625
+ LiteralUnion<string & MRT_FilterOption>
626
+ > | null;
623
627
  /**
624
628
  * The columns to display in the table. `accessorKey`s or `accessorFn`s must match keys in the `data` prop.
625
629
  *
@@ -120,8 +120,6 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
120
120
 
121
121
  return (
122
122
  <TableBody
123
- component={layoutMode === 'grid' ? 'div' : 'tbody'}
124
- role="rowgroup"
125
123
  {...tableBodyProps}
126
124
  sx={(theme) => ({
127
125
  display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
@@ -131,13 +129,18 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
131
129
  })}
132
130
  >
133
131
  {tableBodyProps?.children ?? !rows.length ? (
134
- <tr>
135
- <td colSpan={table.getVisibleLeafColumns().length}>
132
+ <tr style={{ display: layoutMode === 'grid' ? 'grid' : 'table-row' }}>
133
+ <td
134
+ colSpan={table.getVisibleLeafColumns().length}
135
+ style={{ display: layoutMode === 'grid' ? 'grid' : 'table-cell' }}
136
+ >
136
137
  <Typography
137
138
  sx={{
138
139
  color: 'text.secondary',
139
140
  fontStyle: 'italic',
140
- maxWidth: `min(100vw, ${tablePaperRef.current?.clientWidth}px)`,
141
+ maxWidth: `min(100vw, ${
142
+ tablePaperRef.current?.clientWidth ?? 360
143
+ }px)`,
141
144
  py: '2rem',
142
145
  textAlign: 'center',
143
146
  width: '100%',
@@ -23,7 +23,7 @@ interface Props {
23
23
  enableHover?: boolean;
24
24
  numRows: number;
25
25
  rowIndex: number;
26
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
26
+ rowRef: RefObject<HTMLTableRowElement>;
27
27
  table: MRT_TableInstance;
28
28
  }
29
29
 
@@ -169,8 +169,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
169
169
 
170
170
  return (
171
171
  <TableCell
172
- component={layoutMode === 'grid' ? 'div' : 'td'}
173
- role="gridcell"
174
172
  {...tableCellProps}
175
173
  onDragEnter={handleDragEnter}
176
174
  onDoubleClick={handleDoubleClick}
@@ -47,7 +47,7 @@ export const MRT_TableBodyRow: FC<Props> = ({
47
47
  }
48
48
  };
49
49
 
50
- const rowRef = useRef<HTMLDivElement | HTMLTableRowElement | null>(null);
50
+ const rowRef = useRef<HTMLTableRowElement | null>(null);
51
51
 
52
52
  const draggingBorder = useMemo(
53
53
  () =>
@@ -68,17 +68,15 @@ export const MRT_TableBodyRow: FC<Props> = ({
68
68
  return (
69
69
  <>
70
70
  <TableRow
71
- component={layoutMode === 'grid' ? 'div' : 'tr'}
72
71
  hover
73
72
  onDragEnter={handleDragEnter}
74
73
  selected={row.getIsSelected()}
75
- ref={(node: HTMLTableRowElement | HTMLDivElement) => {
74
+ ref={(node: HTMLTableRowElement) => {
76
75
  rowRef.current = node;
77
76
  if (virtualRow?.measureRef) {
78
77
  virtualRow.measureRef = node;
79
78
  }
80
79
  }}
81
- role="row"
82
80
  {...tableRowProps}
83
81
  sx={(theme) => ({
84
82
  backgroundColor: lighten(theme.palette.background.default, 0.06),
@@ -4,7 +4,7 @@ import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
4
4
 
5
5
  interface Props {
6
6
  cell: MRT_Cell;
7
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
7
+ rowRef: RefObject<HTMLTableRowElement>;
8
8
  table: MRT_TableInstance;
9
9
  }
10
10
 
@@ -14,6 +14,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
14
14
  getVisibleLeafColumns,
15
15
  getState,
16
16
  options: {
17
+ layoutMode,
17
18
  muiTableBodyRowProps,
18
19
  muiTableDetailPanelProps,
19
20
  renderDetailPanel,
@@ -32,7 +33,12 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
32
33
  : muiTableDetailPanelProps;
33
34
 
34
35
  return (
35
- <TableRow {...tableRowProps}>
36
+ <TableRow
37
+ sx={{
38
+ display: layoutMode === 'grid' ? 'flex' : 'table-row',
39
+ }}
40
+ {...tableRowProps}
41
+ >
36
42
  <TableCell
37
43
  colSpan={getVisibleLeafColumns().length}
38
44
  {...tableCellProps}
@@ -274,7 +274,6 @@ export const getCommonCellStyles = ({
274
274
  table.options.layoutMode === 'grid'
275
275
  ? `${column.getSize()} 0 auto`
276
276
  : undefined,
277
- maxWidth: `min(${column.getSize()}px, fit-content)`,
278
277
  minWidth: `max(${column.getSize()}px, ${column.columnDef.minSize ?? 30}px)`,
279
278
  width: header?.getSize() ?? column.getSize(),
280
279
  });
@@ -12,7 +12,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
12
12
  const {
13
13
  getFooterGroups,
14
14
  getState,
15
- options: { enableStickyFooter, muiTableFooterProps },
15
+ options: { enableStickyFooter, layoutMode, muiTableFooterProps },
16
16
  } = table;
17
17
  const { isFullScreen } = getState();
18
18
 
@@ -30,6 +30,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
30
30
  sx={(theme) => ({
31
31
  backgroundColor: lighten(theme.palette.background.default, 0.06),
32
32
  bottom: stickFooter ? 0 : undefined,
33
+ display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
33
34
  opacity: stickFooter ? 0.97 : undefined,
34
35
  outline: stickFooter
35
36
  ? theme.palette.mode === 'light'
@@ -11,7 +11,7 @@ interface Props {
11
11
  export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
12
12
  const {
13
13
  getState,
14
- options: { muiTableFooterCellProps },
14
+ options: { layoutMode, muiTableFooterCellProps },
15
15
  } = table;
16
16
  const { density } = getState();
17
17
  const { column } = footer;
@@ -40,7 +40,9 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
40
40
  variant="head"
41
41
  {...tableCellProps}
42
42
  sx={(theme) => ({
43
+ display: layoutMode === 'grid' ? 'grid' : 'table-cell',
43
44
  fontWeight: 'bold',
45
+ justifyContent: columnDefType === 'group' ? 'center' : undefined,
44
46
  p:
45
47
  density === 'compact'
46
48
  ? '0.5rem'
@@ -10,7 +10,7 @@ interface Props {
10
10
 
11
11
  export const MRT_TableFooterRow: FC<Props> = ({ footerGroup, table }) => {
12
12
  const {
13
- options: { muiTableFooterRowProps },
13
+ options: { layoutMode, muiTableFooterRowProps },
14
14
  } = table;
15
15
 
16
16
  // if no content in row, skip row
@@ -30,7 +30,15 @@ export const MRT_TableFooterRow: FC<Props> = ({ footerGroup, table }) => {
30
30
  : muiTableFooterRowProps;
31
31
 
32
32
  return (
33
- <TableRow {...tableRowProps}>
33
+ <TableRow
34
+ {...tableRowProps}
35
+ sx={(theme) => ({
36
+ display: layoutMode === 'grid' ? 'flex' : 'table-row',
37
+ ...(tableRowProps?.sx instanceof Function
38
+ ? tableRowProps?.sx(theme)
39
+ : (tableRowProps?.sx as any)),
40
+ })}
41
+ >
34
42
  {footerGroup.headers.map((footer: MRT_Header) => (
35
43
  <MRT_TableFooterCell footer={footer} key={footer.id} table={table} />
36
44
  ))}
@@ -30,12 +30,12 @@ export const MRT_TableHead: FC<Props> = ({ table }) => {
30
30
 
31
31
  return (
32
32
  <TableHead
33
- component={layoutMode === 'grid' ? 'div' : 'thead'}
34
- role="rowgroup"
35
33
  {...tableHeadProps}
36
34
  sx={(theme) => ({
35
+ display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
37
36
  opacity: 0.97,
38
- position: stickyHeader ? 'sticky' : undefined,
37
+ position: stickyHeader ? 'sticky' : 'relative',
38
+ top: stickyHeader && layoutMode === 'grid' ? 0 : undefined,
39
39
  zIndex: stickyHeader ? 2 : undefined,
40
40
  ...(tableHeadProps?.sx instanceof Function
41
41
  ? tableHeadProps?.sx(theme)
@@ -121,7 +121,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
121
121
  return (
122
122
  <TableCell
123
123
  align={columnDefType === 'group' ? 'center' : 'left'}
124
- component={layoutMode === 'grid' ? 'div' : 'td'}
125
124
  colSpan={header.colSpan}
126
125
  onDragEnter={handleDragEnter}
127
126
  ref={(node) => {
@@ -129,7 +128,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
129
128
  tableHeadCellRefs.current[column.id] = node as HTMLTableCellElement;
130
129
  }
131
130
  }}
132
- role="columnheader"
133
131
  {...tableCellProps}
134
132
  sx={(theme: Theme) => ({
135
133
  flexDirection: layoutMode === 'grid' ? 'column' : undefined,
@@ -16,6 +16,8 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
16
16
  icons: { FilterAltIcon },
17
17
  localization,
18
18
  },
19
+ refs: { filterInputRefs },
20
+ setShowFilters,
19
21
  } = table;
20
22
  const { column } = header;
21
23
  const { columnDef } = column;
@@ -64,6 +66,11 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
64
66
  <IconButton
65
67
  disableRipple
66
68
  onClick={(event: MouseEvent<HTMLButtonElement>) => {
69
+ setShowFilters(true);
70
+ queueMicrotask(() => {
71
+ filterInputRefs.current[`${column.id}-0`]?.focus();
72
+ filterInputRefs.current[`${column.id}-0`]?.select();
73
+ });
67
74
  event.stopPropagation();
68
75
  }}
69
76
  size="small"
@@ -21,13 +21,12 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, table }) => {
21
21
 
22
22
  return (
23
23
  <TableRow
24
- component={layoutMode === 'grid' ? 'div' : 'tr'}
25
- role="row"
26
24
  {...tableRowProps}
27
25
  sx={(theme) => ({
26
+ backgroundColor: lighten(theme.palette.background.default, 0.04),
28
27
  boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
29
28
  display: layoutMode === 'grid' ? 'flex' : 'table-row',
30
- backgroundColor: lighten(theme.palette.background.default, 0.04),
29
+ top: 0,
31
30
  ...(tableRowProps?.sx instanceof Function
32
31
  ? tableRowProps?.sx(theme)
33
32
  : (tableRowProps?.sx as any)),
@@ -32,13 +32,12 @@ export const MRT_Table: FC<Props> = ({ table }) => {
32
32
 
33
33
  return (
34
34
  <Table
35
- component={layoutMode === 'grid' ? 'div' : 'table'}
36
- role="grid"
37
35
  stickyHeader={
38
36
  enableStickyHeader || enableRowVirtualization || isFullScreen
39
37
  }
40
38
  {...tableProps}
41
39
  sx={(theme) => ({
40
+ display: layoutMode === 'grid' ? 'grid' : 'table',
42
41
  tableLayout:
43
42
  enableColumnResizing || enableRowVirtualization ? 'fixed' : 'auto',
44
43
  ...(tableProps?.sx instanceof Function