material-react-table 1.9.0 → 1.9.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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
2
+ import { type VirtualItem, type Virtualizer } from '@tanstack/react-virtual';
3
3
  import type { MRT_TableInstance } from '..';
4
4
  interface Props {
5
5
  columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
@@ -1,7 +1,7 @@
1
- import type { Row } from '@tanstack/react-table';
2
1
  import { MRT_AggregationFns } from './aggregationFns';
3
2
  import { MRT_FilterFns } from './filterFns';
4
3
  import { MRT_SortingFns } from './sortingFns';
4
+ import type { Row } from '@tanstack/react-table';
5
5
  import type { TableCellProps } from '@mui/material/TableCell';
6
6
  import type { Theme } from '@mui/material/styles';
7
7
  import type { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_ColumnOrderState, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterOption, MRT_GroupingState, MRT_Header, MRT_TableInstance } from '.';
@@ -1,5 +1,5 @@
1
1
  import { RankingInfo } from '@tanstack/match-sorter-utils';
2
- import { Row } from '@tanstack/react-table';
2
+ import { type Row } from '@tanstack/react-table';
3
3
  export declare const MRT_FilterFns: {
4
4
  between: {
5
5
  <TData extends Record<string, any> = {}>(row: Row<TData>, id: string, filterValues: [string | number, string | number]): boolean;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { VirtualItem } from '@tanstack/react-virtual';
2
+ import type { VirtualItem } from '@tanstack/react-virtual';
3
3
  import type { MRT_HeaderGroup, MRT_TableInstance } from '..';
4
4
  interface Props {
5
5
  footerGroup: MRT_HeaderGroup;
@@ -1,5 +1,5 @@
1
- import { Row } from '@tanstack/react-table';
2
- import { MRT_Row } from '.';
1
+ import { type Row } from '@tanstack/react-table';
2
+ import type { MRT_Row } from '.';
3
3
  export declare const MRT_SortingFns: {
4
4
  fuzzy: <TData extends Record<string, any> = {}>(rowA: Row<TData>, rowB: Row<TData>, columnId: string) => number;
5
5
  alphanumeric: import("@tanstack/react-table").SortingFn<any>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.0",
2
+ "version": "1.9.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.",
@@ -50,7 +50,7 @@ import type {
50
50
  TableOptions,
51
51
  TableState,
52
52
  Updater,
53
- VisibilityState
53
+ VisibilityState,
54
54
  } from '@tanstack/react-table';
55
55
  import type {
56
56
  VirtualizerOptions,
@@ -1,8 +1,8 @@
1
1
  import React, { memo, useMemo } from 'react';
2
2
  import {
3
3
  useVirtualizer,
4
- VirtualItem,
5
- Virtualizer,
4
+ type VirtualItem,
5
+ type Virtualizer,
6
6
  } from '@tanstack/react-virtual';
7
7
  import TableBody from '@mui/material/TableBody';
8
8
  import Typography from '@mui/material/Typography';
@@ -1,6 +1,6 @@
1
1
  import React, { DragEvent, memo, useRef } from 'react';
2
2
  import TableRow from '@mui/material/TableRow';
3
- import { darken, lighten } from '@mui/material/styles';
3
+ import { alpha, darken, lighten } from '@mui/material/styles';
4
4
  import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
5
5
  import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
6
6
  import type { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
@@ -86,7 +86,9 @@ export const MRT_TableBodyRow = ({
86
86
  '&:hover td': {
87
87
  backgroundColor:
88
88
  tableRowProps?.hover !== false
89
- ? theme.palette.mode === 'dark'
89
+ ? row.getIsSelected()
90
+ ? `${alpha(theme.palette.primary.main, 0.2)}`
91
+ : theme.palette.mode === 'dark'
90
92
  ? `${lighten(theme.palette.background.default, 0.12)}`
91
93
  : `${darken(theme.palette.background.default, 0.05)}`
92
94
  : undefined,
@@ -1,8 +1,8 @@
1
- import type { Row } from '@tanstack/react-table';
2
1
  import { MRT_AggregationFns } from './aggregationFns';
3
2
  import { MRT_FilterFns } from './filterFns';
4
3
  import { MRT_SortingFns } from './sortingFns';
5
4
  import { alpha, lighten } from '@mui/material/styles';
5
+ import type { Row } from '@tanstack/react-table';
6
6
  import type { TableCellProps } from '@mui/material/TableCell';
7
7
  import type { Theme } from '@mui/material/styles';
8
8
  import type {
package/src/filterFns.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { rankItem, rankings, RankingInfo } from '@tanstack/match-sorter-utils';
2
- import { filterFns, Row } from '@tanstack/react-table';
2
+ import { filterFns, type Row } from '@tanstack/react-table';
3
3
 
4
4
  const fuzzy = <TData extends Record<string, any> = {}>(
5
5
  row: Row<TData>,
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import TableRow from '@mui/material/TableRow';
3
3
  import { lighten } from '@mui/material/styles';
4
4
  import { MRT_TableFooterCell } from './MRT_TableFooterCell';
5
- import { VirtualItem } from '@tanstack/react-virtual';
5
+ import type { VirtualItem } from '@tanstack/react-virtual';
6
6
  import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
7
7
 
8
8
  interface Props {
@@ -149,7 +149,7 @@ export const MRT_FilterTextField = ({
149
149
  } else if (isRangeFilter) {
150
150
  setFilterValue('');
151
151
  column.setFilterValue((old: [string | undefined, string | undefined]) => {
152
- const newFilterValues = old ?? ['', ''];
152
+ const newFilterValues = (Array.isArray(old) && old) || ['', ''];
153
153
  newFilterValues[rangeFilterIndex as number] = undefined;
154
154
  return newFilterValues;
155
155
  });
@@ -99,6 +99,10 @@ export const mrtFilterOptions = (
99
99
  },
100
100
  ];
101
101
 
102
+ const rangeModes = ['between', 'betweenInclusive', 'inNumberRange'];
103
+ const emptyModes = ['empty', 'notEmpty'];
104
+ const arrModes = ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'];
105
+
102
106
  interface Props<TData extends Record<string, any> = {}> {
103
107
  anchorEl: HTMLElement | null;
104
108
  header?: MRT_Header<TData>;
@@ -150,46 +154,66 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
150
154
  );
151
155
 
152
156
  const handleSelectFilterMode = (option: MRT_FilterOption) => {
153
- if (header && column) {
157
+ const prevFilterMode = columnDef?._filterFn ?? '';
158
+ if (!header || !column) {
159
+ // global filter mode
160
+ setGlobalFilterFn(option);
161
+ } else if (option !== prevFilterMode) {
162
+ // column filter mode
154
163
  setColumnFilterFns((prev: { [key: string]: any }) => ({
155
164
  ...prev,
156
165
  [header.id]: option,
157
166
  }));
158
- if (['empty', 'notEmpty'].includes(option as string)) {
159
- column.setFilterValue(' ');
167
+
168
+ // reset filter value and/or perform new filter render
169
+ if (emptyModes.includes(option)) {
170
+ // will now be empty/notEmpty filter mode
171
+ if (
172
+ currentFilterValue !== ' ' &&
173
+ !emptyModes.includes(prevFilterMode)
174
+ ) {
175
+ column.setFilterValue(' ');
176
+ } else if (currentFilterValue) {
177
+ column.setFilterValue(currentFilterValue); // perform new filter render
178
+ }
160
179
  } else if (
161
180
  columnDef?.filterVariant === 'multi-select' ||
162
- ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'].includes(
163
- option as string,
164
- )
181
+ arrModes.includes(option as string)
165
182
  ) {
183
+ // will now be array filter mode
166
184
  if (
167
185
  currentFilterValue instanceof String ||
168
186
  (currentFilterValue as Array<any>)?.length
169
187
  ) {
170
188
  column.setFilterValue([]);
171
189
  setFilterValue?.([]);
190
+ } else if (currentFilterValue) {
191
+ column.setFilterValue(currentFilterValue); // perform new filter render
172
192
  }
173
193
  } else if (
174
194
  columnDef?.filterVariant === 'range' ||
175
- ['between', 'betweenInclusive', 'inNumberRange'].includes(
176
- option as MRT_FilterOption,
177
- )
195
+ rangeModes.includes(option as MRT_FilterOption)
178
196
  ) {
179
- if (!(currentFilterValue as Array<any>)?.every((v) => v === '')) {
197
+ // will now be range filter mode
198
+ if (
199
+ !Array.isArray(currentFilterValue) ||
200
+ (!(currentFilterValue as Array<any>)?.every((v) => v === '') &&
201
+ !rangeModes.includes(prevFilterMode))
202
+ ) {
180
203
  column.setFilterValue(['', '']);
181
204
  setFilterValue?.('');
205
+ } else {
206
+ column.setFilterValue(currentFilterValue); // perform new filter render
182
207
  }
183
208
  } else {
184
- if (
185
- !['', undefined].includes(currentFilterValue as string | undefined)
186
- ) {
209
+ // will now be single value filter mode
210
+ if (Array.isArray(currentFilterValue)) {
187
211
  column.setFilterValue('');
188
212
  setFilterValue?.('');
213
+ } else {
214
+ column.setFilterValue(currentFilterValue); // perform new filter render
189
215
  }
190
216
  }
191
- } else {
192
- setGlobalFilterFn(option);
193
217
  }
194
218
  setAnchorEl(null);
195
219
  onSelect?.();
package/src/sortingFns.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { compareItems, RankingInfo } from '@tanstack/match-sorter-utils';
2
- import { Row, sortingFns } from '@tanstack/react-table';
3
- import { MRT_Row } from '.';
1
+ import { compareItems, type RankingInfo } from '@tanstack/match-sorter-utils';
2
+ import { type Row, sortingFns } from '@tanstack/react-table';
3
+ import type { MRT_Row } from '.';
4
4
 
5
5
  const fuzzy = <TData extends Record<string, any> = {}>(
6
6
  rowA: Row<TData>,
@@ -1,9 +1,9 @@
1
1
  import React, { useCallback, useMemo } from 'react';
2
2
  import {
3
3
  defaultRangeExtractor,
4
- Range,
5
4
  useVirtualizer,
6
- Virtualizer,
5
+ type Range,
6
+ type Virtualizer,
7
7
  } from '@tanstack/react-virtual';
8
8
  import Table from '@mui/material/Table';
9
9
  import { MRT_TableHead } from '../head/MRT_TableHead';
@@ -26,7 +26,7 @@ import {
26
26
  showExpandColumn,
27
27
  getColumnId,
28
28
  } from '../column.utils';
29
- import {
29
+ import type {
30
30
  MRT_Cell,
31
31
  MRT_Column,
32
32
  MRT_ColumnDef,