@mui/x-data-grid 5.17.4 → 5.17.6

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 (33) hide show
  1. package/CHANGELOG.md +61 -1
  2. package/components/GridPagination.d.ts +43 -1
  3. package/components/GridPagination.js +1 -2
  4. package/components/GridRow.d.ts +1 -4
  5. package/components/GridRow.js +5 -5
  6. package/components/toolbar/GridToolbarFilterButton.js +8 -4
  7. package/hooks/features/editRows/useGridCellEditing.new.js +16 -7
  8. package/hooks/features/editRows/useGridRowEditing.new.js +16 -7
  9. package/hooks/features/virtualization/useGridVirtualScroller.js +7 -7
  10. package/index.js +1 -1
  11. package/legacy/components/GridPagination.js +1 -2
  12. package/legacy/components/GridRow.js +5 -5
  13. package/legacy/components/toolbar/GridToolbarFilterButton.js +3 -1
  14. package/legacy/hooks/features/editRows/useGridCellEditing.new.js +16 -7
  15. package/legacy/hooks/features/editRows/useGridRowEditing.new.js +16 -7
  16. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +7 -7
  17. package/legacy/index.js +1 -1
  18. package/modern/components/GridPagination.js +1 -2
  19. package/modern/components/GridRow.js +5 -5
  20. package/modern/components/toolbar/GridToolbarFilterButton.js +1 -1
  21. package/modern/hooks/features/editRows/useGridCellEditing.new.js +16 -7
  22. package/modern/hooks/features/editRows/useGridRowEditing.new.js +16 -7
  23. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +6 -6
  24. package/modern/index.js +1 -1
  25. package/node/components/GridPagination.js +1 -2
  26. package/node/components/GridRow.js +6 -5
  27. package/node/components/toolbar/GridToolbarFilterButton.js +8 -4
  28. package/node/hooks/features/editRows/useGridCellEditing.new.js +19 -9
  29. package/node/hooks/features/editRows/useGridRowEditing.new.js +19 -9
  30. package/node/hooks/features/virtualization/useGridVirtualScroller.js +7 -7
  31. package/node/index.js +1 -1
  32. package/package.json +1 -1
  33. package/themeAugmentation/props.d.ts +2 -2
@@ -8,6 +8,7 @@ var _excluded = ["id", "field"],
8
8
  _excluded2 = ["id", "field"];
9
9
  import _regeneratorRuntime from "@babel/runtime/regenerator";
10
10
  import * as React from 'react';
11
+ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
11
12
  import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
12
13
  import { GridEditModes, GridCellModes } from '../../../models/gridEditRowModel';
13
14
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
@@ -111,6 +112,10 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
111
112
  } else if (params.isEditable) {
112
113
  var _reason;
113
114
 
115
+ if (event.key === ' ' && event.shiftKey) {
116
+ return; // Shift + Space is used to select the row
117
+ }
118
+
114
119
  if (isPrintableKey(event)) {
115
120
  _reason = GridCellEditStartReasons.printableKeyDown;
116
121
  } else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
@@ -189,7 +194,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
189
194
  var isEditing = editingState[id] && editingState[id][field];
190
195
  return isEditing ? GridCellModes.Edit : GridCellModes.View;
191
196
  }, [apiRef]);
192
- var updateCellModesModel = React.useCallback(function (newModel) {
197
+ var updateCellModesModel = useEventCallback(function (newModel) {
193
198
  var isNewModelDifferentFromProp = newModel !== props.cellModesModel;
194
199
 
195
200
  if (onCellModesModelChange && isNewModelDifferentFromProp) {
@@ -206,7 +211,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
206
211
  setCellModesModel(newModel);
207
212
  cellModesModelRef.current = newModel;
208
213
  apiRef.current.publishEvent('cellModesModelChange', newModel);
209
- }, [apiRef, onCellModesModelChange, props.cellModesModel, signature]);
214
+ });
210
215
  var updateFieldInCellModesModel = React.useCallback(function (id, field, newProps) {
211
216
  // We use the ref because it always contain the up-to-date value, different from the state
212
217
  // that needs a rerender to reflect the new value
@@ -260,7 +265,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
260
265
  mode: GridCellModes.Edit
261
266
  }, other));
262
267
  }, [throwIfNotEditable, throwIfNotInMode, updateFieldInCellModesModel]);
263
- var updateStateToStartCellEditMode = React.useCallback(function (params) {
268
+ var updateStateToStartCellEditMode = useEventCallback(function (params) {
264
269
  var id = params.id,
265
270
  field = params.field,
266
271
  deleteValue = params.deleteValue;
@@ -271,7 +276,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
271
276
  };
272
277
  updateOrDeleteFieldState(id, field, newProps);
273
278
  apiRef.current.setCellFocus(id, field);
274
- }, [apiRef, updateOrDeleteFieldState]);
279
+ });
275
280
  var stopCellEditMode = React.useCallback(function (params) {
276
281
  var id = params.id,
277
282
  field = params.field,
@@ -282,7 +287,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
282
287
  mode: GridCellModes.View
283
288
  }, other));
284
289
  }, [throwIfNotInMode, updateFieldInCellModesModel]);
285
- var updateStateToStopCellEditMode = React.useCallback( /*#__PURE__*/function () {
290
+ var updateStateToStopCellEditMode = useEventCallback( /*#__PURE__*/function () {
286
291
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
287
292
  var id, field, ignoreModifications, _params$cellToFocusAf, cellToFocusAfter, finishCellEditMode, editingState, _editingState$id$fiel, error, isProcessingProps, rowUpdate, handleError, row;
288
293
 
@@ -334,7 +339,11 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
334
339
 
335
340
  if (processRowUpdate) {
336
341
  handleError = function handleError(errorThrown) {
337
- prevCellModesModel.current[id][field].mode = GridCellModes.Edit;
342
+ prevCellModesModel.current[id][field].mode = GridCellModes.Edit; // Revert the mode in the cellModesModel prop back to "edit"
343
+
344
+ updateFieldInCellModesModel(id, field, {
345
+ mode: GridCellModes.Edit
346
+ });
338
347
 
339
348
  if (onProcessRowUpdateError) {
340
349
  onProcessRowUpdateError(errorThrown);
@@ -368,7 +377,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
368
377
  return function (_x) {
369
378
  return _ref.apply(this, arguments);
370
379
  };
371
- }(), [apiRef, onProcessRowUpdateError, processRowUpdate, throwIfNotInMode, updateFieldInCellModesModel, updateOrDeleteFieldState]);
380
+ }());
372
381
  var setCellEditingEditCellValue = React.useCallback( /*#__PURE__*/function () {
373
382
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
374
383
  var _editingState$id, _editingState$id$fiel2;
@@ -6,6 +6,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
6
  var _excluded = ["id"],
7
7
  _excluded2 = ["id"];
8
8
  import * as React from 'react';
9
+ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
9
10
  import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
10
11
  import { GridEditModes, GridRowModes } from '../../../models/gridEditRowModel';
11
12
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
@@ -168,6 +169,10 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
168
169
  } else if (params.isEditable) {
169
170
  var _reason;
170
171
 
172
+ if (event.key === ' ' && event.shiftKey) {
173
+ return; // Shift + Space is used to select the row
174
+ }
175
+
171
176
  if (isPrintableKey(event)) {
172
177
  _reason = GridRowEditStartReasons.printableKeyDown;
173
178
  } else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
@@ -256,7 +261,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
256
261
  var isEditing = editingState[id] && Object.keys(editingState[id]).length > 0;
257
262
  return isEditing ? GridRowModes.Edit : GridRowModes.View;
258
263
  }, [apiRef, props.editMode]);
259
- var updateRowModesModel = React.useCallback(function (newModel) {
264
+ var updateRowModesModel = useEventCallback(function (newModel) {
260
265
  var isNewModelDifferentFromProp = newModel !== props.rowModesModel;
261
266
 
262
267
  if (onRowModesModelChange && isNewModelDifferentFromProp) {
@@ -273,7 +278,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
273
278
  setRowModesModel(newModel);
274
279
  rowModesModelRef.current = newModel;
275
280
  apiRef.current.publishEvent('rowModesModelChange', newModel);
276
- }, [apiRef, onRowModesModelChange, props.rowModesModel, signature]);
281
+ });
277
282
  var updateRowInRowModesModel = React.useCallback(function (id, newProps) {
278
283
  var newModel = _extends({}, rowModesModelRef.current);
279
284
 
@@ -330,7 +335,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
330
335
  mode: GridRowModes.Edit
331
336
  }, other));
332
337
  }, [throwIfNotInMode, updateRowInRowModesModel]);
333
- var updateStateToStartRowEditMode = React.useCallback(function (params) {
338
+ var updateStateToStartRowEditMode = useEventCallback(function (params) {
334
339
  var id = params.id,
335
340
  fieldToFocus = params.fieldToFocus,
336
341
  deleteValue = params.deleteValue;
@@ -355,7 +360,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
355
360
  if (fieldToFocus) {
356
361
  apiRef.current.setCellFocus(id, fieldToFocus);
357
362
  }
358
- }, [apiRef, updateOrDeleteRowState]);
363
+ });
359
364
  var stopRowEditMode = React.useCallback(function (params) {
360
365
  var id = params.id,
361
366
  other = _objectWithoutProperties(params, _excluded2);
@@ -365,7 +370,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
365
370
  mode: GridRowModes.View
366
371
  }, other));
367
372
  }, [throwIfNotInMode, updateRowInRowModesModel]);
368
- var updateStateToStopRowEditMode = React.useCallback(function (params) {
373
+ var updateStateToStopRowEditMode = useEventCallback(function (params) {
369
374
  var id = params.id,
370
375
  ignoreModifications = params.ignoreModifications,
371
376
  focusedField = params.field,
@@ -415,7 +420,11 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
415
420
 
416
421
  if (processRowUpdate) {
417
422
  var handleError = function handleError(errorThrown) {
418
- prevRowModesModel.current[id].mode = GridRowModes.Edit;
423
+ prevRowModesModel.current[id].mode = GridRowModes.Edit; // Revert the mode in the rowModesModel prop back to "edit"
424
+
425
+ updateRowInRowModesModel(id, {
426
+ mode: GridRowModes.Edit
427
+ });
419
428
 
420
429
  if (onProcessRowUpdateError) {
421
430
  onProcessRowUpdateError(errorThrown);
@@ -436,7 +445,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
436
445
  apiRef.current.updateRows([rowUpdate]);
437
446
  finishRowEditMode();
438
447
  }
439
- }, [apiRef, onProcessRowUpdateError, processRowUpdate, updateOrDeleteRowState, updateRowInRowModesModel]);
448
+ });
440
449
  var setRowEditingEditCellValue = React.useCallback(function (params) {
441
450
  var id = params.id,
442
451
  field = params.field,
@@ -104,16 +104,16 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
104
104
  var _currentPage$range, _currentPage$range2;
105
105
 
106
106
  var lastMeasuredIndexRelativeToAllRows = apiRef.current.unstable_getLastMeasuredRowIndex();
107
- var lastMeasuredIndexRelativeToCurrentPage = lastMeasuredIndexRelativeToAllRows - (((_currentPage$range = currentPage.range) == null ? void 0 : _currentPage$range.firstRowIndex) || 0);
108
- var lastMeasuredIndex = Math.max(0, lastMeasuredIndexRelativeToCurrentPage);
109
- var allRowsMeasured = lastMeasuredIndex === Infinity;
107
+ var allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
110
108
 
111
- if ((_currentPage$range2 = currentPage.range) != null && _currentPage$range2.lastRowIndex && !allRowsMeasured) {
109
+ if ((_currentPage$range = currentPage.range) != null && _currentPage$range.lastRowIndex && !allRowsMeasured) {
112
110
  // Check if all rows in this page are already measured
113
- allRowsMeasured = lastMeasuredIndex >= currentPage.range.lastRowIndex;
111
+ allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
114
112
  }
115
113
 
116
- if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndex] >= offset) {
114
+ var lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (((_currentPage$range2 = currentPage.range) == null ? void 0 : _currentPage$range2.firstRowIndex) || 0), 0, rowsMeta.positions.length);
115
+
116
+ if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
117
117
  // If all rows were measured (when no row has "auto" as height) or all rows before the offset
118
118
  // were measured, then use a binary search because it's faster.
119
119
  return binarySearch(offset, rowsMeta.positions);
@@ -123,7 +123,7 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
123
123
  // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
124
124
 
125
125
 
126
- return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndex);
126
+ return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
127
127
  }, [apiRef, (_currentPage$range3 = currentPage.range) == null ? void 0 : _currentPage$range3.firstRowIndex, (_currentPage$range4 = currentPage.range) == null ? void 0 : _currentPage$range4.lastRowIndex, rowsMeta.positions]);
128
128
  var computeRenderContext = React.useCallback(function () {
129
129
  if (disableVirtualization) {
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.17.4
1
+ /** @license MUI v5.17.6
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -47,8 +47,7 @@ export const GridPagination = /*#__PURE__*/React.forwardRef(function GridPaginat
47
47
  }
48
48
 
49
49
  return /*#__PURE__*/_jsx(GridPaginationRoot, _extends({
50
- ref: ref // @ts-ignore
51
- ,
50
+ ref: ref,
52
51
  component: "div",
53
52
  count: paginationState.rowCount,
54
53
  page: paginationState.page <= lastPage ? paginationState.page : lastPage,
@@ -5,7 +5,7 @@ const _excluded = ["selected", "rowId", "row", "index", "style", "position", "ro
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import clsx from 'clsx';
8
- import { unstable_composeClasses as composeClasses } from '@mui/material';
8
+ import { unstable_composeClasses as composeClasses, useForkRef } from '@mui/material';
9
9
  import { GridEditModes, GridRowModes, GridCellModes } from '../models/gridEditRowModel';
10
10
  import { useGridApiContext } from '../hooks/utils/useGridApiContext';
11
11
  import { getDataGridUtilityClass, gridClasses } from '../constants/gridClasses';
@@ -55,7 +55,7 @@ const EmptyCell = ({
55
55
  }); // TODO change to .MuiDataGrid-emptyCell or .MuiDataGrid-rowFiller
56
56
  };
57
57
 
58
- function GridRow(props) {
58
+ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
59
59
  const {
60
60
  selected,
61
61
  rowId,
@@ -88,6 +88,7 @@ function GridRow(props) {
88
88
  const sortModel = useGridSelector(apiRef, gridSortModelSelector);
89
89
  const treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
90
90
  const headerGroupingMaxDepth = useGridSelector(apiRef, gridDensityHeaderGroupingMaxDepthSelector);
91
+ const handleRef = useForkRef(ref, refProp);
91
92
  const ariaRowIndex = index + headerGroupingMaxDepth + 2; // 1 for the header row and 1 as it's 1-based
92
93
 
93
94
  const {
@@ -368,7 +369,7 @@ function GridRow(props) {
368
369
  onMouseLeave: publish('rowMouseLeave', onMouseLeave)
369
370
  } : null;
370
371
  return /*#__PURE__*/_jsxs("div", _extends({
371
- ref: ref,
372
+ ref: handleRef,
372
373
  "data-id": rowId,
373
374
  "data-rowindex": index,
374
375
  role: "row",
@@ -381,8 +382,7 @@ function GridRow(props) {
381
382
  width: emptyCellWidth
382
383
  })]
383
384
  }));
384
- }
385
-
385
+ });
386
386
  process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
387
387
  // ----------------------------- Warning --------------------------------
388
388
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -71,7 +71,7 @@ const GridToolbarFilterButton = /*#__PURE__*/React.forwardRef(function GridToolb
71
71
  children: activeFilters.map((item, index) => _extends({}, lookup[item.columnField] && /*#__PURE__*/_jsx("li", {
72
72
  children: `${lookup[item.columnField].headerName || item.columnField}
73
73
  ${getOperatorLabel(item)}
74
- ${item.value}`
74
+ ${item.value ?? ''}`
75
75
  }, index)))
76
76
  })]
77
77
  });
@@ -4,6 +4,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  const _excluded = ["id", "field"],
5
5
  _excluded2 = ["id", "field"];
6
6
  import * as React from 'react';
7
+ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
7
8
  import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
8
9
  import { GridEditModes, GridCellModes } from '../../../models/gridEditRowModel';
9
10
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
@@ -103,6 +104,10 @@ export const useGridCellEditing = (apiRef, props) => {
103
104
  } else if (params.isEditable) {
104
105
  let reason;
105
106
 
107
+ if (event.key === ' ' && event.shiftKey) {
108
+ return; // Shift + Space is used to select the row
109
+ }
110
+
106
111
  if (isPrintableKey(event)) {
107
112
  reason = GridCellEditStartReasons.printableKeyDown;
108
113
  } else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
@@ -185,7 +190,7 @@ export const useGridCellEditing = (apiRef, props) => {
185
190
  const isEditing = editingState[id] && editingState[id][field];
186
191
  return isEditing ? GridCellModes.Edit : GridCellModes.View;
187
192
  }, [apiRef]);
188
- const updateCellModesModel = React.useCallback(newModel => {
193
+ const updateCellModesModel = useEventCallback(newModel => {
189
194
  const isNewModelDifferentFromProp = newModel !== props.cellModesModel;
190
195
 
191
196
  if (onCellModesModelChange && isNewModelDifferentFromProp) {
@@ -202,7 +207,7 @@ export const useGridCellEditing = (apiRef, props) => {
202
207
  setCellModesModel(newModel);
203
208
  cellModesModelRef.current = newModel;
204
209
  apiRef.current.publishEvent('cellModesModelChange', newModel);
205
- }, [apiRef, onCellModesModelChange, props.cellModesModel, signature]);
210
+ });
206
211
  const updateFieldInCellModesModel = React.useCallback((id, field, newProps) => {
207
212
  // We use the ref because it always contain the up-to-date value, different from the state
208
213
  // that needs a rerender to reflect the new value
@@ -261,7 +266,7 @@ export const useGridCellEditing = (apiRef, props) => {
261
266
  mode: GridCellModes.Edit
262
267
  }, other));
263
268
  }, [throwIfNotEditable, throwIfNotInMode, updateFieldInCellModesModel]);
264
- const updateStateToStartCellEditMode = React.useCallback(params => {
269
+ const updateStateToStartCellEditMode = useEventCallback(params => {
265
270
  const {
266
271
  id,
267
272
  field,
@@ -274,7 +279,7 @@ export const useGridCellEditing = (apiRef, props) => {
274
279
  };
275
280
  updateOrDeleteFieldState(id, field, newProps);
276
281
  apiRef.current.setCellFocus(id, field);
277
- }, [apiRef, updateOrDeleteFieldState]);
282
+ });
278
283
  const stopCellEditMode = React.useCallback(params => {
279
284
  const {
280
285
  id,
@@ -287,7 +292,7 @@ export const useGridCellEditing = (apiRef, props) => {
287
292
  mode: GridCellModes.View
288
293
  }, other));
289
294
  }, [throwIfNotInMode, updateFieldInCellModesModel]);
290
- const updateStateToStopCellEditMode = React.useCallback(async params => {
295
+ const updateStateToStopCellEditMode = useEventCallback(async params => {
291
296
  const {
292
297
  id,
293
298
  field,
@@ -332,7 +337,11 @@ export const useGridCellEditing = (apiRef, props) => {
332
337
 
333
338
  if (processRowUpdate) {
334
339
  const handleError = errorThrown => {
335
- prevCellModesModel.current[id][field].mode = GridCellModes.Edit;
340
+ prevCellModesModel.current[id][field].mode = GridCellModes.Edit; // Revert the mode in the cellModesModel prop back to "edit"
341
+
342
+ updateFieldInCellModesModel(id, field, {
343
+ mode: GridCellModes.Edit
344
+ });
336
345
 
337
346
  if (onProcessRowUpdateError) {
338
347
  onProcessRowUpdateError(errorThrown);
@@ -354,7 +363,7 @@ export const useGridCellEditing = (apiRef, props) => {
354
363
  apiRef.current.updateRows([rowUpdate]);
355
364
  finishCellEditMode();
356
365
  }
357
- }, [apiRef, onProcessRowUpdateError, processRowUpdate, throwIfNotInMode, updateFieldInCellModesModel, updateOrDeleteFieldState]);
366
+ });
358
367
  const setCellEditingEditCellValue = React.useCallback(async params => {
359
368
  const {
360
369
  id,
@@ -4,6 +4,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  const _excluded = ["id"],
5
5
  _excluded2 = ["id"];
6
6
  import * as React from 'react';
7
+ import { unstable_useEventCallback as useEventCallback } from '@mui/utils';
7
8
  import { useGridApiEventHandler, useGridApiOptionHandler, GridSignature } from '../../utils/useGridApiEventHandler';
8
9
  import { GridEditModes, GridRowModes } from '../../../models/gridEditRowModel';
9
10
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
@@ -158,6 +159,10 @@ export const useGridRowEditing = (apiRef, props) => {
158
159
  } else if (params.isEditable) {
159
160
  let reason;
160
161
 
162
+ if (event.key === ' ' && event.shiftKey) {
163
+ return; // Shift + Space is used to select the row
164
+ }
165
+
161
166
  if (isPrintableKey(event)) {
162
167
  reason = GridRowEditStartReasons.printableKeyDown;
163
168
  } else if ((event.ctrlKey || event.metaKey) && event.key === 'v') {
@@ -250,7 +255,7 @@ export const useGridRowEditing = (apiRef, props) => {
250
255
  const isEditing = editingState[id] && Object.keys(editingState[id]).length > 0;
251
256
  return isEditing ? GridRowModes.Edit : GridRowModes.View;
252
257
  }, [apiRef, props.editMode]);
253
- const updateRowModesModel = React.useCallback(newModel => {
258
+ const updateRowModesModel = useEventCallback(newModel => {
254
259
  const isNewModelDifferentFromProp = newModel !== props.rowModesModel;
255
260
 
256
261
  if (onRowModesModelChange && isNewModelDifferentFromProp) {
@@ -267,7 +272,7 @@ export const useGridRowEditing = (apiRef, props) => {
267
272
  setRowModesModel(newModel);
268
273
  rowModesModelRef.current = newModel;
269
274
  apiRef.current.publishEvent('rowModesModelChange', newModel);
270
- }, [apiRef, onRowModesModelChange, props.rowModesModel, signature]);
275
+ });
271
276
  const updateRowInRowModesModel = React.useCallback((id, newProps) => {
272
277
  const newModel = _extends({}, rowModesModelRef.current);
273
278
 
@@ -328,7 +333,7 @@ export const useGridRowEditing = (apiRef, props) => {
328
333
  mode: GridRowModes.Edit
329
334
  }, other));
330
335
  }, [throwIfNotInMode, updateRowInRowModesModel]);
331
- const updateStateToStartRowEditMode = React.useCallback(params => {
336
+ const updateStateToStartRowEditMode = useEventCallback(params => {
332
337
  const {
333
338
  id,
334
339
  fieldToFocus,
@@ -355,7 +360,7 @@ export const useGridRowEditing = (apiRef, props) => {
355
360
  if (fieldToFocus) {
356
361
  apiRef.current.setCellFocus(id, fieldToFocus);
357
362
  }
358
- }, [apiRef, updateOrDeleteRowState]);
363
+ });
359
364
  const stopRowEditMode = React.useCallback(params => {
360
365
  const {
361
366
  id
@@ -367,7 +372,7 @@ export const useGridRowEditing = (apiRef, props) => {
367
372
  mode: GridRowModes.View
368
373
  }, other));
369
374
  }, [throwIfNotInMode, updateRowInRowModesModel]);
370
- const updateStateToStopRowEditMode = React.useCallback(params => {
375
+ const updateStateToStopRowEditMode = useEventCallback(params => {
371
376
  const {
372
377
  id,
373
378
  ignoreModifications,
@@ -414,7 +419,11 @@ export const useGridRowEditing = (apiRef, props) => {
414
419
 
415
420
  if (processRowUpdate) {
416
421
  const handleError = errorThrown => {
417
- prevRowModesModel.current[id].mode = GridRowModes.Edit;
422
+ prevRowModesModel.current[id].mode = GridRowModes.Edit; // Revert the mode in the rowModesModel prop back to "edit"
423
+
424
+ updateRowInRowModesModel(id, {
425
+ mode: GridRowModes.Edit
426
+ });
418
427
 
419
428
  if (onProcessRowUpdateError) {
420
429
  onProcessRowUpdateError(errorThrown);
@@ -435,7 +444,7 @@ export const useGridRowEditing = (apiRef, props) => {
435
444
  apiRef.current.updateRows([rowUpdate]);
436
445
  finishRowEditMode();
437
446
  }
438
- }, [apiRef, onProcessRowUpdateError, processRowUpdate, updateOrDeleteRowState, updateRowInRowModesModel]);
447
+ });
439
448
  const setRowEditingEditCellValue = React.useCallback(params => {
440
449
  const {
441
450
  id,
@@ -87,16 +87,16 @@ export const useGridVirtualScroller = props => {
87
87
  const prevTotalWidth = React.useRef(columnsTotalWidth);
88
88
  const getNearestIndexToRender = React.useCallback(offset => {
89
89
  const lastMeasuredIndexRelativeToAllRows = apiRef.current.unstable_getLastMeasuredRowIndex();
90
- const lastMeasuredIndexRelativeToCurrentPage = lastMeasuredIndexRelativeToAllRows - (currentPage.range?.firstRowIndex || 0);
91
- const lastMeasuredIndex = Math.max(0, lastMeasuredIndexRelativeToCurrentPage);
92
- let allRowsMeasured = lastMeasuredIndex === Infinity;
90
+ let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
93
91
 
94
92
  if (currentPage.range?.lastRowIndex && !allRowsMeasured) {
95
93
  // Check if all rows in this page are already measured
96
- allRowsMeasured = lastMeasuredIndex >= currentPage.range.lastRowIndex;
94
+ allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= currentPage.range.lastRowIndex;
97
95
  }
98
96
 
99
- if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndex] >= offset) {
97
+ const lastMeasuredIndexRelativeToCurrentPage = clamp(lastMeasuredIndexRelativeToAllRows - (currentPage.range?.firstRowIndex || 0), 0, rowsMeta.positions.length);
98
+
99
+ if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
100
100
  // If all rows were measured (when no row has "auto" as height) or all rows before the offset
101
101
  // were measured, then use a binary search because it's faster.
102
102
  return binarySearch(offset, rowsMeta.positions);
@@ -106,7 +106,7 @@ export const useGridVirtualScroller = props => {
106
106
  // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
107
107
 
108
108
 
109
- return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndex);
109
+ return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
110
110
  }, [apiRef, currentPage.range?.firstRowIndex, currentPage.range?.lastRowIndex, rowsMeta.positions]);
111
111
  const computeRenderContext = React.useCallback(() => {
112
112
  if (disableVirtualization) {
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.17.4
1
+ /** @license MUI v5.17.6
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -75,8 +75,7 @@ const GridPagination = /*#__PURE__*/React.forwardRef(function GridPagination(pro
75
75
  }
76
76
 
77
77
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridPaginationRoot, (0, _extends2.default)({
78
- ref: ref // @ts-ignore
79
- ,
78
+ ref: ref,
80
79
  component: "div",
81
80
  count: paginationState.rowCount,
82
81
  page: paginationState.page <= lastPage ? paginationState.page : lastPage,
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.GridRow = GridRow;
8
+ exports.GridRow = void 0;
9
9
 
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
 
@@ -89,7 +89,7 @@ const EmptyCell = ({
89
89
  }); // TODO change to .MuiDataGrid-emptyCell or .MuiDataGrid-rowFiller
90
90
  };
91
91
 
92
- function GridRow(props) {
92
+ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
93
93
  var _apiRef$current$getRo;
94
94
 
95
95
  const {
@@ -123,6 +123,7 @@ function GridRow(props) {
123
123
  const sortModel = (0, _useGridSelector.useGridSelector)(apiRef, _gridSortingSelector.gridSortModelSelector);
124
124
  const treeDepth = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridRowTreeDepthSelector);
125
125
  const headerGroupingMaxDepth = (0, _useGridSelector.useGridSelector)(apiRef, _densitySelector.gridDensityHeaderGroupingMaxDepthSelector);
126
+ const handleRef = (0, _material.useForkRef)(ref, refProp);
126
127
  const ariaRowIndex = index + headerGroupingMaxDepth + 2; // 1 for the header row and 1 as it's 1-based
127
128
 
128
129
  const {
@@ -407,7 +408,7 @@ function GridRow(props) {
407
408
  onMouseLeave: publish('rowMouseLeave', onMouseLeave)
408
409
  } : null;
409
410
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _extends2.default)({
410
- ref: ref,
411
+ ref: handleRef,
411
412
  "data-id": rowId,
412
413
  "data-rowindex": index,
413
414
  role: "row",
@@ -420,8 +421,8 @@ function GridRow(props) {
420
421
  width: emptyCellWidth
421
422
  })]
422
423
  }));
423
- }
424
-
424
+ });
425
+ exports.GridRow = GridRow;
425
426
  process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
426
427
  // ----------------------------- Warning --------------------------------
427
428
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -98,11 +98,15 @@ const GridToolbarFilterButton = /*#__PURE__*/React.forwardRef(function GridToolb
98
98
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
99
99
  children: [apiRef.current.getLocaleText('toolbarFiltersTooltipActive')(activeFilters.length), /*#__PURE__*/(0, _jsxRuntime.jsx)(GridToolbarFilterListRoot, {
100
100
  className: classes.root,
101
- children: activeFilters.map((item, index) => (0, _extends2.default)({}, lookup[item.columnField] && /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
102
- children: `${lookup[item.columnField].headerName || item.columnField}
101
+ children: activeFilters.map((item, index) => {
102
+ var _item$value;
103
+
104
+ return (0, _extends2.default)({}, lookup[item.columnField] && /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
105
+ children: `${lookup[item.columnField].headerName || item.columnField}
103
106
  ${getOperatorLabel(item)}
104
- ${item.value}`
105
- }, index)))
107
+ ${(_item$value = item.value) != null ? _item$value : ''}`
108
+ }, index));
109
+ })
106
110
  })]
107
111
  });
108
112
  }, [apiRef, preferencePanel.open, activeFilters, lookup, classes]);