@mui/x-data-grid 6.0.0-beta.3 → 6.0.0-beta.4

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 (60) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/colDef/gridSingleSelectColDef.d.ts +2 -2
  3. package/colDef/gridSingleSelectColDef.js +4 -1
  4. package/components/GridPagination.d.ts +3 -3
  5. package/components/cell/GridActionsCellItem.d.ts +5 -5
  6. package/components/cell/GridEditInputCell.d.ts +1 -1
  7. package/components/cell/GridEditSingleSelectCell.d.ts +1 -1
  8. package/components/cell/GridEditSingleSelectCell.js +16 -9
  9. package/components/panel/GridColumnsPanel.js +1 -0
  10. package/components/panel/GridPanel.d.ts +1 -1
  11. package/components/panel/GridPanelWrapper.d.ts +4 -0
  12. package/components/panel/GridPanelWrapper.js +15 -5
  13. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +16 -9
  14. package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -1
  15. package/components/panel/filterPanel/GridFilterInputSingleSelect.js +17 -8
  16. package/components/panel/filterPanel/filterPanelUtils.d.ts +2 -1
  17. package/components/panel/filterPanel/filterPanelUtils.js +3 -0
  18. package/components/toolbar/GridToolbar.d.ts +1 -1
  19. package/components/toolbar/GridToolbarColumnsButton.d.ts +1 -1
  20. package/components/toolbar/GridToolbarDensitySelector.d.ts +1 -1
  21. package/components/toolbar/GridToolbarExport.d.ts +1 -1
  22. package/components/toolbar/GridToolbarExportContainer.d.ts +1 -1
  23. package/components/toolbar/GridToolbarFilterButton.d.ts +1 -1
  24. package/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
  25. package/index.js +1 -1
  26. package/internals/index.d.ts +2 -1
  27. package/internals/index.js +1 -0
  28. package/legacy/colDef/gridSingleSelectColDef.js +4 -1
  29. package/legacy/components/cell/GridEditSingleSelectCell.js +16 -9
  30. package/legacy/components/panel/GridColumnsPanel.js +1 -0
  31. package/legacy/components/panel/GridPanelWrapper.js +15 -4
  32. package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +16 -9
  33. package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +17 -8
  34. package/legacy/components/panel/filterPanel/filterPanelUtils.js +3 -0
  35. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
  36. package/legacy/index.js +1 -1
  37. package/legacy/internals/index.js +1 -0
  38. package/models/colDef/gridColDef.d.ts +18 -5
  39. package/models/colDef/index.d.ts +1 -1
  40. package/modern/colDef/gridSingleSelectColDef.js +4 -1
  41. package/modern/components/cell/GridEditSingleSelectCell.js +15 -9
  42. package/modern/components/panel/GridColumnsPanel.js +1 -0
  43. package/modern/components/panel/GridPanelWrapper.js +15 -5
  44. package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +14 -8
  45. package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +17 -8
  46. package/modern/components/panel/filterPanel/filterPanelUtils.js +3 -0
  47. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
  48. package/modern/index.js +1 -1
  49. package/modern/internals/index.js +1 -0
  50. package/node/colDef/gridSingleSelectColDef.js +3 -0
  51. package/node/components/cell/GridEditSingleSelectCell.js +14 -8
  52. package/node/components/panel/GridColumnsPanel.js +1 -0
  53. package/node/components/panel/GridPanelWrapper.js +16 -6
  54. package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +13 -7
  55. package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +16 -7
  56. package/node/components/panel/filterPanel/filterPanelUtils.js +4 -0
  57. package/node/hooks/features/virtualization/useGridVirtualScroller.js +10 -0
  58. package/node/index.js +1 -1
  59. package/node/internals/index.js +7 -0
  60. package/package.json +1 -1
@@ -8,7 +8,7 @@ import MenuItem from '@mui/material/MenuItem';
8
8
  import { isEscapeKey } from '../../utils/keyboardUtils';
9
9
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
10
10
  import { GridEditModes } from '../../models/gridEditRowModel';
11
- import { getLabelFromValueOption, getValueFromValueOptions } from '../panel/filterPanel/filterPanelUtils';
11
+ import { getLabelFromValueOption, getValueFromValueOptions, isSingleSelectColDef } from '../panel/filterPanel/filterPanelUtils';
12
12
  import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  function isKeyboardEvent(event) {
@@ -35,15 +35,26 @@ function GridEditSingleSelectCell(props) {
35
35
  const [open, setOpen] = React.useState(initialOpen);
36
36
  const baseSelectProps = rootProps.componentsProps?.baseSelect || {};
37
37
  const isSelectNative = baseSelectProps.native ?? false;
38
+ useEnhancedEffect(() => {
39
+ if (hasFocus) {
40
+ inputRef.current?.focus();
41
+ }
42
+ }, [hasFocus]);
43
+ if (!isSingleSelectColDef(colDef)) {
44
+ return null;
45
+ }
38
46
  let valueOptions;
39
- if (typeof colDef.valueOptions === 'function') {
40
- valueOptions = colDef.valueOptions({
47
+ if (typeof colDef?.valueOptions === 'function') {
48
+ valueOptions = colDef?.valueOptions({
41
49
  id,
42
50
  row,
43
51
  field
44
52
  });
45
53
  } else {
46
- valueOptions = colDef.valueOptions;
54
+ valueOptions = colDef?.valueOptions;
55
+ }
56
+ if (!valueOptions) {
57
+ return null;
47
58
  }
48
59
  const handleChange = async event => {
49
60
  setOpen(false);
@@ -78,11 +89,6 @@ function GridEditSingleSelectCell(props) {
78
89
  }
79
90
  setOpen(true);
80
91
  };
81
- useEnhancedEffect(() => {
82
- if (hasFocus) {
83
- inputRef.current.focus();
84
- }
85
- }, [hasFocus]);
86
92
  const OptionComponent = isSelectNative ? 'option' : MenuItem;
87
93
  return /*#__PURE__*/_jsx(rootProps.components.BaseSelect, _extends({
88
94
  ref: ref,
@@ -195,6 +195,7 @@ process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
195
195
  disableHideAllButton: PropTypes.bool,
196
196
  disableShowAllButton: PropTypes.bool,
197
197
  searchPredicate: PropTypes.func,
198
+ slotProps: PropTypes.object,
198
199
  sort: PropTypes.oneOf(['asc', 'desc'])
199
200
  } : void 0;
200
201
  export { GridColumnsPanel };
@@ -1,7 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["className"];
3
+ const _excluded = ["className", "slotProps"];
4
4
  import * as React from 'react';
5
+ import PropTypes from 'prop-types';
5
6
  import clsx from 'clsx';
6
7
  import TrapFocus from '@mui/material/Unstable_TrapFocus';
7
8
  import { styled } from '@mui/material/styles';
@@ -33,7 +34,8 @@ const GridPanelWrapperRoot = styled('div', {
33
34
  const isEnabled = () => true;
34
35
  const GridPanelWrapper = /*#__PURE__*/React.forwardRef(function GridPanelWrapper(props, ref) {
35
36
  const {
36
- className
37
+ className,
38
+ slotProps = {}
37
39
  } = props,
38
40
  other = _objectWithoutPropertiesLoose(props, _excluded);
39
41
  const rootProps = useGridRootProps();
@@ -41,15 +43,23 @@ const GridPanelWrapper = /*#__PURE__*/React.forwardRef(function GridPanelWrapper
41
43
  classes: rootProps.classes
42
44
  };
43
45
  const classes = useUtilityClasses(ownerState);
44
- return /*#__PURE__*/_jsx(TrapFocus, {
46
+ return /*#__PURE__*/_jsx(TrapFocus, _extends({
45
47
  open: true,
46
48
  disableEnforceFocus: true,
47
- isEnabled: isEnabled,
49
+ isEnabled: isEnabled
50
+ }, slotProps.TrapFocus, {
48
51
  children: /*#__PURE__*/_jsx(GridPanelWrapperRoot, _extends({
49
52
  ref: ref,
50
53
  tabIndex: -1,
51
54
  className: clsx(className, classes.root)
52
55
  }, other))
53
- });
56
+ }));
54
57
  });
58
+ process.env.NODE_ENV !== "production" ? GridPanelWrapper.propTypes = {
59
+ // ----------------------------- Warning --------------------------------
60
+ // | These PropTypes are generated from the TypeScript type definitions |
61
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
62
+ // ----------------------------------------------------------------------
63
+ slotProps: PropTypes.object
64
+ } : void 0;
55
65
  export { GridPanelWrapper };
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
6
6
  import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
7
7
  import Chip from '@mui/material/Chip';
8
8
  import { unstable_useId as useId } from '@mui/utils';
9
- import { getLabelFromValueOption, getValueFromOption } from './filterPanelUtils';
9
+ import { getLabelFromValueOption, getValueFromOption, isSingleSelectColDef } from './filterPanelUtils';
10
10
  import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  const isOptionEqualToValue = (option, value) => getValueFromOption(option) === getValueFromOption(value);
@@ -34,7 +34,13 @@ function GridFilterInputMultipleSingleSelect(props) {
34
34
  };
35
35
  const id = useId();
36
36
  const rootProps = useGridRootProps();
37
- const resolvedColumn = item.field ? apiRef.current.getColumn(item.field) : null;
37
+ let resolvedColumn = null;
38
+ if (item.field) {
39
+ const column = apiRef.current.getColumn(item.field);
40
+ if (isSingleSelectColDef(column)) {
41
+ resolvedColumn = column;
42
+ }
43
+ }
38
44
  const resolvedValueOptions = React.useMemo(() => {
39
45
  if (!resolvedColumn?.valueOptions) {
40
46
  return [];
@@ -52,7 +58,7 @@ function GridFilterInputMultipleSingleSelect(props) {
52
58
 
53
59
  // The value is computed from the item.value and used directly
54
60
  // If it was done by a useEffect/useState, the Autocomplete could receive incoherent value and options
55
- const filterValues = React.useMemo(() => {
61
+ const filteredValues = React.useMemo(() => {
56
62
  if (!Array.isArray(item.value)) {
57
63
  return [];
58
64
  }
@@ -68,13 +74,13 @@ function GridFilterInputMultipleSingleSelect(props) {
68
74
  return item.value;
69
75
  }, [item.value, resolvedValueOptions, resolvedFormattedValueOptions]);
70
76
  React.useEffect(() => {
71
- if (!Array.isArray(item.value) || filterValues.length !== item.value.length) {
72
- // update the state if the filter value has been cleaned by the component
77
+ if (!Array.isArray(item.value) || filteredValues.length !== item.value.length) {
78
+ // Updates the state if the filter value has been cleaned by the component
73
79
  applyValue(_extends({}, item, {
74
- value: filterValues.map(getValueFromOption)
80
+ value: filteredValues.map(getValueFromOption)
75
81
  }));
76
82
  }
77
- }, [item, filterValues, applyValue]);
83
+ }, [item, filteredValues, applyValue]);
78
84
  const handleChange = React.useCallback((event, value) => {
79
85
  applyValue(_extends({}, item, {
80
86
  value: [...value.map(getValueFromOption)]
@@ -86,7 +92,7 @@ function GridFilterInputMultipleSingleSelect(props) {
86
92
  isOptionEqualToValue: isOptionEqualToValue,
87
93
  filterOptions: filter,
88
94
  id: id,
89
- value: filterValues,
95
+ value: filteredValues,
90
96
  onChange: handleChange,
91
97
  getOptionLabel: getOptionLabel,
92
98
  renderTags: (value, getTagProps) => value.map((option, index) => /*#__PURE__*/_jsx(Chip, _extends({
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
6
6
  import { unstable_useId as useId } from '@mui/utils';
7
7
  import MenuItem from '@mui/material/MenuItem';
8
8
  import { useGridRootProps } from '../../../hooks/utils/useGridRootProps';
9
- import { getLabelFromValueOption, getValueFromValueOptions } from './filterPanelUtils';
9
+ import { getLabelFromValueOption, getValueFromValueOptions, isSingleSelectColDef } from './filterPanelUtils';
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  const renderSingleSelectOptions = ({
12
12
  valueOptions,
@@ -40,15 +40,21 @@ function GridFilterInputSingleSelect(props) {
40
40
  const rootProps = useGridRootProps();
41
41
  const baseSelectProps = rootProps.componentsProps?.baseSelect || {};
42
42
  const isSelectNative = baseSelectProps.native ?? true;
43
- const currentColumn = item.field ? apiRef.current.getColumn(item.field) : null;
43
+ let resolvedColumn = null;
44
+ if (item.field) {
45
+ const column = apiRef.current.getColumn(item.field);
46
+ if (isSingleSelectColDef(column)) {
47
+ resolvedColumn = column;
48
+ }
49
+ }
44
50
  const currentValueOptions = React.useMemo(() => {
45
- if (currentColumn === null) {
51
+ if (!resolvedColumn) {
46
52
  return undefined;
47
53
  }
48
- return typeof currentColumn.valueOptions === 'function' ? currentColumn.valueOptions({
49
- field: currentColumn.field
50
- }) : currentColumn.valueOptions;
51
- }, [currentColumn]);
54
+ return typeof resolvedColumn.valueOptions === 'function' ? resolvedColumn.valueOptions({
55
+ field: resolvedColumn.field
56
+ }) : resolvedColumn.valueOptions;
57
+ }, [resolvedColumn]);
52
58
  const onFilterChange = React.useCallback(event => {
53
59
  let value = event.target.value;
54
60
 
@@ -76,6 +82,9 @@ function GridFilterInputSingleSelect(props) {
76
82
  itemValue = itemValue ?? '';
77
83
  setFilterValueState(String(itemValue));
78
84
  }, [item, currentValueOptions, applyValue]);
85
+ if (!isSingleSelectColDef(resolvedColumn)) {
86
+ return null;
87
+ }
79
88
  return /*#__PURE__*/_jsx(rootProps.components.BaseTextField, _extends({
80
89
  id: id,
81
90
  label: apiRef.current.getLocaleText('filterPanelInputLabel'),
@@ -93,7 +102,7 @@ function GridFilterInputSingleSelect(props) {
93
102
  native: isSelectNative
94
103
  }, rootProps.componentsProps?.baseSelect)
95
104
  }, others, rootProps.componentsProps?.baseTextField, {
96
- children: renderSingleSelectOptions(apiRef.current.getColumn(item.field), isSelectNative ? 'option' : MenuItem, getOptionLabel)
105
+ children: renderSingleSelectOptions(resolvedColumn, isSelectNative ? 'option' : MenuItem, getOptionLabel)
97
106
  }));
98
107
  }
99
108
  process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes = {
@@ -1,3 +1,6 @@
1
+ export function isSingleSelectColDef(colDef) {
2
+ return colDef?.type === 'singleSelect';
3
+ }
1
4
  export function getValueFromOption(option) {
2
5
  if (typeof option === 'object' && option !== null) {
3
6
  return option.value;
@@ -51,6 +51,12 @@ export const getRenderableIndexes = ({
51
51
  }) => {
52
52
  return [clamp(firstIndex - buffer, minFirstIndex, maxLastIndex), clamp(lastIndex + buffer, minFirstIndex, maxLastIndex)];
53
53
  };
54
+ const areRenderContextsEqual = (context1, context2) => {
55
+ if (context1 === context2) {
56
+ return true;
57
+ }
58
+ return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
59
+ };
54
60
  export const useGridVirtualScroller = props => {
55
61
  const apiRef = useGridPrivateApiContext();
56
62
  const rootProps = useGridRootProps();
@@ -205,6 +211,10 @@ export const useGridVirtualScroller = props => {
205
211
  }
206
212
  }, [apiRef, currentPage.rows, onRenderZonePositioning, renderZoneMinColumnIndex, renderZoneMaxColumnIndex, rootProps.columnBuffer, rootProps.rowBuffer, theme.direction]);
207
213
  const updateRenderContext = React.useCallback(nextRenderContext => {
214
+ if (prevRenderContext.current && areRenderContextsEqual(nextRenderContext, prevRenderContext.current)) {
215
+ updateRenderZonePosition(nextRenderContext);
216
+ return;
217
+ }
208
218
  setRenderContext(nextRenderContext);
209
219
  updateRenderZonePosition(nextRenderContext);
210
220
  const [firstRowToRender, lastRowToRender] = getRenderableIndexes({
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.0.0-beta.3
2
+ * @mui/x-data-grid v6.0.0-beta.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -18,6 +18,7 @@ export { useGridCsvExport } from '../hooks/features/export/useGridCsvExport';
18
18
  export { useGridPrintExport } from '../hooks/features/export/useGridPrintExport';
19
19
  export { useGridFilter, filterStateInitializer } from '../hooks/features/filter/useGridFilter';
20
20
  export { passFilterLogic } from '../hooks/features/filter/gridFilterUtils';
21
+ export { isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
21
22
  export { useGridFocus, focusStateInitializer } from '../hooks/features/focus/useGridFocus';
22
23
  export { useGridKeyboardNavigation } from '../hooks/features/keyboardNavigation/useGridKeyboardNavigation';
23
24
  export { useGridPagination, paginationStateInitializer } from '../hooks/features/pagination/useGridPagination';
@@ -23,6 +23,9 @@ const GRID_SINGLE_SELECT_COL_DEF = (0, _extends2.default)({}, _gridStringColDef.
23
23
  api
24
24
  } = params;
25
25
  const colDef = params.api.getColumn(field);
26
+ if (!(0, _filterPanelUtils.isSingleSelectColDef)(colDef)) {
27
+ return '';
28
+ }
26
29
  let valueOptions;
27
30
  if (typeof colDef.valueOptions === 'function') {
28
31
  valueOptions = colDef.valueOptions({
@@ -45,15 +45,26 @@ function GridEditSingleSelectCell(props) {
45
45
  const [open, setOpen] = React.useState(initialOpen);
46
46
  const baseSelectProps = rootProps.componentsProps?.baseSelect || {};
47
47
  const isSelectNative = baseSelectProps.native ?? false;
48
+ (0, _utils.unstable_useEnhancedEffect)(() => {
49
+ if (hasFocus) {
50
+ inputRef.current?.focus();
51
+ }
52
+ }, [hasFocus]);
53
+ if (!(0, _filterPanelUtils.isSingleSelectColDef)(colDef)) {
54
+ return null;
55
+ }
48
56
  let valueOptions;
49
- if (typeof colDef.valueOptions === 'function') {
50
- valueOptions = colDef.valueOptions({
57
+ if (typeof colDef?.valueOptions === 'function') {
58
+ valueOptions = colDef?.valueOptions({
51
59
  id,
52
60
  row,
53
61
  field
54
62
  });
55
63
  } else {
56
- valueOptions = colDef.valueOptions;
64
+ valueOptions = colDef?.valueOptions;
65
+ }
66
+ if (!valueOptions) {
67
+ return null;
57
68
  }
58
69
  const handleChange = async event => {
59
70
  setOpen(false);
@@ -88,11 +99,6 @@ function GridEditSingleSelectCell(props) {
88
99
  }
89
100
  setOpen(true);
90
101
  };
91
- (0, _utils.unstable_useEnhancedEffect)(() => {
92
- if (hasFocus) {
93
- inputRef.current.focus();
94
- }
95
- }, [hasFocus]);
96
102
  const OptionComponent = isSelectNative ? 'option' : _MenuItem.default;
97
103
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.components.BaseSelect, (0, _extends2.default)({
98
104
  ref: ref,
@@ -203,5 +203,6 @@ process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
203
203
  disableHideAllButton: _propTypes.default.bool,
204
204
  disableShowAllButton: _propTypes.default.bool,
205
205
  searchPredicate: _propTypes.default.func,
206
+ slotProps: _propTypes.default.object,
206
207
  sort: _propTypes.default.oneOf(['asc', 'desc'])
207
208
  } : void 0;
@@ -8,6 +8,7 @@ exports.GridPanelWrapper = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
10
  var React = _interopRequireWildcard(require("react"));
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
12
  var _clsx = _interopRequireDefault(require("clsx"));
12
13
  var _Unstable_TrapFocus = _interopRequireDefault(require("@mui/material/Unstable_TrapFocus"));
13
14
  var _styles = require("@mui/material/styles");
@@ -15,7 +16,7 @@ var _utils = require("@mui/utils");
15
16
  var _gridClasses = require("../../constants/gridClasses");
16
17
  var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
17
18
  var _jsxRuntime = require("react/jsx-runtime");
18
- const _excluded = ["className"];
19
+ const _excluded = ["className", "slotProps"];
19
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
21
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
22
  const useUtilityClasses = ownerState => {
@@ -42,7 +43,8 @@ const GridPanelWrapperRoot = (0, _styles.styled)('div', {
42
43
  const isEnabled = () => true;
43
44
  const GridPanelWrapper = /*#__PURE__*/React.forwardRef(function GridPanelWrapper(props, ref) {
44
45
  const {
45
- className
46
+ className,
47
+ slotProps = {}
46
48
  } = props,
47
49
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
48
50
  const rootProps = (0, _useGridRootProps.useGridRootProps)();
@@ -50,15 +52,23 @@ const GridPanelWrapper = /*#__PURE__*/React.forwardRef(function GridPanelWrapper
50
52
  classes: rootProps.classes
51
53
  };
52
54
  const classes = useUtilityClasses(ownerState);
53
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_TrapFocus.default, {
55
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Unstable_TrapFocus.default, (0, _extends2.default)({
54
56
  open: true,
55
57
  disableEnforceFocus: true,
56
- isEnabled: isEnabled,
58
+ isEnabled: isEnabled
59
+ }, slotProps.TrapFocus, {
57
60
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(GridPanelWrapperRoot, (0, _extends2.default)({
58
61
  ref: ref,
59
62
  tabIndex: -1,
60
63
  className: (0, _clsx.default)(className, classes.root)
61
64
  }, other))
62
- });
65
+ }));
63
66
  });
64
- exports.GridPanelWrapper = GridPanelWrapper;
67
+ exports.GridPanelWrapper = GridPanelWrapper;
68
+ process.env.NODE_ENV !== "production" ? GridPanelWrapper.propTypes = {
69
+ // ----------------------------- Warning --------------------------------
70
+ // | These PropTypes are generated from the TypeScript type definitions |
71
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
72
+ // ----------------------------------------------------------------------
73
+ slotProps: _propTypes.default.object
74
+ } : void 0;
@@ -43,7 +43,13 @@ function GridFilterInputMultipleSingleSelect(props) {
43
43
  };
44
44
  const id = (0, _utils.unstable_useId)();
45
45
  const rootProps = (0, _useGridRootProps.useGridRootProps)();
46
- const resolvedColumn = item.field ? apiRef.current.getColumn(item.field) : null;
46
+ let resolvedColumn = null;
47
+ if (item.field) {
48
+ const column = apiRef.current.getColumn(item.field);
49
+ if ((0, _filterPanelUtils.isSingleSelectColDef)(column)) {
50
+ resolvedColumn = column;
51
+ }
52
+ }
47
53
  const resolvedValueOptions = React.useMemo(() => {
48
54
  if (!resolvedColumn?.valueOptions) {
49
55
  return [];
@@ -61,7 +67,7 @@ function GridFilterInputMultipleSingleSelect(props) {
61
67
 
62
68
  // The value is computed from the item.value and used directly
63
69
  // If it was done by a useEffect/useState, the Autocomplete could receive incoherent value and options
64
- const filterValues = React.useMemo(() => {
70
+ const filteredValues = React.useMemo(() => {
65
71
  if (!Array.isArray(item.value)) {
66
72
  return [];
67
73
  }
@@ -77,13 +83,13 @@ function GridFilterInputMultipleSingleSelect(props) {
77
83
  return item.value;
78
84
  }, [item.value, resolvedValueOptions, resolvedFormattedValueOptions]);
79
85
  React.useEffect(() => {
80
- if (!Array.isArray(item.value) || filterValues.length !== item.value.length) {
81
- // update the state if the filter value has been cleaned by the component
86
+ if (!Array.isArray(item.value) || filteredValues.length !== item.value.length) {
87
+ // Updates the state if the filter value has been cleaned by the component
82
88
  applyValue((0, _extends2.default)({}, item, {
83
- value: filterValues.map(_filterPanelUtils.getValueFromOption)
89
+ value: filteredValues.map(_filterPanelUtils.getValueFromOption)
84
90
  }));
85
91
  }
86
- }, [item, filterValues, applyValue]);
92
+ }, [item, filteredValues, applyValue]);
87
93
  const handleChange = React.useCallback((event, value) => {
88
94
  applyValue((0, _extends2.default)({}, item, {
89
95
  value: [...value.map(_filterPanelUtils.getValueFromOption)]
@@ -95,7 +101,7 @@ function GridFilterInputMultipleSingleSelect(props) {
95
101
  isOptionEqualToValue: isOptionEqualToValue,
96
102
  filterOptions: filter,
97
103
  id: id,
98
- value: filterValues,
104
+ value: filteredValues,
99
105
  onChange: handleChange,
100
106
  getOptionLabel: getOptionLabel,
101
107
  renderTags: (value, getTagProps) => value.map((option, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, (0, _extends2.default)({
@@ -49,15 +49,21 @@ function GridFilterInputSingleSelect(props) {
49
49
  const rootProps = (0, _useGridRootProps.useGridRootProps)();
50
50
  const baseSelectProps = rootProps.componentsProps?.baseSelect || {};
51
51
  const isSelectNative = baseSelectProps.native ?? true;
52
- const currentColumn = item.field ? apiRef.current.getColumn(item.field) : null;
52
+ let resolvedColumn = null;
53
+ if (item.field) {
54
+ const column = apiRef.current.getColumn(item.field);
55
+ if ((0, _filterPanelUtils.isSingleSelectColDef)(column)) {
56
+ resolvedColumn = column;
57
+ }
58
+ }
53
59
  const currentValueOptions = React.useMemo(() => {
54
- if (currentColumn === null) {
60
+ if (!resolvedColumn) {
55
61
  return undefined;
56
62
  }
57
- return typeof currentColumn.valueOptions === 'function' ? currentColumn.valueOptions({
58
- field: currentColumn.field
59
- }) : currentColumn.valueOptions;
60
- }, [currentColumn]);
63
+ return typeof resolvedColumn.valueOptions === 'function' ? resolvedColumn.valueOptions({
64
+ field: resolvedColumn.field
65
+ }) : resolvedColumn.valueOptions;
66
+ }, [resolvedColumn]);
61
67
  const onFilterChange = React.useCallback(event => {
62
68
  let value = event.target.value;
63
69
 
@@ -85,6 +91,9 @@ function GridFilterInputSingleSelect(props) {
85
91
  itemValue = itemValue ?? '';
86
92
  setFilterValueState(String(itemValue));
87
93
  }, [item, currentValueOptions, applyValue]);
94
+ if (!(0, _filterPanelUtils.isSingleSelectColDef)(resolvedColumn)) {
95
+ return null;
96
+ }
88
97
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.components.BaseTextField, (0, _extends2.default)({
89
98
  id: id,
90
99
  label: apiRef.current.getLocaleText('filterPanelInputLabel'),
@@ -102,7 +111,7 @@ function GridFilterInputSingleSelect(props) {
102
111
  native: isSelectNative
103
112
  }, rootProps.componentsProps?.baseSelect)
104
113
  }, others, rootProps.componentsProps?.baseTextField, {
105
- children: renderSingleSelectOptions(apiRef.current.getColumn(item.field), isSelectNative ? 'option' : _MenuItem.default, getOptionLabel)
114
+ children: renderSingleSelectOptions(resolvedColumn, isSelectNative ? 'option' : _MenuItem.default, getOptionLabel)
106
115
  }));
107
116
  }
108
117
  process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes = {
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getLabelFromValueOption = void 0;
7
7
  exports.getValueFromOption = getValueFromOption;
8
8
  exports.getValueFromValueOptions = getValueFromValueOptions;
9
+ exports.isSingleSelectColDef = isSingleSelectColDef;
10
+ function isSingleSelectColDef(colDef) {
11
+ return colDef?.type === 'singleSelect';
12
+ }
9
13
  function getValueFromOption(option) {
10
14
  if (typeof option === 'object' && option !== null) {
11
15
  return option.value;
@@ -61,6 +61,12 @@ const getRenderableIndexes = ({
61
61
  return [(0, _utils2.clamp)(firstIndex - buffer, minFirstIndex, maxLastIndex), (0, _utils2.clamp)(lastIndex + buffer, minFirstIndex, maxLastIndex)];
62
62
  };
63
63
  exports.getRenderableIndexes = getRenderableIndexes;
64
+ const areRenderContextsEqual = (context1, context2) => {
65
+ if (context1 === context2) {
66
+ return true;
67
+ }
68
+ return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
69
+ };
64
70
  const useGridVirtualScroller = props => {
65
71
  const apiRef = (0, _useGridPrivateApiContext.useGridPrivateApiContext)();
66
72
  const rootProps = (0, _useGridRootProps.useGridRootProps)();
@@ -215,6 +221,10 @@ const useGridVirtualScroller = props => {
215
221
  }
216
222
  }, [apiRef, currentPage.rows, onRenderZonePositioning, renderZoneMinColumnIndex, renderZoneMaxColumnIndex, rootProps.columnBuffer, rootProps.rowBuffer, theme.direction]);
217
223
  const updateRenderContext = React.useCallback(nextRenderContext => {
224
+ if (prevRenderContext.current && areRenderContextsEqual(nextRenderContext, prevRenderContext.current)) {
225
+ updateRenderZonePosition(nextRenderContext);
226
+ return;
227
+ }
218
228
  setRenderContext(nextRenderContext);
219
229
  updateRenderZonePosition(nextRenderContext);
220
230
  const [firstRowToRender, lastRowToRender] = getRenderableIndexes({
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.0.0-beta.3
2
+ * @mui/x-data-grid v6.0.0-beta.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -207,6 +207,12 @@ Object.defineProperty(exports, "isObject", {
207
207
  return _utils2.isObject;
208
208
  }
209
209
  });
210
+ Object.defineProperty(exports, "isSingleSelectColDef", {
211
+ enumerable: true,
212
+ get: function () {
213
+ return _filterPanelUtils.isSingleSelectColDef;
214
+ }
215
+ });
210
216
  Object.defineProperty(exports, "paginationStateInitializer", {
211
217
  enumerable: true,
212
218
  get: function () {
@@ -473,6 +479,7 @@ var _useGridCsvExport = require("../hooks/features/export/useGridCsvExport");
473
479
  var _useGridPrintExport = require("../hooks/features/export/useGridPrintExport");
474
480
  var _useGridFilter = require("../hooks/features/filter/useGridFilter");
475
481
  var _gridFilterUtils = require("../hooks/features/filter/gridFilterUtils");
482
+ var _filterPanelUtils = require("../components/panel/filterPanel/filterPanelUtils");
476
483
  var _useGridFocus = require("../hooks/features/focus/useGridFocus");
477
484
  var _useGridKeyboardNavigation = require("../hooks/features/keyboardNavigation/useGridKeyboardNavigation");
478
485
  var _useGridPagination = require("../hooks/features/pagination/useGridPagination");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "6.0.0-beta.3",
3
+ "version": "6.0.0-beta.4",
4
4
  "description": "The community edition of the data grid component (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",