@mui/x-data-grid 6.10.1 → 6.10.2

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 (37) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/components/GridRow.d.ts +2 -0
  3. package/components/GridRow.js +50 -22
  4. package/components/cell/GridCell.d.ts +2 -2
  5. package/components/cell/GridCell.js +38 -14
  6. package/components/containers/GridRootStyles.js +1 -0
  7. package/hooks/features/rowSelection/useGridRowSelection.js +1 -1
  8. package/hooks/features/virtualization/useGridVirtualScroller.js +69 -5
  9. package/index.js +1 -1
  10. package/internals/index.d.ts +1 -1
  11. package/internals/index.js +1 -1
  12. package/legacy/components/GridRow.js +47 -21
  13. package/legacy/components/cell/GridCell.js +38 -14
  14. package/legacy/components/containers/GridRootStyles.js +1 -0
  15. package/legacy/hooks/features/rowSelection/useGridRowSelection.js +1 -1
  16. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +73 -5
  17. package/legacy/index.js +1 -1
  18. package/legacy/internals/index.js +1 -1
  19. package/legacy/locales/fiFI.js +1 -1
  20. package/locales/fiFI.js +1 -1
  21. package/modern/components/GridRow.js +50 -22
  22. package/modern/components/cell/GridCell.js +38 -14
  23. package/modern/components/containers/GridRootStyles.js +1 -0
  24. package/modern/hooks/features/rowSelection/useGridRowSelection.js +1 -1
  25. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +69 -5
  26. package/modern/index.js +1 -1
  27. package/modern/internals/index.js +1 -1
  28. package/modern/locales/fiFI.js +1 -1
  29. package/node/components/GridRow.js +50 -22
  30. package/node/components/cell/GridCell.js +38 -14
  31. package/node/components/containers/GridRootStyles.js +1 -0
  32. package/node/hooks/features/rowSelection/useGridRowSelection.js +1 -1
  33. package/node/hooks/features/virtualization/useGridVirtualScroller.js +69 -5
  34. package/node/index.js +1 -1
  35. package/node/internals/index.js +7 -0
  36. package/node/locales/fiFI.js +1 -1
  37. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,70 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 6.10.2
7
+
8
+ _Jul 27, 2023_
9
+
10
+ We'd like to offer a big thanks to the 13 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 🚀 Improve scatter charts performance
13
+ - 📚 Redesigned component API documentation and side navigation
14
+ - 🐞 Bugfixes
15
+
16
+ ### Data Grid
17
+
18
+ #### `@mui/x-data-grid@v6.10.2`
19
+
20
+ - [DataGrid] Fix quick filter & aggregation error (#9729) @romgrk
21
+ - [DataGrid] Fix row click propagation causing error in nested grid (#9741) @cherniavskii
22
+ - [DataGrid] Keep focused cell in the DOM (#7357) @yaredtsy
23
+ - [l10n] Improve Finnish (fi-FI) locale (#9746) @sambbaahh
24
+
25
+ #### `@mui/x-data-grid-pro@v6.10.2` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link)
26
+
27
+ Same changes as in `@mui/x-data-grid@v6.10.2`.
28
+
29
+ #### `@mui/x-data-grid-premium@v6.10.2` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link)
30
+
31
+ Same changes as in `@mui/x-data-grid-pro@v6.10.2`, plus:
32
+
33
+ - [DataGridPremium] Allow to customize grouping cell offset (#9417) @cherniavskii
34
+
35
+ ### Date Pickers
36
+
37
+ #### `@mui/x-date-pickers@v6.10.2`
38
+
39
+ - [pickers] Remove the `endOfDate` from `DigitalClock` timeOptions (#9800) @noraleonte
40
+
41
+ #### `@mui/x-date-pickers-pro@v6.10.2` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link)
42
+
43
+ Same changes as in `@mui/x-date-pickers@v6.10.2`.
44
+
45
+ ### Charts / `@mui/x-charts@v6.0.0-alpha.5`
46
+
47
+ - [charts] Improve JSDoc for axis-related props (#9779) @flaviendelangle
48
+ - [charts] Improve performances of Scatter component (#9527) @flaviendelangle
49
+
50
+ ### Docs
51
+
52
+ - [docs] Add `pnpm` in more places @oliviertassinari
53
+ - [docs] Add `pnpm` installation instructions for MUI X (#9707) @richbustos
54
+ - [docs] Align pickers "uncontrolled vs controlled" sections (#9772) @LukasTy
55
+ - [docs] Apply style guide to the data grid Layout page (#9673) @richbustos
56
+ - [docs] Differentiate between packages in `slotProps` docs (#9668) @cherniavskii
57
+ - [docs] Fix charts width in axis pages (#9801) @alexfauquette
58
+ - [docs] Fix wrong prop name in the Editing page (#9753) @m4theushw
59
+ - [docs] New component API page and side nav design (#9187) @alexfauquette
60
+ - [docs] Update overview page with up to date information about the plans (#9512) @joserodolfofreitas
61
+
62
+ ### Core
63
+
64
+ - [core] Use PR charts version in preview (#9787) @alexfauquette
65
+ - [license] Allow overriding the license on specific parts of the page (#9717) @Janpot
66
+ - [license] Throw in dev mode after 30 days (#9701) @oliviertassinari
67
+ - [license] Only throw in dev mode (#9803) @oliviertassinari
68
+ - [test] Fail the CI when new unexpected files are created (#9728) @oliviertassinari
69
+
6
70
  ## 6.10.1
7
71
 
8
72
  _Jul 20, 2023_
@@ -28,6 +28,8 @@ export interface GridRowProps extends React.HTMLAttributes<HTMLDivElement> {
28
28
  tabbableCell: string | null;
29
29
  row?: GridRowModel;
30
30
  isLastVisible?: boolean;
31
+ focusedCellColumnIndexNotInRange?: number;
32
+ isNotVisible?: boolean;
31
33
  onClick?: React.MouseEventHandler<HTMLDivElement>;
32
34
  onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
33
35
  onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
3
+ const _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCellColumnIndexNotInRange", "isNotVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
@@ -64,10 +64,14 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
64
64
  position,
65
65
  rowHeight,
66
66
  className,
67
+ visibleColumns,
67
68
  renderedColumns,
68
69
  containerWidth,
69
70
  firstColumnToRender,
70
71
  isLastVisible = false,
72
+ focusedCellColumnIndexNotInRange,
73
+ isNotVisible,
74
+ focusedCell,
71
75
  onClick,
72
76
  onDoubleClick,
73
77
  onMouseEnter,
@@ -173,7 +177,7 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
173
177
 
174
178
  // User clicked a button from the "actions" column type
175
179
  const column = apiRef.current.getColumn(field);
176
- if (column.type === GRID_ACTIONS_COLUMN_TYPE) {
180
+ if ((column == null ? void 0 : column.type) === GRID_ACTIONS_COLUMN_TYPE) {
177
181
  return;
178
182
  }
179
183
  }
@@ -190,6 +194,10 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
190
194
  var _editRowsState$rowId$, _editRowsState$rowId;
191
195
  const disableDragEvents = disableColumnReorder && column.disableReorder || !rowReordering && !!sortModel.length && treeDepth > 1 && Object.keys(editRowsState).length > 0;
192
196
  const editCellState = (_editRowsState$rowId$ = (_editRowsState$rowId = editRowsState[rowId]) == null ? void 0 : _editRowsState$rowId[column.field]) != null ? _editRowsState$rowId$ : null;
197
+ let cellIsNotVisible = false;
198
+ if (focusedCellColumnIndexNotInRange !== undefined && visibleColumns[focusedCellColumnIndexNotInRange].field === column.field) {
199
+ cellIsNotVisible = true;
200
+ }
193
201
  return /*#__PURE__*/_jsx(CellComponent, _extends({
194
202
  column: column,
195
203
  width: cellProps.width,
@@ -200,7 +208,8 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
200
208
  colIndex: cellProps.indexRelativeToAllColumns,
201
209
  colSpan: cellProps.colSpan,
202
210
  disableDragEvents: disableDragEvents,
203
- editCellState: editCellState
211
+ editCellState: editCellState,
212
+ isNotVisible: cellIsNotVisible
204
213
  }, slotProps == null ? void 0 : slotProps.cell), column.field);
205
214
  };
206
215
  const sizes = useGridSelector(apiRef, () => _extends({}, apiRef.current.unstable_getRowInternalSizes(rowId)), objectShallowCompare);
@@ -222,25 +231,35 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
222
231
  minHeight = maximumSize;
223
232
  }
224
233
  }
225
- const style = _extends({}, styleProp, {
226
- maxHeight: rowHeight === 'auto' ? 'none' : rowHeight,
227
- // max-height doesn't support "auto"
228
- minHeight
229
- });
230
- if (sizes != null && sizes.spacingTop) {
231
- const property = rootProps.rowSpacingType === 'border' ? 'borderTopWidth' : 'marginTop';
232
- style[property] = sizes.spacingTop;
233
- }
234
- if (sizes != null && sizes.spacingBottom) {
235
- const property = rootProps.rowSpacingType === 'border' ? 'borderBottomWidth' : 'marginBottom';
236
- let propertyValue = style[property];
237
- // avoid overriding existing value
238
- if (typeof propertyValue !== 'number') {
239
- propertyValue = parseInt(propertyValue || '0', 10);
234
+ const style = React.useMemo(() => {
235
+ if (isNotVisible) {
236
+ return {
237
+ opacity: 0,
238
+ width: 0,
239
+ height: 0
240
+ };
240
241
  }
241
- propertyValue += sizes.spacingBottom;
242
- style[property] = propertyValue;
243
- }
242
+ const rowStyle = _extends({}, styleProp, {
243
+ maxHeight: rowHeight === 'auto' ? 'none' : rowHeight,
244
+ // max-height doesn't support "auto"
245
+ minHeight
246
+ });
247
+ if (sizes != null && sizes.spacingTop) {
248
+ const property = rootProps.rowSpacingType === 'border' ? 'borderTopWidth' : 'marginTop';
249
+ rowStyle[property] = sizes.spacingTop;
250
+ }
251
+ if (sizes != null && sizes.spacingBottom) {
252
+ const property = rootProps.rowSpacingType === 'border' ? 'borderBottomWidth' : 'marginBottom';
253
+ let propertyValue = rowStyle[property];
254
+ // avoid overriding existing value
255
+ if (typeof propertyValue !== 'number') {
256
+ propertyValue = parseInt(propertyValue || '0', 10);
257
+ }
258
+ propertyValue += sizes.spacingBottom;
259
+ rowStyle[property] = propertyValue;
260
+ }
261
+ return rowStyle;
262
+ }, [isNotVisible, rowHeight, styleProp, minHeight, sizes, rootProps.rowSpacingType]);
244
263
  const rowClassNames = apiRef.current.unstable_applyPipeProcessors('rowClassName', [], rowId);
245
264
  if (typeof rootProps.getRowClassName === 'function') {
246
265
  var _currentPage$range;
@@ -261,7 +280,14 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
261
280
  const cells = [];
262
281
  for (let i = 0; i < renderedColumns.length; i += 1) {
263
282
  const column = renderedColumns[i];
264
- const indexRelativeToAllColumns = firstColumnToRender + i;
283
+ let indexRelativeToAllColumns = firstColumnToRender + i;
284
+ if (focusedCellColumnIndexNotInRange !== undefined && focusedCell) {
285
+ if (visibleColumns[focusedCellColumnIndexNotInRange].field === column.field) {
286
+ indexRelativeToAllColumns = focusedCellColumnIndexNotInRange;
287
+ } else {
288
+ indexRelativeToAllColumns -= 1;
289
+ }
290
+ }
265
291
  const cellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, indexRelativeToAllColumns);
266
292
  if (cellColSpanInfo && !cellColSpanInfo.spannedByColSpan) {
267
293
  if (rowType !== 'skeletonRow') {
@@ -324,12 +350,14 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
324
350
  * If `null`, no cell in this row has focus.
325
351
  */
326
352
  focusedCell: PropTypes.string,
353
+ focusedCellColumnIndexNotInRange: PropTypes.number,
327
354
  /**
328
355
  * Index of the row in the whole sorted and filtered dataset.
329
356
  * If some rows above have expanded children, this index also take those children into account.
330
357
  */
331
358
  index: PropTypes.number.isRequired,
332
359
  isLastVisible: PropTypes.bool,
360
+ isNotVisible: PropTypes.bool,
333
361
  lastColumnToRender: PropTypes.number.isRequired,
334
362
  onClick: PropTypes.func,
335
363
  onDoubleClick: PropTypes.func,
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
- import { GridRowId, GridCellMode } from '../../models';
2
+ import { GridRowId, GridCellMode, GridEditCellProps } from '../../models';
3
3
  import { GridColDef, GridAlignment } from '../../models/colDef/gridColDef';
4
- import { GridEditCellProps } from '../../models/gridEditRowModel';
5
4
  type GridCellV7Props = {
6
5
  align: GridAlignment;
7
6
  className?: string;
@@ -13,6 +12,7 @@ type GridCellV7Props = {
13
12
  width: number;
14
13
  colSpan?: number;
15
14
  disableDragEvents?: boolean;
15
+ isNotVisible?: boolean;
16
16
  editCellState: GridEditCellProps<any> | null;
17
17
  onClick?: React.MouseEventHandler<HTMLDivElement>;
18
18
  onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
@@ -1,8 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["changeReason", "unstable_updateValueOnRender"],
4
- _excluded2 = ["align", "children", "editCellState", "colIndex", "column", "cellMode", "field", "formattedValue", "hasFocus", "height", "isEditable", "isSelected", "rowId", "tabIndex", "value", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
5
- _excluded3 = ["column", "rowId", "editCellState", "align", "children", "colIndex", "height", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
4
+ _excluded2 = ["align", "children", "editCellState", "colIndex", "column", "cellMode", "field", "formattedValue", "hasFocus", "height", "isEditable", "isSelected", "rowId", "tabIndex", "value", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "isNotVisible", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
5
+ _excluded3 = ["column", "rowId", "editCellState", "align", "children", "colIndex", "height", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "isNotVisible", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
6
6
  _excluded4 = ["changeReason", "unstable_updateValueOnRender"];
7
7
  /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
8
8
  import * as React from 'react';
@@ -177,6 +177,7 @@ const GridCell = /*#__PURE__*/React.forwardRef((props, ref) => {
177
177
  showRightBorder,
178
178
  colSpan,
179
179
  disableDragEvents,
180
+ isNotVisible,
180
181
  onClick,
181
182
  onDoubleClick,
182
183
  onMouseDown,
@@ -227,13 +228,23 @@ const GridCell = /*#__PURE__*/React.forwardRef((props, ref) => {
227
228
  propHandler(event);
228
229
  }
229
230
  }, [apiRef, field, rowId]);
230
- const style = {
231
- minWidth: width,
232
- maxWidth: width,
233
- minHeight: height,
234
- maxHeight: height === 'auto' ? 'none' : height // max-height doesn't support "auto"
235
- };
231
+ const style = React.useMemo(() => {
232
+ if (isNotVisible) {
233
+ return {
234
+ padding: 0,
235
+ opacity: 0,
236
+ width: 0
237
+ };
238
+ }
239
+ const cellStyle = {
240
+ minWidth: width,
241
+ maxWidth: width,
242
+ minHeight: height,
243
+ maxHeight: height === 'auto' ? 'none' : height // max-height doesn't support "auto"
244
+ };
236
245
 
246
+ return cellStyle;
247
+ }, [width, height, isNotVisible]);
237
248
  React.useEffect(() => {
238
249
  if (!hasFocus || cellMode === GridCellModes.Edit) {
239
250
  return;
@@ -353,6 +364,7 @@ process.env.NODE_ENV !== "production" ? GridCell.propTypes = {
353
364
  isValidating: PropTypes.bool,
354
365
  value: PropTypes.any
355
366
  }),
367
+ isNotVisible: PropTypes.bool,
356
368
  height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
357
369
  onClick: PropTypes.func,
358
370
  onDoubleClick: PropTypes.func,
@@ -380,6 +392,7 @@ const GridCellV7 = /*#__PURE__*/React.forwardRef((props, ref) => {
380
392
  showRightBorder,
381
393
  colSpan,
382
394
  disableDragEvents,
395
+ isNotVisible,
383
396
  onClick,
384
397
  onDoubleClick,
385
398
  onMouseDown,
@@ -474,13 +487,23 @@ const GridCellV7 = /*#__PURE__*/React.forwardRef((props, ref) => {
474
487
  propHandler(event);
475
488
  }
476
489
  }, [apiRef, field, rowId]);
477
- const style = {
478
- minWidth: width,
479
- maxWidth: width,
480
- minHeight: height,
481
- maxHeight: height === 'auto' ? 'none' : height // max-height doesn't support "auto"
482
- };
490
+ const style = React.useMemo(() => {
491
+ if (isNotVisible) {
492
+ return {
493
+ padding: 0,
494
+ opacity: 0,
495
+ width: 0
496
+ };
497
+ }
498
+ const cellStyle = {
499
+ minWidth: width,
500
+ maxWidth: width,
501
+ minHeight: height,
502
+ maxHeight: height === 'auto' ? 'none' : height // max-height doesn't support "auto"
503
+ };
483
504
 
505
+ return cellStyle;
506
+ }, [width, height, isNotVisible]);
484
507
  React.useEffect(() => {
485
508
  if (!hasFocus || cellMode === GridCellModes.Edit) {
486
509
  return;
@@ -594,6 +617,7 @@ process.env.NODE_ENV !== "production" ? GridCellV7.propTypes = {
594
617
  value: PropTypes.any
595
618
  }),
596
619
  height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
620
+ isNotVisible: PropTypes.bool,
597
621
  onClick: PropTypes.func,
598
622
  onDoubleClick: PropTypes.func,
599
623
  onDragEnter: PropTypes.func,
@@ -159,6 +159,7 @@ export const GridRootStyles = styled('div', {
159
159
  '--unstable_DataGrid-radius': typeof radius === 'number' ? `${radius}px` : radius,
160
160
  '--unstable_DataGrid-headWeight': theme.typography.fontWeightMedium,
161
161
  '--unstable_DataGrid-overlayBackground': theme.vars ? `rgba(${theme.vars.palette.background.defaultChannel} / ${theme.vars.palette.action.disabledOpacity})` : alpha(theme.palette.background.default, theme.palette.action.disabledOpacity),
162
+ '--DataGrid-cellOffsetMultiplier': 2,
162
163
  flex: 1,
163
164
  boxSizing: 'border-box',
164
165
  position: 'relative',
@@ -249,7 +249,7 @@ export const useGridRowSelection = (apiRef, props) => {
249
249
  }
250
250
  if (field) {
251
251
  const column = apiRef.current.getColumn(field);
252
- if (column.type === GRID_ACTIONS_COLUMN_TYPE) {
252
+ if ((column == null ? void 0 : column.type) === GRID_ACTIONS_COLUMN_TYPE) {
253
253
  return;
254
254
  }
255
255
  }
@@ -98,9 +98,33 @@ export const useGridVirtualScroller = props => {
98
98
  const rowStyleCache = React.useRef(Object.create(null));
99
99
  const prevGetRowProps = React.useRef();
100
100
  const prevRootRowStyle = React.useRef();
101
- const getRenderedColumnsRef = React.useRef(defaultMemoize((columns, firstColumnToRender, lastColumnToRender) => {
102
- return columns.slice(firstColumnToRender, lastColumnToRender);
101
+ const getRenderedColumnsRef = React.useRef(defaultMemoize((columns, firstColumnToRender, lastColumnToRender, minFirstColumn, maxLastColumn, indexOfColumnWithFocusedCell) => {
102
+ // If the selected column is not within the current range of columns being displayed,
103
+ // we need to render it at either the left or right of the columns,
104
+ // depending on whether it is above or below the range.
105
+ let focusedCellColumnIndexNotInRange;
106
+ const renderedColumns = columns.slice(firstColumnToRender, lastColumnToRender);
107
+ if (indexOfColumnWithFocusedCell > -1) {
108
+ // check if it is not on the left pinned column.
109
+ if (firstColumnToRender > indexOfColumnWithFocusedCell && indexOfColumnWithFocusedCell >= minFirstColumn) {
110
+ focusedCellColumnIndexNotInRange = indexOfColumnWithFocusedCell;
111
+ }
112
+ // check if it is not on the right pinned column.
113
+ else if (lastColumnToRender < indexOfColumnWithFocusedCell && indexOfColumnWithFocusedCell < maxLastColumn) {
114
+ focusedCellColumnIndexNotInRange = indexOfColumnWithFocusedCell;
115
+ }
116
+ }
117
+ return {
118
+ focusedCellColumnIndexNotInRange,
119
+ renderedColumns
120
+ };
103
121
  }, MEMOIZE_OPTIONS));
122
+ const indexOfColumnWithFocusedCell = React.useMemo(() => {
123
+ if (cellFocus !== null) {
124
+ return visibleColumns.findIndex(column => column.field === cellFocus.field);
125
+ }
126
+ return -1;
127
+ }, [cellFocus, visibleColumns]);
104
128
  const getNearestIndexToRender = React.useCallback(offset => {
105
129
  var _currentPage$range, _currentPage$range2;
106
130
  const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
@@ -308,6 +332,12 @@ export const useGridVirtualScroller = props => {
308
332
  const handleTouchMove = useEventCallback(event => {
309
333
  apiRef.current.publishEvent('virtualScrollerTouchMove', {}, event);
310
334
  });
335
+ const indexOfRowWithFocusedCell = React.useMemo(() => {
336
+ if (cellFocus !== null) {
337
+ return currentPage.rows.findIndex(row => row.id === cellFocus.id);
338
+ }
339
+ return -1;
340
+ }, [cellFocus, currentPage.rows]);
311
341
  const getRows = (params = {
312
342
  renderContext
313
343
  }) => {
@@ -359,6 +389,28 @@ export const useGridVirtualScroller = props => {
359
389
  });
360
390
  }
361
391
  }
392
+ // If the selected row is not within the current range of rows being displayed,
393
+ // we need to render it at either the top or bottom of the rows,
394
+ // depending on whether it is above or below the range.
395
+
396
+ let isRowWithFocusedCellNotInRange = false;
397
+ if (indexOfRowWithFocusedCell > -1) {
398
+ const rowWithFocusedCell = currentPage.rows[indexOfRowWithFocusedCell];
399
+ if (firstRowToRender > indexOfRowWithFocusedCell || lastRowToRender < indexOfRowWithFocusedCell) {
400
+ isRowWithFocusedCellNotInRange = true;
401
+ if (indexOfRowWithFocusedCell > firstRowToRender) {
402
+ renderedRows.push(rowWithFocusedCell);
403
+ } else {
404
+ renderedRows.unshift(rowWithFocusedCell);
405
+ }
406
+ apiRef.current.calculateColSpan({
407
+ rowId: rowWithFocusedCell.id,
408
+ minFirstColumn,
409
+ maxLastColumn,
410
+ columns: visibleColumns
411
+ });
412
+ }
413
+ }
362
414
  const [initialFirstColumnToRender, lastColumnToRender] = getRenderableIndexes({
363
415
  firstIndex: nextRenderContext.firstColumnIndex,
364
416
  lastIndex: nextRenderContext.lastColumnIndex,
@@ -373,7 +425,14 @@ export const useGridVirtualScroller = props => {
373
425
  lastRowToRender,
374
426
  visibleRows: currentPage.rows
375
427
  });
376
- const renderedColumns = getRenderedColumnsRef.current(visibleColumns, firstColumnToRender, lastColumnToRender);
428
+ let isColumnWihFocusedCellNotInRange = false;
429
+ if (firstColumnToRender > indexOfColumnWithFocusedCell || lastColumnToRender < indexOfColumnWithFocusedCell) {
430
+ isColumnWihFocusedCellNotInRange = true;
431
+ }
432
+ const {
433
+ focusedCellColumnIndexNotInRange,
434
+ renderedColumns
435
+ } = getRenderedColumnsRef.current(visibleColumns, firstColumnToRender, lastColumnToRender, minFirstColumn, maxLastColumn, isColumnWihFocusedCellNotInRange ? indexOfColumnWithFocusedCell : -1);
377
436
  const _ref = ((_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.row) || {},
378
437
  {
379
438
  style: rootRowStyle
@@ -390,7 +449,8 @@ export const useGridVirtualScroller = props => {
390
449
  id,
391
450
  model
392
451
  } = renderedRows[i];
393
- const lastVisibleRowIndex = firstRowToRender + i === currentPage.rows.length - 1;
452
+ const isRowNotVisible = isRowWithFocusedCellNotInRange && cellFocus.id === id;
453
+ const lastVisibleRowIndex = isRowWithFocusedCellNotInRange ? firstRowToRender + i === currentPage.rows.length : firstRowToRender + i === currentPage.rows.length - 1;
394
454
  const baseRowHeight = !apiRef.current.rowHasAutoHeight(id) ? apiRef.current.unstable_getRowHeight(id) : 'auto';
395
455
  let isSelected;
396
456
  if (selectedRowsLookup[id] == null) {
@@ -402,6 +462,8 @@ export const useGridVirtualScroller = props => {
402
462
  onRowRender(id);
403
463
  }
404
464
  const focusedCell = cellFocus !== null && cellFocus.id === id ? cellFocus.field : null;
465
+ const columnWithFocusedCellNotInRange = focusedCellColumnIndexNotInRange !== undefined && visibleColumns[focusedCellColumnIndexNotInRange];
466
+ const renderedColumnsWithFocusedCell = columnWithFocusedCellNotInRange && focusedCell ? [columnWithFocusedCellNotInRange, ...renderedColumns] : renderedColumns;
405
467
  let tabbableCell = null;
406
468
  if (cellTabIndex !== null && cellTabIndex.id === id) {
407
469
  const cellParams = apiRef.current.getCellParams(id, cellTabIndex.field);
@@ -419,10 +481,12 @@ export const useGridVirtualScroller = props => {
419
481
  rows.push( /*#__PURE__*/_jsx(rootProps.slots.row, _extends({
420
482
  row: model,
421
483
  rowId: id,
484
+ focusedCellColumnIndexNotInRange: focusedCellColumnIndexNotInRange,
485
+ isNotVisible: isRowNotVisible,
422
486
  rowHeight: baseRowHeight,
423
487
  focusedCell: focusedCell,
424
488
  tabbableCell: tabbableCell,
425
- renderedColumns: renderedColumns,
489
+ renderedColumns: renderedColumnsWithFocusedCell,
426
490
  visibleColumns: visibleColumns,
427
491
  firstColumnToRender: firstColumnToRender,
428
492
  lastColumnToRender: lastColumnToRender,
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.10.1
2
+ * @mui/x-data-grid v6.10.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -43,7 +43,7 @@ export type { GridRowTreeCreationParams, GridRowTreeCreationValue, GridHydrateRo
43
43
  export { getTreeNodeDescendants, buildRootGroup } from '../hooks/features/rows/gridRowsUtils';
44
44
  export { useGridRowsMeta, rowsMetaStateInitializer } from '../hooks/features/rows/useGridRowsMeta';
45
45
  export { useGridParamsApi } from '../hooks/features/rows/useGridParamsApi';
46
- export { getRowIdFromRowModel } from '../hooks/features/rows/gridRowsUtils';
46
+ export { getRowIdFromRowModel, GRID_ID_AUTOGENERATED } from '../hooks/features/rows/gridRowsUtils';
47
47
  export { gridAdditionalRowGroupsSelector, gridPinnedRowsSelector, } from '../hooks/features/rows/gridRowsSelector';
48
48
  export { headerFilteringStateInitializer, useGridHeaderFiltering, } from '../hooks/features/headerFiltering/useGridHeaderFiltering';
49
49
  export { calculatePinnedRowsHeight } from '../hooks/features/rows/gridRowsUtils';
@@ -34,7 +34,7 @@ export { useGridRowsPreProcessors } from '../hooks/features/rows/useGridRowsPreP
34
34
  export { getTreeNodeDescendants, buildRootGroup } from '../hooks/features/rows/gridRowsUtils';
35
35
  export { useGridRowsMeta, rowsMetaStateInitializer } from '../hooks/features/rows/useGridRowsMeta';
36
36
  export { useGridParamsApi } from '../hooks/features/rows/useGridParamsApi';
37
- export { getRowIdFromRowModel } from '../hooks/features/rows/gridRowsUtils';
37
+ export { getRowIdFromRowModel, GRID_ID_AUTOGENERATED } from '../hooks/features/rows/gridRowsUtils';
38
38
  export { gridAdditionalRowGroupsSelector, gridPinnedRowsSelector } from '../hooks/features/rows/gridRowsSelector';
39
39
  export { headerFilteringStateInitializer, useGridHeaderFiltering } from '../hooks/features/headerFiltering/useGridHeaderFiltering';
40
40
  export { calculatePinnedRowsHeight } from '../hooks/features/rows/gridRowsUtils';
@@ -2,7 +2,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
5
+ var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCellColumnIndexNotInRange", "isNotVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import clsx from 'clsx';
@@ -69,6 +69,8 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
69
69
  lastColumnToRender = props.lastColumnToRender,
70
70
  _props$isLastVisible = props.isLastVisible,
71
71
  isLastVisible = _props$isLastVisible === void 0 ? false : _props$isLastVisible,
72
+ focusedCellColumnIndexNotInRange = props.focusedCellColumnIndexNotInRange,
73
+ isNotVisible = props.isNotVisible,
72
74
  focusedCell = props.focusedCell,
73
75
  tabbableCell = props.tabbableCell,
74
76
  onClick = props.onClick,
@@ -180,7 +182,7 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
180
182
 
181
183
  // User clicked a button from the "actions" column type
182
184
  var column = apiRef.current.getColumn(field);
183
- if (column.type === GRID_ACTIONS_COLUMN_TYPE) {
185
+ if ((column == null ? void 0 : column.type) === GRID_ACTIONS_COLUMN_TYPE) {
184
186
  return;
185
187
  }
186
188
  }
@@ -195,6 +197,10 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
195
197
  var _editRowsState$rowId$, _editRowsState$rowId;
196
198
  var disableDragEvents = disableColumnReorder && column.disableReorder || !rowReordering && !!sortModel.length && treeDepth > 1 && Object.keys(editRowsState).length > 0;
197
199
  var editCellState = (_editRowsState$rowId$ = (_editRowsState$rowId = editRowsState[rowId]) == null ? void 0 : _editRowsState$rowId[column.field]) != null ? _editRowsState$rowId$ : null;
200
+ var cellIsNotVisible = false;
201
+ if (focusedCellColumnIndexNotInRange !== undefined && visibleColumns[focusedCellColumnIndexNotInRange].field === column.field) {
202
+ cellIsNotVisible = true;
203
+ }
198
204
  return /*#__PURE__*/_jsx(CellComponent, _extends({
199
205
  column: column,
200
206
  width: cellProps.width,
@@ -205,7 +211,8 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
205
211
  colIndex: cellProps.indexRelativeToAllColumns,
206
212
  colSpan: cellProps.colSpan,
207
213
  disableDragEvents: disableDragEvents,
208
- editCellState: editCellState
214
+ editCellState: editCellState,
215
+ isNotVisible: cellIsNotVisible
209
216
  }, slotProps == null ? void 0 : slotProps.cell), column.field);
210
217
  };
211
218
  var sizes = useGridSelector(apiRef, function () {
@@ -232,25 +239,35 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
232
239
  minHeight = maximumSize;
233
240
  }
234
241
  }
235
- var style = _extends({}, styleProp, {
236
- maxHeight: rowHeight === 'auto' ? 'none' : rowHeight,
237
- // max-height doesn't support "auto"
238
- minHeight: minHeight
239
- });
240
- if (sizes != null && sizes.spacingTop) {
241
- var property = rootProps.rowSpacingType === 'border' ? 'borderTopWidth' : 'marginTop';
242
- style[property] = sizes.spacingTop;
243
- }
244
- if (sizes != null && sizes.spacingBottom) {
245
- var _property = rootProps.rowSpacingType === 'border' ? 'borderBottomWidth' : 'marginBottom';
246
- var propertyValue = style[_property];
247
- // avoid overriding existing value
248
- if (typeof propertyValue !== 'number') {
249
- propertyValue = parseInt(propertyValue || '0', 10);
242
+ var style = React.useMemo(function () {
243
+ if (isNotVisible) {
244
+ return {
245
+ opacity: 0,
246
+ width: 0,
247
+ height: 0
248
+ };
250
249
  }
251
- propertyValue += sizes.spacingBottom;
252
- style[_property] = propertyValue;
253
- }
250
+ var rowStyle = _extends({}, styleProp, {
251
+ maxHeight: rowHeight === 'auto' ? 'none' : rowHeight,
252
+ // max-height doesn't support "auto"
253
+ minHeight: minHeight
254
+ });
255
+ if (sizes != null && sizes.spacingTop) {
256
+ var property = rootProps.rowSpacingType === 'border' ? 'borderTopWidth' : 'marginTop';
257
+ rowStyle[property] = sizes.spacingTop;
258
+ }
259
+ if (sizes != null && sizes.spacingBottom) {
260
+ var _property = rootProps.rowSpacingType === 'border' ? 'borderBottomWidth' : 'marginBottom';
261
+ var propertyValue = rowStyle[_property];
262
+ // avoid overriding existing value
263
+ if (typeof propertyValue !== 'number') {
264
+ propertyValue = parseInt(propertyValue || '0', 10);
265
+ }
266
+ propertyValue += sizes.spacingBottom;
267
+ rowStyle[_property] = propertyValue;
268
+ }
269
+ return rowStyle;
270
+ }, [isNotVisible, rowHeight, styleProp, minHeight, sizes, rootProps.rowSpacingType]);
254
271
  var rowClassNames = apiRef.current.unstable_applyPipeProcessors('rowClassName', [], rowId);
255
272
  if (typeof rootProps.getRowClassName === 'function') {
256
273
  var _currentPage$range;
@@ -272,6 +289,13 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
272
289
  for (var i = 0; i < renderedColumns.length; i += 1) {
273
290
  var column = renderedColumns[i];
274
291
  var indexRelativeToAllColumns = firstColumnToRender + i;
292
+ if (focusedCellColumnIndexNotInRange !== undefined && focusedCell) {
293
+ if (visibleColumns[focusedCellColumnIndexNotInRange].field === column.field) {
294
+ indexRelativeToAllColumns = focusedCellColumnIndexNotInRange;
295
+ } else {
296
+ indexRelativeToAllColumns -= 1;
297
+ }
298
+ }
275
299
  var cellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, indexRelativeToAllColumns);
276
300
  if (cellColSpanInfo && !cellColSpanInfo.spannedByColSpan) {
277
301
  if (rowType !== 'skeletonRow') {
@@ -331,12 +355,14 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
331
355
  * If `null`, no cell in this row has focus.
332
356
  */
333
357
  focusedCell: PropTypes.string,
358
+ focusedCellColumnIndexNotInRange: PropTypes.number,
334
359
  /**
335
360
  * Index of the row in the whole sorted and filtered dataset.
336
361
  * If some rows above have expanded children, this index also take those children into account.
337
362
  */
338
363
  index: PropTypes.number.isRequired,
339
364
  isLastVisible: PropTypes.bool,
365
+ isNotVisible: PropTypes.bool,
340
366
  lastColumnToRender: PropTypes.number.isRequired,
341
367
  onClick: PropTypes.func,
342
368
  onDoubleClick: PropTypes.func,