@mui/x-data-grid 7.24.0 → 7.25.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 (228) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/DataGrid/DataGrid.js +1 -7
  3. package/DataGrid/useDataGridComponent.d.ts +2 -1
  4. package/components/GridRow.d.ts +0 -1
  5. package/components/GridRow.js +25 -19
  6. package/components/cell/GridCell.d.ts +9 -6
  7. package/components/cell/GridCell.js +29 -52
  8. package/components/columnHeaders/GridColumnHeaderFilterIconButton.d.ts +3 -3
  9. package/components/columnHeaders/GridColumnHeaderFilterIconButton.js +21 -7
  10. package/components/containers/GridRootStyles.js +135 -37
  11. package/components/panel/GridPanel.js +2 -1
  12. package/components/panel/filterPanel/GridFilterInputValueProps.d.ts +2 -1
  13. package/components/toolbar/GridToolbarColumnsButton.js +8 -2
  14. package/components/toolbar/GridToolbarDensitySelector.js +2 -2
  15. package/components/toolbar/GridToolbarExportContainer.js +2 -2
  16. package/components/toolbar/GridToolbarFilterButton.js +8 -2
  17. package/components/virtualization/GridMainContainer.d.ts +10 -0
  18. package/components/virtualization/GridMainContainer.js +10 -2
  19. package/components/virtualization/GridVirtualScrollbar.d.ts +4 -0
  20. package/components/virtualization/GridVirtualScrollbar.js +5 -5
  21. package/components/virtualization/GridVirtualScroller.js +18 -5
  22. package/components/virtualization/GridVirtualScrollerContent.js +11 -2
  23. package/context/GridContextProvider.d.ts +2 -1
  24. package/hooks/core/pipeProcessing/useGridPipeProcessing.d.ts +2 -2
  25. package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.d.ts +2 -2
  26. package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +2 -2
  27. package/hooks/core/strategyProcessing/useGridRegisterStrategyProcessor.d.ts +2 -2
  28. package/hooks/core/strategyProcessing/useGridStrategyProcessing.d.ts +2 -2
  29. package/hooks/core/useGridApiInitialization.d.ts +2 -2
  30. package/hooks/core/useGridInitialization.d.ts +2 -2
  31. package/hooks/core/useGridIsRtl.d.ts +2 -2
  32. package/hooks/core/useGridLocaleText.d.ts +2 -2
  33. package/hooks/core/useGridLoggerFactory.d.ts +2 -2
  34. package/hooks/core/useGridRefs.d.ts +2 -2
  35. package/hooks/core/useGridStateInitialization.d.ts +2 -2
  36. package/hooks/features/clipboard/useGridClipboard.d.ts +2 -2
  37. package/hooks/features/columnGrouping/useGridColumnGrouping.d.ts +2 -2
  38. package/hooks/features/columnMenu/useGridColumnMenu.d.ts +2 -2
  39. package/hooks/features/columnMenu/useGridColumnMenu.js +0 -2
  40. package/hooks/features/columnResize/useGridColumnResize.d.ts +2 -2
  41. package/hooks/features/columnResize/useGridColumnResize.js +2 -1
  42. package/hooks/features/columns/gridColumnsUtils.d.ts +4 -4
  43. package/hooks/features/columns/useGridColumnSpanning.d.ts +2 -2
  44. package/hooks/features/columns/useGridColumns.d.ts +2 -2
  45. package/hooks/features/columns/useGridColumns.js +7 -3
  46. package/hooks/features/density/useGridDensity.d.ts +2 -2
  47. package/hooks/features/dimensions/useGridDimensions.d.ts +2 -2
  48. package/hooks/features/dimensions/useGridDimensions.js +7 -11
  49. package/hooks/features/editing/gridEditingSelectors.d.ts +6 -0
  50. package/hooks/features/editing/gridEditingSelectors.js +7 -1
  51. package/hooks/features/editing/index.d.ts +1 -1
  52. package/hooks/features/editing/index.js +1 -1
  53. package/hooks/features/editing/useGridCellEditing.d.ts +2 -2
  54. package/hooks/features/editing/useGridCellEditing.js +3 -3
  55. package/hooks/features/editing/useGridEditing.d.ts +2 -2
  56. package/hooks/features/editing/useGridRowEditing.d.ts +2 -2
  57. package/hooks/features/editing/useGridRowEditing.js +5 -6
  58. package/hooks/features/events/useGridEvents.d.ts +2 -2
  59. package/hooks/features/export/serializers/csvSerializer.d.ts +2 -1
  60. package/hooks/features/export/useGridCsvExport.d.ts +2 -2
  61. package/hooks/features/export/useGridPrintExport.d.ts +2 -2
  62. package/hooks/features/export/utils.d.ts +2 -2
  63. package/hooks/features/filter/gridFilterUtils.d.ts +7 -7
  64. package/hooks/features/filter/gridFilterUtils.js +3 -3
  65. package/hooks/features/filter/useGridFilter.d.ts +2 -2
  66. package/hooks/features/focus/useGridFocus.d.ts +2 -2
  67. package/hooks/features/focus/useGridFocus.js +3 -2
  68. package/hooks/features/headerFiltering/useGridHeaderFiltering.d.ts +2 -2
  69. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +2 -2
  70. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
  71. package/hooks/features/keyboardNavigation/utils.d.ts +3 -4
  72. package/hooks/features/keyboardNavigation/utils.js +0 -5
  73. package/hooks/features/listView/useGridListView.d.ts +2 -2
  74. package/hooks/features/listView/useGridListView.js +2 -1
  75. package/hooks/features/pagination/useGridPagination.d.ts +2 -2
  76. package/hooks/features/pagination/useGridPaginationMeta.d.ts +2 -2
  77. package/hooks/features/pagination/useGridPaginationModel.d.ts +2 -2
  78. package/hooks/features/pagination/useGridRowCount.d.ts +2 -2
  79. package/hooks/features/preferencesPanel/gridPreferencePanelSelector.d.ts +1 -0
  80. package/hooks/features/preferencesPanel/gridPreferencePanelSelector.js +8 -1
  81. package/hooks/features/preferencesPanel/index.d.ts +1 -1
  82. package/hooks/features/preferencesPanel/index.js +1 -1
  83. package/hooks/features/preferencesPanel/useGridPreferencesPanel.d.ts +2 -2
  84. package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +14 -38
  85. package/hooks/features/rowSelection/useGridRowSelection.d.ts +2 -2
  86. package/hooks/features/rowSelection/useGridRowSelection.js +3 -3
  87. package/hooks/features/rowSelection/useGridRowSelectionPreProcessors.d.ts +2 -2
  88. package/hooks/features/rowSelection/utils.d.ts +3 -2
  89. package/hooks/features/rows/gridRowSpanningUtils.d.ts +2 -2
  90. package/hooks/features/rows/gridRowsUtils.d.ts +4 -4
  91. package/hooks/features/rows/useGridParamsApi.d.ts +2 -2
  92. package/hooks/features/rows/useGridParamsApi.js +33 -14
  93. package/hooks/features/rows/useGridRowSpanning.d.ts +2 -2
  94. package/hooks/features/rows/useGridRowSpanning.js +94 -91
  95. package/hooks/features/rows/useGridRows.d.ts +2 -2
  96. package/hooks/features/rows/useGridRows.js +7 -8
  97. package/hooks/features/rows/useGridRowsMeta.d.ts +2 -2
  98. package/hooks/features/rows/useGridRowsMeta.js +3 -2
  99. package/hooks/features/rows/useGridRowsPreProcessors.d.ts +2 -2
  100. package/hooks/features/scroll/useGridScroll.d.ts +2 -2
  101. package/hooks/features/sorting/gridSortingUtils.d.ts +3 -3
  102. package/hooks/features/sorting/gridSortingUtils.js +2 -2
  103. package/hooks/features/sorting/useGridSorting.d.ts +2 -2
  104. package/hooks/features/statePersistence/useGridStatePersistence.d.ts +2 -2
  105. package/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  106. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +9 -1
  107. package/hooks/features/virtualization/useGridVirtualScroller.js +32 -53
  108. package/hooks/features/virtualization/useGridVirtualization.d.ts +2 -2
  109. package/hooks/utils/useGridApiContext.d.ts +2 -2
  110. package/hooks/utils/useGridApiEventHandler.d.ts +4 -4
  111. package/hooks/utils/useGridApiMethod.d.ts +2 -2
  112. package/hooks/utils/useGridApiRef.d.ts +2 -2
  113. package/hooks/utils/useGridApiRef.js +3 -1
  114. package/hooks/utils/useGridInitializeState.d.ts +3 -3
  115. package/hooks/utils/useGridLogger.d.ts +2 -2
  116. package/hooks/utils/useGridNativeEventListener.d.ts +2 -1
  117. package/hooks/utils/useGridPrivateApiContext.d.ts +2 -1
  118. package/hooks/utils/useGridSelector.d.ts +3 -3
  119. package/hooks/utils/useGridVisibleRows.d.ts +3 -3
  120. package/index.js +1 -1
  121. package/locales/faIR.js +5 -6
  122. package/models/api/gridApiCommon.d.ts +2 -2
  123. package/models/api/gridParamsApi.d.ts +29 -2
  124. package/models/api/index.d.ts +1 -1
  125. package/models/api/index.js +0 -1
  126. package/models/colDef/gridColDef.d.ts +9 -8
  127. package/models/gridExport.d.ts +2 -2
  128. package/models/gridFilterOperator.d.ts +2 -1
  129. package/models/props/DataGridProps.d.ts +2 -1
  130. package/modern/DataGrid/DataGrid.js +1 -7
  131. package/modern/components/GridRow.js +25 -19
  132. package/modern/components/cell/GridCell.js +29 -52
  133. package/modern/components/columnHeaders/GridColumnHeaderFilterIconButton.js +21 -7
  134. package/modern/components/containers/GridRootStyles.js +135 -37
  135. package/modern/components/panel/GridPanel.js +2 -1
  136. package/modern/components/toolbar/GridToolbarColumnsButton.js +8 -2
  137. package/modern/components/toolbar/GridToolbarDensitySelector.js +2 -2
  138. package/modern/components/toolbar/GridToolbarExportContainer.js +2 -2
  139. package/modern/components/toolbar/GridToolbarFilterButton.js +8 -2
  140. package/modern/components/virtualization/GridMainContainer.js +10 -2
  141. package/modern/components/virtualization/GridVirtualScrollbar.js +5 -5
  142. package/modern/components/virtualization/GridVirtualScroller.js +18 -5
  143. package/modern/components/virtualization/GridVirtualScrollerContent.js +11 -2
  144. package/modern/hooks/features/columnMenu/useGridColumnMenu.js +0 -2
  145. package/modern/hooks/features/columnResize/useGridColumnResize.js +2 -1
  146. package/modern/hooks/features/columns/useGridColumns.js +7 -3
  147. package/modern/hooks/features/dimensions/useGridDimensions.js +7 -11
  148. package/modern/hooks/features/editing/gridEditingSelectors.js +7 -1
  149. package/modern/hooks/features/editing/index.js +1 -1
  150. package/modern/hooks/features/editing/useGridCellEditing.js +3 -3
  151. package/modern/hooks/features/editing/useGridRowEditing.js +5 -6
  152. package/modern/hooks/features/filter/gridFilterUtils.js +3 -3
  153. package/modern/hooks/features/focus/useGridFocus.js +3 -2
  154. package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
  155. package/modern/hooks/features/keyboardNavigation/utils.js +0 -5
  156. package/modern/hooks/features/listView/useGridListView.js +2 -1
  157. package/modern/hooks/features/preferencesPanel/gridPreferencePanelSelector.js +8 -1
  158. package/modern/hooks/features/preferencesPanel/index.js +1 -1
  159. package/modern/hooks/features/preferencesPanel/useGridPreferencesPanel.js +14 -38
  160. package/modern/hooks/features/rowSelection/useGridRowSelection.js +3 -3
  161. package/modern/hooks/features/rows/useGridParamsApi.js +33 -14
  162. package/modern/hooks/features/rows/useGridRowSpanning.js +94 -91
  163. package/modern/hooks/features/rows/useGridRows.js +7 -8
  164. package/modern/hooks/features/rows/useGridRowsMeta.js +3 -2
  165. package/modern/hooks/features/sorting/gridSortingUtils.js +2 -2
  166. package/modern/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  167. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +32 -53
  168. package/modern/hooks/utils/useGridApiRef.js +3 -1
  169. package/modern/index.js +1 -1
  170. package/modern/locales/faIR.js +5 -6
  171. package/modern/models/api/index.js +0 -1
  172. package/modern/utils/isJSDOM.js +1 -0
  173. package/modern/utils/roundToDecimalPlaces.js +3 -0
  174. package/modern/utils/utils.js +6 -1
  175. package/node/DataGrid/DataGrid.js +1 -7
  176. package/node/components/GridRow.js +22 -16
  177. package/node/components/cell/GridCell.js +27 -50
  178. package/node/components/columnHeaders/GridColumnHeaderFilterIconButton.js +20 -6
  179. package/node/components/containers/GridRootStyles.js +135 -37
  180. package/node/components/panel/GridPanel.js +2 -1
  181. package/node/components/toolbar/GridToolbarColumnsButton.js +8 -2
  182. package/node/components/toolbar/GridToolbarDensitySelector.js +2 -2
  183. package/node/components/toolbar/GridToolbarExportContainer.js +2 -2
  184. package/node/components/toolbar/GridToolbarFilterButton.js +8 -2
  185. package/node/components/virtualization/GridMainContainer.js +10 -2
  186. package/node/components/virtualization/GridVirtualScrollbar.js +5 -5
  187. package/node/components/virtualization/GridVirtualScroller.js +18 -5
  188. package/node/components/virtualization/GridVirtualScrollerContent.js +11 -2
  189. package/node/hooks/features/columnMenu/useGridColumnMenu.js +0 -2
  190. package/node/hooks/features/columnResize/useGridColumnResize.js +2 -1
  191. package/node/hooks/features/columns/useGridColumns.js +7 -3
  192. package/node/hooks/features/dimensions/useGridDimensions.js +9 -13
  193. package/node/hooks/features/editing/gridEditingSelectors.js +8 -2
  194. package/node/hooks/features/editing/index.js +7 -11
  195. package/node/hooks/features/editing/useGridCellEditing.js +2 -2
  196. package/node/hooks/features/editing/useGridRowEditing.js +3 -4
  197. package/node/hooks/features/filter/gridFilterUtils.js +3 -3
  198. package/node/hooks/features/focus/useGridFocus.js +3 -2
  199. package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -15
  200. package/node/hooks/features/keyboardNavigation/utils.js +0 -6
  201. package/node/hooks/features/listView/useGridListView.js +2 -1
  202. package/node/hooks/features/preferencesPanel/gridPreferencePanelSelector.js +9 -2
  203. package/node/hooks/features/preferencesPanel/index.js +11 -10
  204. package/node/hooks/features/preferencesPanel/useGridPreferencesPanel.js +14 -38
  205. package/node/hooks/features/rowSelection/useGridRowSelection.js +2 -2
  206. package/node/hooks/features/rows/useGridParamsApi.js +33 -14
  207. package/node/hooks/features/rows/useGridRowSpanning.js +92 -89
  208. package/node/hooks/features/rows/useGridRows.js +7 -8
  209. package/node/hooks/features/rows/useGridRowsMeta.js +5 -4
  210. package/node/hooks/features/sorting/gridSortingUtils.js +2 -2
  211. package/node/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  212. package/node/hooks/features/virtualization/useGridVirtualScroller.js +34 -55
  213. package/node/hooks/utils/useGridApiRef.js +3 -1
  214. package/node/index.js +1 -1
  215. package/node/locales/faIR.js +5 -6
  216. package/node/models/api/index.js +0 -11
  217. package/node/utils/isJSDOM.js +7 -0
  218. package/node/utils/roundToDecimalPlaces.js +9 -0
  219. package/node/utils/utils.js +8 -1
  220. package/package.json +2 -2
  221. package/utils/createSelector.d.ts +3 -3
  222. package/utils/getPublicApiRef.d.ts +2 -1
  223. package/utils/isJSDOM.d.ts +1 -0
  224. package/utils/isJSDOM.js +1 -0
  225. package/utils/roundToDecimalPlaces.d.ts +1 -0
  226. package/utils/roundToDecimalPlaces.js +3 -0
  227. package/utils/utils.d.ts +1 -0
  228. package/utils/utils.js +6 -1
@@ -20,9 +20,11 @@ import { GridVirtualScrollerFiller as SpaceFiller } from "./GridVirtualScrollerF
20
20
  import { GridVirtualScrollerRenderZone as RenderZone } from "./GridVirtualScrollerRenderZone.js";
21
21
  import { GridVirtualScrollbar as Scrollbar } from "./GridVirtualScrollbar.js";
22
22
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
- const useUtilityClasses = (ownerState, dimensions, loadingOverlayVariant) => {
23
+ const useUtilityClasses = ownerState => {
24
24
  const {
25
- classes
25
+ classes,
26
+ dimensions,
27
+ loadingOverlayVariant
26
28
  } = ownerState;
27
29
  const slots = {
28
30
  root: ['main', dimensions.rightPinnedWidth > 0 && 'main--hasPinnedRight', loadingOverlayVariant === 'skeleton' && 'main--hasSkeletonLoadingOverlay'],
@@ -33,7 +35,12 @@ const useUtilityClasses = (ownerState, dimensions, loadingOverlayVariant) => {
33
35
  const Scroller = styled('div', {
34
36
  name: 'MuiDataGrid',
35
37
  slot: 'VirtualScroller',
36
- overridesResolver: (props, styles) => styles.virtualScroller
38
+ overridesResolver: (props, styles) => {
39
+ const {
40
+ ownerState
41
+ } = props;
42
+ return [styles.virtualScroller, ownerState.dimensions.hasScrollX && styles['virtualScroller--hasScrollX']];
43
+ }
37
44
  })({
38
45
  position: 'relative',
39
46
  height: '100%',
@@ -56,7 +63,12 @@ function GridVirtualScroller(props) {
56
63
  const rootProps = useGridRootProps();
57
64
  const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
58
65
  const overlaysProps = useGridOverlays();
59
- const classes = useUtilityClasses(rootProps, dimensions, overlaysProps.loadingOverlayVariant);
66
+ const ownerState = {
67
+ classes: rootProps.classes,
68
+ dimensions,
69
+ loadingOverlayVariant: overlaysProps.loadingOverlayVariant
70
+ };
71
+ const classes = useUtilityClasses(ownerState);
60
72
  const virtualScroller = useGridVirtualScroller();
61
73
  const {
62
74
  getContainerProps,
@@ -71,6 +83,7 @@ function GridVirtualScroller(props) {
71
83
  return /*#__PURE__*/_jsxs(Container, _extends({
72
84
  className: classes.root
73
85
  }, getContainerProps(), {
86
+ ownerState: ownerState,
74
87
  children: [/*#__PURE__*/_jsx(GridScrollArea, {
75
88
  scrollDirection: "left"
76
89
  }), /*#__PURE__*/_jsx(GridScrollArea, {
@@ -78,7 +91,7 @@ function GridVirtualScroller(props) {
78
91
  }), /*#__PURE__*/_jsxs(Scroller, _extends({
79
92
  className: classes.scroller
80
93
  }, getScrollerProps(), {
81
- ownerState: rootProps,
94
+ ownerState: ownerState,
82
95
  children: [/*#__PURE__*/_jsxs(TopContainer, {
83
96
  children: [!rootProps.unstable_listView && /*#__PURE__*/_jsx(GridHeaders, {}), /*#__PURE__*/_jsx(rootProps.slots.pinnedRows, {
84
97
  position: "top",
@@ -19,14 +19,23 @@ const useUtilityClasses = (props, overflowedContent) => {
19
19
  const VirtualScrollerContentRoot = styled('div', {
20
20
  name: 'MuiDataGrid',
21
21
  slot: 'VirtualScrollerContent',
22
- overridesResolver: (props, styles) => styles.virtualScrollerContent
22
+ overridesResolver: (props, styles) => {
23
+ const {
24
+ ownerState
25
+ } = props;
26
+ return [styles.virtualScrollerContent, ownerState.overflowedContent && styles['virtualScrollerContent--overflowed']];
27
+ }
23
28
  })({});
24
29
  const GridVirtualScrollerContent = forwardRef(function GridVirtualScrollerContent(props, ref) {
25
30
  const rootProps = useGridRootProps();
26
31
  const overflowedContent = !rootProps.autoHeight && props.style?.minHeight === 'auto';
27
32
  const classes = useUtilityClasses(rootProps, overflowedContent);
33
+ const ownerState = {
34
+ classes: rootProps.classes,
35
+ overflowedContent
36
+ };
28
37
  return /*#__PURE__*/_jsx(VirtualScrollerContentRoot, _extends({}, props, {
29
- ownerState: rootProps,
38
+ ownerState: ownerState,
30
39
  className: clsx(classes.root, props.className),
31
40
  ref: ref
32
41
  }));
@@ -40,7 +40,6 @@ export const useGridColumnMenu = apiRef => {
40
40
  });
41
41
  });
42
42
  apiRef.current.hidePreferences();
43
- apiRef.current.forceUpdate();
44
43
  }
45
44
  }, [apiRef, logger]);
46
45
  const hideColumnMenu = React.useCallback(() => {
@@ -82,7 +81,6 @@ export const useGridColumnMenu = apiRef => {
82
81
  columnMenu: newState
83
82
  });
84
83
  });
85
- apiRef.current.forceUpdate();
86
84
  }
87
85
  }, [apiRef, logger]);
88
86
  const toggleColumnMenu = React.useCallback(field => {
@@ -500,7 +500,8 @@ export const useGridColumnResize = (apiRef, props) => {
500
500
  if (options.expand) {
501
501
  const visibleColumns = state.orderedFields.map(field => state.lookup[field]).filter(c => state.columnVisibilityModel[c.field] !== false);
502
502
  const totalWidth = visibleColumns.reduce((total, column) => total + (widthByField[column.field] ?? column.computedWidth ?? column.width), 0);
503
- const availableWidth = apiRef.current.getRootDimensions().viewportInnerSize.width;
503
+ const dimensions = apiRef.current.getRootDimensions();
504
+ const availableWidth = dimensions.viewportInnerSize.width;
504
505
  const remainingWidth = availableWidth - totalWidth;
505
506
  if (remainingWidth > 0) {
506
507
  const widthPerColumn = remainingWidth / (newColumns.length || 1);
@@ -242,9 +242,13 @@ export function useGridColumns(apiRef, props) {
242
242
  */
243
243
 
244
244
  const prevInnerWidth = React.useRef(null);
245
- const handleGridSizeChange = viewportInnerSize => {
246
- if (prevInnerWidth.current !== viewportInnerSize.width) {
247
- prevInnerWidth.current = viewportInnerSize.width;
245
+ const handleGridSizeChange = size => {
246
+ if (prevInnerWidth.current !== size.width) {
247
+ prevInnerWidth.current = size.width;
248
+ const hasFlexColumns = gridVisibleColumnDefinitionsSelector(apiRef).some(col => col.flex && col.flex > 0);
249
+ if (!hasFlexColumns) {
250
+ return;
251
+ }
248
252
  setGridColumnsState(hydrateColumnsWidth(gridColumnsStateSelector(apiRef.current.state), apiRef.current.getRootDimensions()));
249
253
  }
250
254
  };
@@ -15,6 +15,8 @@ import { gridRowsMetaSelector } from "../rows/gridRowsMetaSelector.js";
15
15
  import { calculatePinnedRowsHeight, getValidRowHeight, rowHeightWarning } from "../rows/gridRowsUtils.js";
16
16
  import { getTotalHeaderHeight } from "../columns/gridColumnsUtils.js";
17
17
  import { DATA_GRID_PROPS_DEFAULT_VALUES } from "../../../constants/dataGridPropsDefaultValues.js";
18
+ import { roundToDecimalPlaces } from "../../../utils/roundToDecimalPlaces.js";
19
+ import { isJSDOM } from "../../../utils/isJSDOM.js";
18
20
  const EMPTY_SIZE = {
19
21
  width: 0,
20
22
  height: 0
@@ -60,7 +62,7 @@ export function useGridDimensions(apiRef, props) {
60
62
  const headerHeight = Math.floor(props.columnHeaderHeight * densityFactor);
61
63
  const groupHeaderHeight = Math.floor((props.columnGroupHeaderHeight ?? props.columnHeaderHeight) * densityFactor);
62
64
  const headerFilterHeight = Math.floor((props.headerFilterHeight ?? props.columnHeaderHeight) * densityFactor);
63
- const columnsTotalWidth = roundToDecimalPlaces(gridColumnsTotalWidthSelector(apiRef), 6);
65
+ const columnsTotalWidth = roundToDecimalPlaces(gridColumnsTotalWidthSelector(apiRef), 1);
64
66
  const headersTotalHeight = getTotalHeaderHeight(apiRef, props);
65
67
  const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
66
68
  const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
@@ -110,6 +112,9 @@ export function useGridDimensions(apiRef, props) {
110
112
  return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
111
113
  }, [apiRef, props.pagination, props.paginationMode, props.getRowHeight, rowHeight]);
112
114
  const updateDimensions = React.useCallback(() => {
115
+ // All the floating point dimensions should be rounded to .1 decimal places to avoid subpixel rendering issues
116
+ // https://github.com/mui/mui-x/issues/9550#issuecomment-1619020477
117
+ // https://github.com/mui/mui-x/issues/15721
113
118
  const rootElement = apiRef.current.rootElementRef.current;
114
119
  const pinnedRowsHeight = calculatePinnedRowsHeight(apiRef);
115
120
  const scrollbarSize = measureScrollbarSize(rootElement, columnsTotalWidth, props.scrollbarSize);
@@ -118,7 +123,7 @@ export function useGridDimensions(apiRef, props) {
118
123
  const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
119
124
  const contentSize = {
120
125
  width: nonPinnedColumnsTotalWidth,
121
- height: rowsMeta.currentPageTotalHeight
126
+ height: roundToDecimalPlaces(rowsMeta.currentPageTotalHeight, 1)
122
127
  };
123
128
  let viewportOuterSize;
124
129
  let viewportInnerSize;
@@ -237,9 +242,6 @@ export function useGridDimensions(apiRef, props) {
237
242
  const isFirstSizing = React.useRef(true);
238
243
  const handleResize = React.useCallback(size => {
239
244
  rootDimensionsRef.current = size;
240
-
241
- // jsdom has no layout capabilities
242
- const isJSDOM = /jsdom|HappyDOM/.test(window.navigator.userAgent);
243
245
  if (size.height === 0 && !errorShown.current && !props.autoHeight && !isJSDOM) {
244
246
  logger.error(['The parent DOM element of the Data Grid has an empty height.', 'Please make sure that this element has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
245
247
  errorShown.current = true;
@@ -282,12 +284,6 @@ function measureScrollbarSize(rootElement, columnsTotalWidth, scrollbarSize) {
282
284
  rootElement.removeChild(scrollDiv);
283
285
  return size;
284
286
  }
285
-
286
- // Get rid of floating point imprecision errors
287
- // https://github.com/mui/mui-x/issues/9550#issuecomment-1619020477
288
- function roundToDecimalPlaces(value, decimals) {
289
- return Math.round(value * 10 ** decimals) / 10 ** decimals;
290
- }
291
287
  function areElementSizesEqual(a, b) {
292
288
  return a.width === b.width && a.height === b.height;
293
289
  }
@@ -1,4 +1,10 @@
1
+ import { createSelectorV8 } from "../../../utils/createSelector.js";
1
2
  /**
2
3
  * Select the row editing state.
3
4
  */
4
- export const gridEditRowsStateSelector = state => state.editRows;
5
+ export const gridEditRowsStateSelector = state => state.editRows;
6
+ export const gridRowIsEditingSelector = createSelectorV8(gridEditRowsStateSelector, (editRows, rowId) => Boolean(editRows[rowId]));
7
+ export const gridEditCellStateSelector = createSelectorV8(gridEditRowsStateSelector, (editRows, {
8
+ rowId,
9
+ field
10
+ }) => editRows[rowId]?.[field] ?? null);
@@ -1 +1 @@
1
- export * from "./gridEditingSelectors.js";
1
+ export { gridEditRowsStateSelector } from "./gridEditingSelectors.js";
@@ -11,7 +11,7 @@ import { GridEditModes, GridCellModes } from "../../../models/gridEditRowModel.j
11
11
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
12
12
  import { gridEditRowsStateSelector } from "./gridEditingSelectors.js";
13
13
  import { isPrintableKey, isPasteShortcut } from "../../../utils/keyboardUtils.js";
14
- import { gridRowsDataRowIdToIdLookupSelector } from "../rows/gridRowsSelector.js";
14
+ import { gridRowsLookupSelector } from "../rows/gridRowsSelector.js";
15
15
  import { deepClone } from "../../../utils/utils.js";
16
16
  import { GridCellEditStartReasons, GridCellEditStopReasons } from "../../../models/params/gridEditCellParams.js";
17
17
  import { getDefaultCellValue } from "./utils.js";
@@ -442,7 +442,7 @@ export const useGridCellEditing = (apiRef, props) => {
442
442
 
443
443
  // Run this effect synchronously so that the keyboard event can impact the yet-to-be-rendered input.
444
444
  useEnhancedEffect(() => {
445
- const idToIdLookup = gridRowsDataRowIdToIdLookupSelector(apiRef);
445
+ const rowsLookup = gridRowsLookupSelector(apiRef);
446
446
 
447
447
  // Update the ref here because updateStateToStopCellEditMode may change it later
448
448
  const copyOfPrevCellModes = prevCellModesModel.current;
@@ -451,7 +451,7 @@ export const useGridCellEditing = (apiRef, props) => {
451
451
  Object.entries(cellModesModel).forEach(([id, fields]) => {
452
452
  Object.entries(fields).forEach(([field, params]) => {
453
453
  const prevMode = copyOfPrevCellModes[id]?.[field]?.mode || GridCellModes.View;
454
- const originalId = idToIdLookup[id] ?? id;
454
+ const originalId = rowsLookup[id] ? apiRef.current.getRowId(rowsLookup[id]) : id;
455
455
  if (params.mode === GridCellModes.Edit && prevMode === GridCellModes.View) {
456
456
  updateStateToStartCellEditMode(_extends({
457
457
  id: originalId,
@@ -9,10 +9,10 @@ import { warnOnce } from '@mui/x-internals/warning';
9
9
  import { useGridApiEventHandler, useGridApiOptionHandler } from "../../utils/useGridApiEventHandler.js";
10
10
  import { GridEditModes, GridRowModes } from "../../../models/gridEditRowModel.js";
11
11
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
12
- import { gridEditRowsStateSelector } from "./gridEditingSelectors.js";
12
+ import { gridEditRowsStateSelector, gridRowIsEditingSelector } from "./gridEditingSelectors.js";
13
13
  import { isPrintableKey, isPasteShortcut } from "../../../utils/keyboardUtils.js";
14
14
  import { gridColumnFieldsSelector, gridVisibleColumnFieldsSelector } from "../columns/gridColumnsSelector.js";
15
- import { gridRowsDataRowIdToIdLookupSelector } from "../rows/gridRowsSelector.js";
15
+ import { gridRowsLookupSelector } from "../rows/gridRowsSelector.js";
16
16
  import { deepClone } from "../../../utils/utils.js";
17
17
  import { GridRowEditStopReasons, GridRowEditStartReasons } from "../../../models/params/gridRowParams.js";
18
18
  import { GRID_ACTIONS_COLUMN_TYPE } from "../../../colDef/index.js";
@@ -235,8 +235,7 @@ export const useGridRowEditing = (apiRef, props) => {
235
235
  if (props.editMode === GridEditModes.Cell) {
236
236
  return GridRowModes.View;
237
237
  }
238
- const editingState = gridEditRowsStateSelector(apiRef.current.state);
239
- const isEditing = editingState[id] && Object.keys(editingState[id]).length > 0;
238
+ const isEditing = gridRowIsEditingSelector(apiRef, id);
240
239
  return isEditing ? GridRowModes.Edit : GridRowModes.View;
241
240
  }, [apiRef, props.editMode]);
242
241
  const updateRowModesModel = useEventCallback(newModel => {
@@ -571,7 +570,7 @@ export const useGridRowEditing = (apiRef, props) => {
571
570
 
572
571
  // Run this effect synchronously so that the keyboard event can impact the yet-to-be-rendered input.
573
572
  useEnhancedEffect(() => {
574
- const idToIdLookup = gridRowsDataRowIdToIdLookupSelector(apiRef);
573
+ const rowsLookup = gridRowsLookupSelector(apiRef);
575
574
 
576
575
  // Update the ref here because updateStateToStopRowEditMode may change it later
577
576
  const copyOfPrevRowModesModel = prevRowModesModel.current;
@@ -583,7 +582,7 @@ export const useGridRowEditing = (apiRef, props) => {
583
582
  mode: GridRowModes.View
584
583
  };
585
584
  const prevMode = copyOfPrevRowModesModel[id]?.mode || GridRowModes.View;
586
- const originalId = idToIdLookup[id] ?? id;
585
+ const originalId = rowsLookup[id] ? apiRef.current.getRowId(rowsLookup[id]) : id;
587
586
  if (params.mode === GridRowModes.Edit && prevMode === GridRowModes.View) {
588
587
  updateStateToStartRowEditMode(_extends({
589
588
  id: originalId
@@ -19,7 +19,7 @@ function getHasEval() {
19
19
  /**
20
20
  * Adds default values to the optional fields of a filter items.
21
21
  * @param {GridFilterItem} item The raw filter item.
22
- * @param {React.RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
22
+ * @param {RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
23
23
  * @return {GridFilterItem} The clean filter item with an uniq ID and an always-defined operator.
24
24
  * TODO: Make the typing reflect the different between GridFilterInputItem and GridFilterItem.
25
25
  */
@@ -133,7 +133,7 @@ let filterItemsApplierId = 1;
133
133
  /**
134
134
  * Generates a method to easily check if a row is matching the current filter model.
135
135
  * @param {GridFilterModel} filterModel The model with which we want to filter the rows.
136
- * @param {React.RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
136
+ * @param {RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
137
137
  * @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
138
138
  */
139
139
  const buildAggregatedFilterItemsApplier = (filterModel, apiRef, disableEval) => {
@@ -181,7 +181,7 @@ export const shouldQuickFilterExcludeHiddenColumns = filterModel => {
181
181
  /**
182
182
  * Generates a method to easily check if a row is matching the current quick filter.
183
183
  * @param {any[]} filterModel The model with which we want to filter the rows.
184
- * @param {React.RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
184
+ * @param {RefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
185
185
  * @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
186
186
  */
187
187
  const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
@@ -326,10 +326,11 @@ export const useGridFocus = (apiRef, props) => {
326
326
  // If the focused cell is in a row which does not exist anymore,
327
327
  // focus previous row or remove the focus
328
328
  if (cell && !apiRef.current.getRow(cell.id)) {
329
- const lastFocusedRowId = gridFocusCellSelector(apiRef)?.id;
329
+ const lastFocusedRowId = cell.id;
330
330
  let nextRowId = null;
331
331
  if (typeof lastFocusedRowId !== 'undefined') {
332
- const lastFocusedRowIndex = apiRef.current.getRowIndexRelativeToVisibleRows(lastFocusedRowId);
332
+ const rowEl = apiRef.current.getRowElement(lastFocusedRowId);
333
+ const lastFocusedRowIndex = rowEl?.dataset.rowindex ? Number(rowEl?.dataset.rowindex) : 0;
333
334
  const currentPage = getVisibleRows(apiRef, {
334
335
  pagination: props.pagination,
335
336
  paginationMode: props.paginationMode
@@ -6,7 +6,6 @@ import { gridVisibleColumnDefinitionsSelector, gridVisibleColumnFieldsSelector }
6
6
  import { useGridLogger } from "../../utils/useGridLogger.js";
7
7
  import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
8
8
  import { gridExpandedSortedRowEntriesSelector } from "../filter/gridFilterSelector.js";
9
- import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
10
9
  import { GRID_CHECKBOX_SELECTION_COL_DEF } from "../../../colDef/gridCheckboxSelectionColDef.js";
11
10
  import { gridClasses } from "../../../constants/gridClasses.js";
12
11
  import { GridCellModes } from "../../../models/gridEditRowModel.js";
@@ -16,8 +15,14 @@ import { gridColumnGroupsHeaderMaxDepthSelector } from "../columnGrouping/gridCo
16
15
  import { gridHeaderFilteringEditFieldSelector, gridHeaderFilteringMenuSelector } from "../headerFiltering/gridHeaderFilteringSelectors.js";
17
16
  import { useGridRegisterPipeProcessor } from "../../core/pipeProcessing/index.js";
18
17
  import { isEventTargetInPortal } from "../../../utils/domUtils.js";
19
- import { enrichPageRowsWithPinnedRows, getLeftColumnIndex, getRightColumnIndex, findNonRowSpannedCell } from "./utils.js";
18
+ import { getLeftColumnIndex, getRightColumnIndex, findNonRowSpannedCell } from "./utils.js";
20
19
  import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
20
+ import { createSelectorMemoized } from "../../../utils/createSelector.js";
21
+ import { gridVisibleRowsSelector } from "../pagination/index.js";
22
+ import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
23
+ const gridVisibleRowsWithPinnedRowsSelector = createSelectorMemoized(gridVisibleRowsSelector, gridPinnedRowsSelector, (visibleRows, pinnedRows) => {
24
+ return (pinnedRows.top || []).concat(visibleRows.rows, pinnedRows.bottom || []);
25
+ });
21
26
 
22
27
  /**
23
28
  * @requires useGridSorting (method) - can be after
@@ -30,10 +35,11 @@ import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
30
35
  */
31
36
  export const useGridKeyboardNavigation = (apiRef, props) => {
32
37
  const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
33
- const initialCurrentPageRows = useGridVisibleRows(apiRef, props).rows;
34
38
  const isRtl = useRtl();
35
39
  const listView = props.unstable_listView;
36
- const currentPageRows = React.useMemo(() => enrichPageRowsWithPinnedRows(apiRef, initialCurrentPageRows), [apiRef, initialCurrentPageRows]);
40
+ const getCurrentPageRows = React.useCallback(() => {
41
+ return gridVisibleRowsWithPinnedRowsSelector(apiRef);
42
+ }, [apiRef]);
37
43
  const headerFilteringEnabled = props.signature !== 'DataGrid' && props.headerFilters;
38
44
 
39
45
  /**
@@ -92,8 +98,8 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
92
98
  apiRef.current.setColumnGroupHeaderFocus(field, depth, event);
93
99
  }, [apiRef, logger]);
94
100
  const getRowIdFromIndex = React.useCallback(rowIndex => {
95
- return currentPageRows[rowIndex]?.id;
96
- }, [currentPageRows]);
101
+ return getCurrentPageRows()[rowIndex]?.id;
102
+ }, [getCurrentPageRows]);
97
103
  const handleColumnHeaderKeyDown = React.useCallback((params, event) => {
98
104
  const headerTitleNode = event.currentTarget.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`);
99
105
  const isFromInsideContent = !!headerTitleNode && headerTitleNode.contains(event.target);
@@ -102,6 +108,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
102
108
  // There is one exception for the checkBoxHeader
103
109
  return;
104
110
  }
111
+ const currentPageRows = getCurrentPageRows();
105
112
  const viewportPageSize = apiRef.current.getViewportPageSize();
106
113
  const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
107
114
  const firstRowIndexInPage = currentPageRows.length > 0 ? 0 : null;
@@ -113,12 +120,10 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
113
120
  switch (event.key) {
114
121
  case 'ArrowDown':
115
122
  {
116
- if (firstRowIndexInPage !== null) {
117
- if (headerFilteringEnabled) {
118
- goToHeaderFilter(colIndexBefore, event);
119
- } else {
120
- goToCell(colIndexBefore, getRowIdFromIndex(firstRowIndexInPage));
121
- }
123
+ if (headerFilteringEnabled) {
124
+ goToHeaderFilter(colIndexBefore, event);
125
+ } else if (firstRowIndexInPage !== null) {
126
+ goToCell(colIndexBefore, getRowIdFromIndex(firstRowIndexInPage));
122
127
  }
123
128
  break;
124
129
  }
@@ -192,13 +197,14 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
192
197
  if (shouldPreventDefault) {
193
198
  event.preventDefault();
194
199
  }
195
- }, [apiRef, currentPageRows.length, headerFilteringEnabled, goToHeaderFilter, goToCell, getRowIdFromIndex, isRtl, goToHeader, goToGroupHeader]);
200
+ }, [apiRef, getCurrentPageRows, headerFilteringEnabled, goToHeaderFilter, goToCell, getRowIdFromIndex, isRtl, goToHeader, goToGroupHeader]);
196
201
  const handleHeaderFilterKeyDown = React.useCallback((params, event) => {
197
202
  const isEditing = gridHeaderFilteringEditFieldSelector(apiRef) === params.field;
198
203
  const isHeaderMenuOpen = gridHeaderFilteringMenuSelector(apiRef) === params.field;
199
204
  if (isEditing || isHeaderMenuOpen || !isNavigationKey(event.key)) {
200
205
  return;
201
206
  }
207
+ const currentPageRows = getCurrentPageRows();
202
208
  const viewportPageSize = apiRef.current.getViewportPageSize();
203
209
  const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
204
210
  const firstRowIndexInPage = 0;
@@ -278,7 +284,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
278
284
  if (shouldPreventDefault) {
279
285
  event.preventDefault();
280
286
  }
281
- }, [apiRef, currentPageRows.length, goToHeaderFilter, isRtl, goToHeader, goToCell, getRowIdFromIndex]);
287
+ }, [apiRef, getCurrentPageRows, goToHeaderFilter, isRtl, goToHeader, goToCell, getRowIdFromIndex]);
282
288
  const handleColumnGroupHeaderKeyDown = React.useCallback((params, event) => {
283
289
  const focusedColumnGroup = gridFocusColumnGroupHeaderSelector(apiRef);
284
290
  if (focusedColumnGroup === null) {
@@ -293,6 +299,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
293
299
  depth,
294
300
  maxDepth
295
301
  } = params;
302
+ const currentPageRows = getCurrentPageRows();
296
303
  const viewportPageSize = apiRef.current.getViewportPageSize();
297
304
  const currentColIndex = apiRef.current.getColumnIndex(currentField);
298
305
  const colIndexBefore = currentField ? apiRef.current.getColumnIndex(currentField) : 0;
@@ -364,7 +371,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
364
371
  if (shouldPreventDefault) {
365
372
  event.preventDefault();
366
373
  }
367
- }, [apiRef, currentPageRows.length, goToHeader, goToGroupHeader, goToCell, getRowIdFromIndex]);
374
+ }, [apiRef, getCurrentPageRows, goToHeader, goToGroupHeader, goToCell, getRowIdFromIndex]);
368
375
  const handleCellKeyDown = React.useCallback((params, event) => {
369
376
  // Ignore portal
370
377
  if (isEventTargetInPortal(event)) {
@@ -383,6 +390,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
383
390
  if (!canUpdateFocus) {
384
391
  return;
385
392
  }
393
+ const currentPageRows = getCurrentPageRows();
386
394
  if (currentPageRows.length === 0) {
387
395
  return;
388
396
  }
@@ -511,7 +519,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
511
519
  if (shouldPreventDefault) {
512
520
  event.preventDefault();
513
521
  }
514
- }, [apiRef, currentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader, listView]);
522
+ }, [apiRef, getCurrentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader, listView]);
515
523
  const checkIfCanStartEditing = React.useCallback((initialValue, {
516
524
  event
517
525
  }) => {
@@ -1,10 +1,5 @@
1
1
  import { gridFilteredSortedRowIdsSelector } from "../filter/gridFilterSelector.js";
2
2
  import { gridRowSpanningHiddenCellsSelector } from "../rows/gridRowSpanningSelectors.js";
3
- import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
4
- export function enrichPageRowsWithPinnedRows(apiRef, rows) {
5
- const pinnedRows = gridPinnedRowsSelector(apiRef) || {};
6
- return [...(pinnedRows.top || []), ...rows, ...(pinnedRows.bottom || [])];
7
- }
8
3
  export const getLeftColumnIndex = ({
9
4
  currentColIndex,
10
5
  firstColIndex,
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
3
4
  import { warnOnce } from '@mui/x-internals/warning';
4
5
  import { gridDimensionsSelector } from "../dimensions/index.js";
5
6
  import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
@@ -37,7 +38,7 @@ export function useGridListView(apiRef, props) {
37
38
  /*
38
39
  * EFFECTS
39
40
  */
40
- React.useEffect(() => {
41
+ useEnhancedEffect(() => {
41
42
  const listColumn = props.unstable_listColumn;
42
43
  if (listColumn) {
43
44
  apiRef.current.setState(state => {
@@ -1 +1,8 @@
1
- export const gridPreferencePanelStateSelector = state => state.preferencePanel;
1
+ import { createSelectorV8 } from "../../../utils/createSelector.js";
2
+ export const gridPreferencePanelStateSelector = state => state.preferencePanel;
3
+ export const gridPreferencePanelSelectorWithLabel = createSelectorV8(gridPreferencePanelStateSelector, (panel, labelId) => {
4
+ if (panel.open && panel.labelId === labelId) {
5
+ return true;
6
+ }
7
+ return false;
8
+ });
@@ -1,3 +1,3 @@
1
- export * from "./gridPreferencePanelSelector.js";
1
+ export { gridPreferencePanelStateSelector } from "./gridPreferencePanelSelector.js";
2
2
  export * from "./gridPreferencePanelState.js";
3
3
  export * from "./gridPreferencePanelsValue.js";
@@ -15,42 +15,29 @@ export const preferencePanelStateInitializer = (state, props) => _extends({}, st
15
15
  */
16
16
  export const useGridPreferencesPanel = (apiRef, props) => {
17
17
  const logger = useGridLogger(apiRef, 'useGridPreferencesPanel');
18
- const hideTimeout = React.useRef(undefined);
19
- const immediateTimeout = React.useRef(undefined);
20
18
 
21
19
  /**
22
20
  * API METHODS
23
21
  */
24
22
  const hidePreferences = React.useCallback(() => {
25
- logger.debug('Hiding Preferences Panel');
26
- const preferencePanelState = gridPreferencePanelStateSelector(apiRef.current.state);
27
- if (preferencePanelState.openedPanelValue) {
23
+ apiRef.current.setState(state => {
24
+ if (!state.preferencePanel.open) {
25
+ return state;
26
+ }
27
+ logger.debug('Hiding Preferences Panel');
28
+ const preferencePanelState = gridPreferencePanelStateSelector(state);
28
29
  apiRef.current.publishEvent('preferencePanelClose', {
29
30
  openedPanelValue: preferencePanelState.openedPanelValue
30
31
  });
31
- }
32
- apiRef.current.setState(state => _extends({}, state, {
33
- preferencePanel: {
34
- open: false
35
- }
36
- }));
37
- apiRef.current.forceUpdate();
32
+ return _extends({}, state, {
33
+ preferencePanel: {
34
+ open: false
35
+ }
36
+ });
37
+ });
38
38
  }, [apiRef, logger]);
39
-
40
- // This is to prevent the preferences from closing when you open a select box or another panel,
41
- // The issue is in MUI core V4 => Fixed in V5
42
- const doNotHidePanel = React.useCallback(() => {
43
- immediateTimeout.current = setTimeout(() => clearTimeout(hideTimeout.current), 0);
44
- }, []);
45
-
46
- // This is a hack for the issue with Core V4, by delaying hiding the panel on the clickAwayListener,
47
- // we can cancel the action if the trigger element still need the panel...
48
- const hidePreferencesDelayed = React.useCallback(() => {
49
- hideTimeout.current = setTimeout(hidePreferences, 100);
50
- }, [hidePreferences]);
51
39
  const showPreferences = React.useCallback((newValue, panelId, labelId) => {
52
40
  logger.debug('Opening Preferences Panel');
53
- doNotHidePanel();
54
41
  apiRef.current.setState(state => _extends({}, state, {
55
42
  preferencePanel: _extends({}, state.preferencePanel, {
56
43
  open: true,
@@ -62,11 +49,10 @@ export const useGridPreferencesPanel = (apiRef, props) => {
62
49
  apiRef.current.publishEvent('preferencePanelOpen', {
63
50
  openedPanelValue: newValue
64
51
  });
65
- apiRef.current.forceUpdate();
66
- }, [logger, doNotHidePanel, apiRef]);
52
+ }, [logger, apiRef]);
67
53
  useGridApiMethod(apiRef, {
68
54
  showPreferences,
69
- hidePreferences: hidePreferencesDelayed
55
+ hidePreferences
70
56
  }, 'public');
71
57
 
72
58
  /**
@@ -99,14 +85,4 @@ export const useGridPreferencesPanel = (apiRef, props) => {
99
85
  }, [apiRef]);
100
86
  useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
101
87
  useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
102
-
103
- /**
104
- * EFFECTS
105
- */
106
- React.useEffect(() => {
107
- return () => {
108
- clearTimeout(hideTimeout.current);
109
- clearTimeout(immediateTimeout.current);
110
- };
111
- }, []);
112
88
  };
@@ -12,7 +12,7 @@ import { gridExpandedSortedRowIdsSelector, gridFilteredRowsLookupSelector } from
12
12
  import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from "../../../colDef/index.js";
13
13
  import { GridCellModes } from "../../../models/gridEditRowModel.js";
14
14
  import { isKeyboardEvent, isNavigationKey } from "../../../utils/keyboardUtils.js";
15
- import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
15
+ import { getVisibleRows } from "../../utils/useGridVisibleRows.js";
16
16
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "../../../internals/constants.js";
17
17
  import { gridClasses } from "../../../constants/gridClasses.js";
18
18
  import { isEventTargetInPortal } from "../../../utils/domUtils.js";
@@ -64,7 +64,6 @@ export const useGridRowSelection = (apiRef, props) => {
64
64
  isRowSelectable: propIsRowSelectable
65
65
  } = props;
66
66
  const canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
67
- const visibleRows = useGridVisibleRows(apiRef, props);
68
67
  const tree = useGridSelector(apiRef, gridRowTreeSelector);
69
68
  const isNestedData = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector) > 1;
70
69
  const expandMouseRowRangeSelection = React.useCallback(id => {
@@ -412,6 +411,7 @@ export const useGridRowSelection = (apiRef, props) => {
412
411
  end = previousRowIndex;
413
412
  }
414
413
  }
414
+ const visibleRows = getVisibleRows(apiRef);
415
415
  const rowsBetweenStartAndEnd = visibleRows.rows.slice(start, end + 1).map(row => row.id);
416
416
  apiRef.current.selectRows(rowsBetweenStartAndEnd, !isNextRowSelected);
417
417
  return;
@@ -426,7 +426,7 @@ export const useGridRowSelection = (apiRef, props) => {
426
426
  event.preventDefault();
427
427
  selectRows(apiRef.current.getAllRowIds(), true);
428
428
  }
429
- }, [apiRef, handleSingleRowSelection, selectRows, visibleRows.rows, canHaveMultipleSelection]);
429
+ }, [apiRef, handleSingleRowSelection, selectRows, canHaveMultipleSelection]);
430
430
  useGridApiEventHandler(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(() => removeOutdatedSelection(true)));
431
431
  useGridApiEventHandler(apiRef, 'filteredRowsSet', runIfRowSelectionIsEnabled(removeOutdatedSelection));
432
432
  useGridApiEventHandler(apiRef, 'rowClick', runIfRowSelectionIsEnabled(handleRowClick));