material-react-table 3.0.3 → 3.2.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.
Files changed (152) hide show
  1. package/dist/index.d.ts +23 -73
  2. package/dist/index.esm.js +130 -107
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +130 -107
  5. package/dist/index.js.map +1 -1
  6. package/locales/ar/index.esm.js +1 -0
  7. package/locales/ar/index.js +1 -0
  8. package/locales/az/index.esm.js +1 -0
  9. package/locales/az/index.js +1 -0
  10. package/locales/bg/index.esm.js +1 -0
  11. package/locales/bg/index.js +1 -0
  12. package/locales/cs/index.esm.js +1 -0
  13. package/locales/cs/index.js +1 -0
  14. package/locales/da/index.esm.js +1 -0
  15. package/locales/da/index.js +1 -0
  16. package/locales/de/index.esm.js +1 -0
  17. package/locales/de/index.js +1 -0
  18. package/locales/el/index.esm.js +1 -0
  19. package/locales/el/index.js +1 -0
  20. package/locales/en/index.esm.js +1 -0
  21. package/locales/en/index.js +1 -0
  22. package/locales/es/index.esm.js +1 -0
  23. package/locales/es/index.js +1 -0
  24. package/locales/et/index.esm.js +1 -0
  25. package/locales/et/index.js +1 -0
  26. package/locales/fa/index.esm.js +1 -0
  27. package/locales/fa/index.js +1 -0
  28. package/locales/fi/index.esm.js +1 -0
  29. package/locales/fi/index.js +1 -0
  30. package/locales/fr/index.esm.js +1 -0
  31. package/locales/fr/index.js +1 -0
  32. package/locales/he/index.esm.js +1 -0
  33. package/locales/he/index.js +1 -0
  34. package/locales/hr/index.esm.js +1 -0
  35. package/locales/hr/index.js +1 -0
  36. package/locales/hu/index.esm.js +1 -0
  37. package/locales/hu/index.js +1 -0
  38. package/locales/hy/index.esm.js +1 -0
  39. package/locales/hy/index.js +1 -0
  40. package/locales/id/index.esm.js +1 -0
  41. package/locales/id/index.js +1 -0
  42. package/locales/it/index.esm.js +1 -0
  43. package/locales/it/index.js +1 -0
  44. package/locales/ja/index.esm.js +1 -0
  45. package/locales/ja/index.js +1 -0
  46. package/locales/ko/index.esm.js +1 -0
  47. package/locales/ko/index.js +1 -0
  48. package/locales/nl/index.esm.js +1 -0
  49. package/locales/nl/index.js +1 -0
  50. package/locales/no/index.esm.js +1 -0
  51. package/locales/no/index.js +1 -0
  52. package/locales/np/index.esm.js +1 -0
  53. package/locales/np/index.js +1 -0
  54. package/locales/pl/index.esm.js +1 -0
  55. package/locales/pl/index.js +1 -0
  56. package/locales/pt/index.esm.js +1 -0
  57. package/locales/pt/index.js +1 -0
  58. package/locales/pt-BR/index.esm.js +1 -0
  59. package/locales/pt-BR/index.js +1 -0
  60. package/locales/ro/index.esm.js +1 -0
  61. package/locales/ro/index.js +1 -0
  62. package/locales/ru/index.esm.js +1 -0
  63. package/locales/ru/index.js +1 -0
  64. package/locales/sk/index.esm.js +1 -0
  65. package/locales/sk/index.js +1 -0
  66. package/locales/sr-Cyrl-RS/index.esm.js +1 -0
  67. package/locales/sr-Cyrl-RS/index.js +1 -0
  68. package/locales/sr-Latn-RS/index.esm.js +1 -0
  69. package/locales/sr-Latn-RS/index.js +1 -0
  70. package/locales/sv/index.esm.js +1 -0
  71. package/locales/sv/index.js +1 -0
  72. package/locales/tr/index.esm.js +1 -0
  73. package/locales/tr/index.js +1 -0
  74. package/locales/uk/index.esm.js +1 -0
  75. package/locales/uk/index.js +1 -0
  76. package/locales/vi/index.esm.js +1 -0
  77. package/locales/vi/index.js +1 -0
  78. package/locales/zh-Hans/index.esm.js +1 -0
  79. package/locales/zh-Hans/index.js +1 -0
  80. package/locales/zh-Hant/index.esm.js +1 -0
  81. package/locales/zh-Hant/index.js +1 -0
  82. package/package.json +31 -32
  83. package/src/components/body/MRT_TableBodyCell.tsx +2 -2
  84. package/src/components/body/MRT_TableBodyCellValue.tsx +1 -1
  85. package/src/components/body/MRT_TableBodyRow.tsx +1 -1
  86. package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +1 -1
  87. package/src/components/body/MRT_TableDetailPanel.tsx +1 -1
  88. package/src/components/buttons/MRT_EditActionButtons.tsx +2 -2
  89. package/src/components/footer/MRT_TableFooter.tsx +1 -1
  90. package/src/components/head/MRT_TableHead.tsx +1 -1
  91. package/src/components/head/MRT_TableHeadCell.tsx +2 -2
  92. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +8 -10
  93. package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +1 -1
  94. package/src/components/inputs/MRT_EditCellTextField.tsx +5 -3
  95. package/src/components/inputs/MRT_FilterRangeSlider.tsx +12 -5
  96. package/src/components/inputs/MRT_FilterTextField.tsx +106 -70
  97. package/src/components/menus/MRT_ColumnActionMenu.tsx +3 -2
  98. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +12 -0
  99. package/src/components/table/MRT_TableContainer.tsx +1 -1
  100. package/src/components/table/MRT_TablePaper.tsx +1 -1
  101. package/src/components/toolbar/MRT_BottomToolbar.tsx +1 -1
  102. package/src/components/toolbar/MRT_TablePagination.tsx +5 -3
  103. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +4 -4
  104. package/src/components/toolbar/MRT_TopToolbar.tsx +1 -1
  105. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +1 -1
  106. package/src/hooks/useMRT_ColumnVirtualizer.ts +1 -1
  107. package/src/hooks/useMRT_Effects.ts +3 -3
  108. package/src/hooks/useMRT_RowVirtualizer.ts +17 -5
  109. package/src/hooks/useMRT_TableInstance.ts +1 -1
  110. package/src/locales/ar.ts +1 -0
  111. package/src/locales/az.ts +1 -0
  112. package/src/locales/bg.ts +1 -0
  113. package/src/locales/cs.ts +1 -0
  114. package/src/locales/da.ts +1 -0
  115. package/src/locales/de.ts +1 -0
  116. package/src/locales/el.ts +1 -0
  117. package/src/locales/en.ts +1 -0
  118. package/src/locales/es.ts +1 -0
  119. package/src/locales/et.ts +1 -0
  120. package/src/locales/fa.ts +1 -0
  121. package/src/locales/fi.ts +1 -0
  122. package/src/locales/fr.ts +1 -0
  123. package/src/locales/he.ts +1 -0
  124. package/src/locales/hr.ts +1 -0
  125. package/src/locales/hu.ts +1 -0
  126. package/src/locales/hy.ts +1 -0
  127. package/src/locales/id.ts +1 -0
  128. package/src/locales/it.ts +1 -0
  129. package/src/locales/ja.ts +1 -0
  130. package/src/locales/ko.ts +1 -0
  131. package/src/locales/nl.ts +1 -0
  132. package/src/locales/no.ts +1 -0
  133. package/src/locales/np.ts +1 -0
  134. package/src/locales/pl.ts +1 -0
  135. package/src/locales/pt-BR.ts +1 -0
  136. package/src/locales/pt.ts +1 -0
  137. package/src/locales/ro.ts +1 -0
  138. package/src/locales/ru.ts +1 -0
  139. package/src/locales/sk.ts +1 -0
  140. package/src/locales/sr-Cyrl-RS.ts +1 -0
  141. package/src/locales/sr-Latn-RS.ts +1 -0
  142. package/src/locales/sv.ts +1 -0
  143. package/src/locales/tr.ts +1 -0
  144. package/src/locales/uk.ts +1 -0
  145. package/src/locales/vi.ts +1 -0
  146. package/src/locales/zh-Hans.ts +1 -0
  147. package/src/locales/zh-Hant.ts +1 -0
  148. package/src/types.ts +17 -67
  149. package/src/utils/cell.utils.ts +2 -2
  150. package/src/utils/column.utils.ts +1 -1
  151. package/src/utils/tanstack.helpers.ts +1 -1
  152. package/src/utils/virtualization.utils.ts +5 -0
package/src/types.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  type Dispatch,
3
- type MutableRefObject,
4
3
  type ReactNode,
5
4
  type RefObject,
6
5
  type SetStateAction,
@@ -151,6 +150,8 @@ export type MRT_ColumnHelper<TData extends MRT_RowData> = {
151
150
  };
152
151
 
153
152
  export interface MRT_Localization {
153
+ // language of the localization as BCP 47 language tag for number formatting
154
+ language: string;
154
155
  actions: string;
155
156
  and: string;
156
157
  cancel: string;
@@ -308,18 +309,18 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
308
309
  getTopRows: () => MRT_Row<TData>[];
309
310
  options: MRT_StatefulTableOptions<TData>;
310
311
  refs: {
311
- actionCellRef: MutableRefObject<HTMLTableCellElement | null>;
312
- bottomToolbarRef: MutableRefObject<HTMLDivElement | null>;
313
- editInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
314
- filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
315
- lastSelectedRowId: MutableRefObject<null | string>;
316
- searchInputRef: MutableRefObject<HTMLInputElement | null>;
317
- tableContainerRef: MutableRefObject<HTMLDivElement | null>;
318
- tableFooterRef: MutableRefObject<HTMLTableSectionElement | null>;
319
- tableHeadCellRefs: MutableRefObject<Record<string, HTMLTableCellElement>>;
320
- tableHeadRef: MutableRefObject<HTMLTableSectionElement | null>;
321
- tablePaperRef: MutableRefObject<HTMLDivElement | null>;
322
- topToolbarRef: MutableRefObject<HTMLDivElement | null>;
312
+ actionCellRef: RefObject<HTMLTableCellElement | null>;
313
+ bottomToolbarRef: RefObject<HTMLDivElement | null>;
314
+ editInputRefs: RefObject<Record<string, HTMLInputElement> | null>;
315
+ filterInputRefs: RefObject<Record<string, HTMLInputElement> | null>;
316
+ lastSelectedRowId: RefObject<null | string>;
317
+ searchInputRef: RefObject<HTMLInputElement | null>;
318
+ tableContainerRef: RefObject<HTMLDivElement | null>;
319
+ tableFooterRef: RefObject<HTMLTableSectionElement | null>;
320
+ tableHeadCellRefs: RefObject<Record<string, HTMLTableCellElement> | null>;
321
+ tableHeadRef: RefObject<HTMLTableSectionElement | null>;
322
+ tablePaperRef: RefObject<HTMLDivElement | null>;
323
+ topToolbarRef: RefObject<HTMLDivElement | null>;
323
324
  };
324
325
  setActionCell: Dispatch<SetStateAction<MRT_Cell<TData> | null>>;
325
326
  setColumnFilterFns: Dispatch<SetStateAction<MRT_ColumnFilterFnsState>>;
@@ -442,7 +443,7 @@ export interface MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown>
442
443
  column: MRT_Column<TData, TValue>;
443
444
  renderedCellValue: ReactNode;
444
445
  row: MRT_Row<TData>;
445
- rowRef?: RefObject<HTMLTableRowElement>;
446
+ rowRef?: RefObject<HTMLTableRowElement | null>;
446
447
  staticColumnIndex?: number;
447
448
  staticRowIndex?: number;
448
449
  table: MRT_TableInstance<TData>;
@@ -824,7 +825,7 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
824
825
  * @link https://www.material-react-table.com/docs/api/column-options
825
826
  */
826
827
  columns: MRT_ColumnDef<TData, any>[];
827
- columnVirtualizerInstanceRef?: MutableRefObject<MRT_ColumnVirtualizer | null>;
828
+ columnVirtualizerInstanceRef?: RefObject<MRT_ColumnVirtualizer | null>;
828
829
  columnVirtualizerOptions?:
829
830
  | ((props: {
830
831
  table: MRT_TableInstance<TData>;
@@ -923,27 +924,18 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
923
924
  table: MRT_TableInstance<TData>;
924
925
  }) => CircularProgressProps & { Component?: ReactNode })
925
926
  | (CircularProgressProps & { Component?: ReactNode });
926
- /**
927
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
928
- */
929
927
  muiColumnActionsButtonProps?:
930
928
  | ((props: {
931
929
  column: MRT_Column<TData>;
932
930
  table: MRT_TableInstance<TData>;
933
931
  }) => IconButtonProps)
934
932
  | IconButtonProps;
935
- /**
936
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
937
- */
938
933
  muiColumnDragHandleProps?:
939
934
  | ((props: {
940
935
  column: MRT_Column<TData>;
941
936
  table: MRT_TableInstance<TData>;
942
937
  }) => IconButtonProps)
943
938
  | IconButtonProps;
944
- /**
945
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
946
- */
947
939
  muiCopyButtonProps?:
948
940
  | ((props: {
949
941
  cell: MRT_Cell<TData>;
@@ -970,9 +962,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
970
962
  table: MRT_TableInstance<TData>;
971
963
  }) => DialogProps)
972
964
  | DialogProps;
973
- /**
974
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
975
- */
976
965
  muiEditTextFieldProps?:
977
966
  | ((props: {
978
967
  cell: MRT_Cell<TData>;
@@ -991,27 +980,18 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
991
980
  table: MRT_TableInstance<TData>;
992
981
  }) => IconButtonProps)
993
982
  | IconButtonProps;
994
- /**
995
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
996
- */
997
983
  muiFilterAutocompleteProps?:
998
984
  | ((props: {
999
985
  column: MRT_Column<TData>;
1000
986
  table: MRT_TableInstance<TData>;
1001
987
  }) => AutocompleteProps<any, any, any, any>)
1002
988
  | AutocompleteProps<any, any, any, any>;
1003
- /**
1004
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1005
- */
1006
989
  muiFilterCheckboxProps?:
1007
990
  | ((props: {
1008
991
  column: MRT_Column<TData>;
1009
992
  table: MRT_TableInstance<TData>;
1010
993
  }) => CheckboxProps)
1011
994
  | CheckboxProps;
1012
- /**
1013
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1014
- */
1015
995
  muiFilterDatePickerProps?:
1016
996
  | ((props: {
1017
997
  column: MRT_Column<TData>;
@@ -1019,9 +999,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1019
999
  table: MRT_TableInstance<TData>;
1020
1000
  }) => DatePickerProps<never>)
1021
1001
  | DatePickerProps<never>;
1022
- /**
1023
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1024
- */
1025
1002
  muiFilterDateTimePickerProps?:
1026
1003
  | ((props: {
1027
1004
  column: MRT_Column<TData>;
@@ -1029,18 +1006,12 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1029
1006
  table: MRT_TableInstance<TData>;
1030
1007
  }) => DateTimePickerProps<never>)
1031
1008
  | DateTimePickerProps<never>;
1032
- /**
1033
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1034
- */
1035
1009
  muiFilterSliderProps?:
1036
1010
  | ((props: {
1037
1011
  column: MRT_Column<TData>;
1038
1012
  table: MRT_TableInstance<TData>;
1039
1013
  }) => SliderProps)
1040
1014
  | SliderProps;
1041
- /**
1042
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1043
- */
1044
1015
  muiFilterTextFieldProps?:
1045
1016
  | ((props: {
1046
1017
  column: MRT_Column<TData>;
@@ -1048,9 +1019,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1048
1019
  table: MRT_TableInstance<TData>;
1049
1020
  }) => TextFieldProps)
1050
1021
  | TextFieldProps;
1051
- /**
1052
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1053
- */
1054
1022
  muiFilterTimePickerProps?:
1055
1023
  | ((props: {
1056
1024
  column: MRT_Column<TData>;
@@ -1108,9 +1076,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1108
1076
  table: MRT_TableInstance<TData>;
1109
1077
  }) => SkeletonProps)
1110
1078
  | SkeletonProps;
1111
- /**
1112
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1113
- */
1114
1079
  muiTableBodyCellProps?:
1115
1080
  | ((props: {
1116
1081
  cell: MRT_Cell<TData>;
@@ -1133,9 +1098,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1133
1098
  muiTableContainerProps?:
1134
1099
  | ((props: { table: MRT_TableInstance<TData> }) => TableContainerProps)
1135
1100
  | TableContainerProps;
1136
- /**
1137
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1138
- */
1139
1101
  muiTableFooterCellProps?:
1140
1102
  | ((props: {
1141
1103
  column: MRT_Column<TData>;
@@ -1151,9 +1113,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1151
1113
  table: MRT_TableInstance<TData>;
1152
1114
  }) => TableRowProps)
1153
1115
  | TableRowProps;
1154
- /**
1155
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1156
- */
1157
1116
  muiTableHeadCellProps?:
1158
1117
  | ((props: {
1159
1118
  column: MRT_Column<TData>;
@@ -1237,9 +1196,6 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1237
1196
  renderCaption?:
1238
1197
  | ((props: { table: MRT_TableInstance<TData> }) => ReactNode)
1239
1198
  | ReactNode;
1240
- /**
1241
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1242
- */
1243
1199
  renderCellActionMenuItems?: (props: {
1244
1200
  cell: MRT_Cell<TData>;
1245
1201
  closeMenu: () => void;
@@ -1250,18 +1206,12 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1250
1206
  staticRowIndex?: number;
1251
1207
  table: MRT_TableInstance<TData>;
1252
1208
  }) => ReactNode[];
1253
- /**
1254
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1255
- */
1256
1209
  renderColumnActionsMenuItems?: (props: {
1257
1210
  closeMenu: () => void;
1258
1211
  column: MRT_Column<TData>;
1259
1212
  internalColumnMenuItems: ReactNode[];
1260
1213
  table: MRT_TableInstance<TData>;
1261
1214
  }) => ReactNode[];
1262
- /**
1263
- * @deprecated Specify this in the `defaultColumn` table option instead if you want to apply to all columns.
1264
- */
1265
1215
  renderColumnFilterModeMenuItems?: (props: {
1266
1216
  column: MRT_Column<TData>;
1267
1217
  internalFilterOptions: MRT_InternalFilterOption[];
@@ -1325,7 +1275,7 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
1325
1275
  | 'sticky'
1326
1276
  | 'top'
1327
1277
  | 'top-and-bottom';
1328
- rowVirtualizerInstanceRef?: MutableRefObject<MRT_RowVirtualizer | null>;
1278
+ rowVirtualizerInstanceRef?: RefObject<MRT_RowVirtualizer | null>;
1329
1279
  rowVirtualizerOptions?:
1330
1280
  | ((props: {
1331
1281
  table: MRT_TableInstance<TData>;
@@ -52,7 +52,7 @@ export const openEditingCell = <TData extends MRT_RowData>({
52
52
  if (isCellEditable({ cell, table }) && editDisplayMode === 'cell') {
53
53
  table.setEditingCell(cell);
54
54
  queueMicrotask(() => {
55
- const textField = editInputRefs.current[column.id];
55
+ const textField = editInputRefs.current?.[column.id];
56
56
  if (textField) {
57
57
  textField.focus();
58
58
  textField.select?.();
@@ -92,7 +92,7 @@ export const cellKeyboardShortcuts = <TData extends MRT_RowData = MRT_RowData>({
92
92
  getMRT_RowSelectionHandler({
93
93
  row: cell.row,
94
94
  table,
95
- //@ts-ignore
95
+ //@ts-expect-error
96
96
  staticRowIndex: +event.target.getAttribute('data-index'),
97
97
  })(event as any);
98
98
  } else if (
@@ -85,7 +85,7 @@ export const prepareColumns = <TData extends MRT_RowData>({
85
85
 
86
86
  //assign sortingFns
87
87
  if (Object.keys(sortingFns).includes(columnDef.sortingFn as string)) {
88
- // @ts-ignore
88
+ // @ts-expect-error
89
89
  columnDef.sortingFn = sortingFns[columnDef.sortingFn];
90
90
  }
91
91
  } else if (columnDef.columnDefType === 'display') {
@@ -1,4 +1,4 @@
1
- import { type ReactNode } from 'react';
1
+ import { type ReactNode, type JSX } from 'react';
2
2
  import {
3
3
  createRow as _createRow,
4
4
  flexRender as _flexRender,
@@ -1,5 +1,10 @@
1
1
  import { type Range, defaultRangeExtractor } from '@tanstack/react-virtual';
2
2
 
3
+ /**
4
+ * When scroll, the `draggingRow` or `draggingColumn` can be removed from document because of virtualization,
5
+ * then, the `dragEnd` event on `MRT_TableBodyRowGrabHandle` or `MRT_TableHeadCellGrabHandle` will not fire.
6
+ * We should keep the `draggingRow` or `draggingColumn` in `getVirtualItems()` to avoid this thing.
7
+ */
3
8
  export const extraIndexRangeExtractor = (
4
9
  range: Range,
5
10
  draggingIndex?: number,