@mui/x-data-grid 7.0.0-alpha.5 → 7.0.0-alpha.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.
- package/CHANGELOG.md +226 -6
- package/DataGrid/DataGrid.js +25 -19
- package/DataGrid/useDataGridProps.js +0 -1
- package/colDef/gridDateOperators.js +13 -6
- package/colDef/gridSingleSelectColDef.js +6 -15
- package/components/cell/GridEditSingleSelectCell.d.ts +1 -2
- package/components/cell/GridEditSingleSelectCell.js +9 -29
- package/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/components/panel/filterPanel/GridFilterForm.js +44 -9
- package/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +25 -8
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -2
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -48
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -2
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -57
- package/components/panel/filterPanel/filterPanelUtils.d.ts +3 -2
- package/components/panel/filterPanel/filterPanelUtils.js +10 -5
- package/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/hooks/features/rowSelection/utils.d.ts +2 -0
- package/hooks/features/rowSelection/utils.js +8 -0
- package/hooks/utils/useGridAriaAttributes.js +2 -1
- package/index.js +1 -1
- package/legacy/DataGrid/DataGrid.js +25 -19
- package/legacy/DataGrid/useDataGridProps.js +0 -1
- package/legacy/colDef/gridDateOperators.js +13 -13
- package/legacy/colDef/gridSingleSelectColDef.js +6 -15
- package/legacy/components/cell/GridEditSingleSelectCell.js +8 -28
- package/legacy/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/legacy/components/panel/filterPanel/GridFilterForm.js +51 -19
- package/legacy/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterInputDate.js +27 -8
- package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -53
- package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -59
- package/legacy/components/panel/filterPanel/filterPanelUtils.js +10 -6
- package/legacy/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/legacy/hooks/features/rowSelection/utils.js +8 -0
- package/legacy/hooks/utils/useGridAriaAttributes.js +2 -1
- package/legacy/index.js +1 -1
- package/models/props/DataGridProps.d.ts +26 -25
- package/modern/DataGrid/DataGrid.js +25 -19
- package/modern/DataGrid/useDataGridProps.js +0 -1
- package/modern/colDef/gridDateOperators.js +13 -6
- package/modern/colDef/gridSingleSelectColDef.js +6 -15
- package/modern/components/cell/GridEditSingleSelectCell.js +9 -29
- package/modern/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/modern/components/panel/filterPanel/GridFilterForm.js +44 -9
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +24 -6
- package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +7 -47
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +15 -56
- package/modern/components/panel/filterPanel/filterPanelUtils.js +10 -5
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/modern/hooks/features/rowSelection/utils.js +8 -0
- package/modern/hooks/utils/useGridAriaAttributes.js +2 -1
- package/modern/index.js +1 -1
- package/node/DataGrid/DataGrid.js +25 -19
- package/node/DataGrid/useDataGridProps.js +0 -1
- package/node/colDef/gridDateOperators.js +13 -6
- package/node/colDef/gridSingleSelectColDef.js +5 -14
- package/node/components/cell/GridEditSingleSelectCell.js +8 -28
- package/node/components/columnSelection/GridHeaderCheckbox.js +3 -1
- package/node/components/panel/filterPanel/GridFilterForm.js +44 -9
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputDate.js +24 -6
- package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -46
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +14 -55
- package/node/components/panel/filterPanel/filterPanelUtils.js +12 -7
- package/node/hooks/features/rowSelection/useGridRowSelection.js +9 -9
- package/node/hooks/features/rowSelection/utils.js +14 -0
- package/node/hooks/utils/useGridAriaAttributes.js +2 -1
- package/node/index.js +1 -1
- package/package.json +3 -3
|
@@ -14,7 +14,7 @@ var _utils = require("@mui/utils");
|
|
|
14
14
|
var _filterPanelUtils = require("./filterPanelUtils");
|
|
15
15
|
var _useGridRootProps = require("../../../hooks/utils/useGridRootProps");
|
|
16
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
-
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "color", "error", "helperText", "size", "variant"
|
|
17
|
+
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "color", "error", "helperText", "size", "variant"];
|
|
18
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
19
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
20
|
const filter = (0, _Autocomplete.createFilterOptions)();
|
|
@@ -28,9 +28,7 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
28
28
|
error,
|
|
29
29
|
helperText,
|
|
30
30
|
size,
|
|
31
|
-
variant = 'standard'
|
|
32
|
-
getOptionLabel: getOptionLabelProp,
|
|
33
|
-
getOptionValue: getOptionValueProp
|
|
31
|
+
variant = 'standard'
|
|
34
32
|
} = props,
|
|
35
33
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
36
34
|
const TextFieldProps = {
|
|
@@ -49,23 +47,12 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
49
47
|
resolvedColumn = column;
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
const getOptionValue =
|
|
53
|
-
const getOptionLabel =
|
|
50
|
+
const getOptionValue = resolvedColumn?.getOptionValue;
|
|
51
|
+
const getOptionLabel = resolvedColumn?.getOptionLabel;
|
|
54
52
|
const isOptionEqualToValue = React.useCallback((option, value) => getOptionValue(option) === getOptionValue(value), [getOptionValue]);
|
|
55
53
|
const resolvedValueOptions = React.useMemo(() => {
|
|
56
|
-
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
if (typeof resolvedColumn.valueOptions === 'function') {
|
|
60
|
-
return resolvedColumn.valueOptions({
|
|
61
|
-
field: resolvedColumn.field
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return resolvedColumn.valueOptions;
|
|
54
|
+
return (0, _filterPanelUtils.getValueOptions)(resolvedColumn) || [];
|
|
65
55
|
}, [resolvedColumn]);
|
|
66
|
-
const resolvedFormattedValueOptions = React.useMemo(() => {
|
|
67
|
-
return resolvedValueOptions?.map(getOptionValue);
|
|
68
|
-
}, [resolvedValueOptions, getOptionValue]);
|
|
69
56
|
|
|
70
57
|
// The value is computed from the item.value and used directly
|
|
71
58
|
// If it was done by a useEffect/useState, the Autocomplete could receive incoherent value and options
|
|
@@ -73,23 +60,8 @@ function GridFilterInputMultipleSingleSelect(props) {
|
|
|
73
60
|
if (!Array.isArray(item.value)) {
|
|
74
61
|
return [];
|
|
75
62
|
}
|
|
76
|
-
if (resolvedValueOptions !== undefined) {
|
|
77
|
-
const itemValueIndexes = item.value.map(element => {
|
|
78
|
-
// Gets the index matching between values and valueOptions
|
|
79
|
-
return resolvedFormattedValueOptions?.findIndex(formattedOption => formattedOption === element);
|
|
80
|
-
});
|
|
81
|
-
return itemValueIndexes.filter(index => index >= 0).map(index => resolvedValueOptions[index]);
|
|
82
|
-
}
|
|
83
63
|
return item.value;
|
|
84
|
-
}, [item.value
|
|
85
|
-
React.useEffect(() => {
|
|
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
|
|
88
|
-
applyValue((0, _extends2.default)({}, item, {
|
|
89
|
-
value: filteredValues.map(getOptionValue)
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
}, [item, filteredValues, applyValue, getOptionValue]);
|
|
64
|
+
}, [item.value]);
|
|
93
65
|
const handleChange = React.useCallback((event, value) => {
|
|
94
66
|
applyValue((0, _extends2.default)({}, item, {
|
|
95
67
|
value: value.map(getOptionValue)
|
|
@@ -132,18 +104,6 @@ process.env.NODE_ENV !== "production" ? GridFilterInputMultipleSingleSelect.prop
|
|
|
132
104
|
}).isRequired,
|
|
133
105
|
applyValue: _propTypes.default.func.isRequired,
|
|
134
106
|
focusElementRef: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.func, _propTypes.default.object]),
|
|
135
|
-
/**
|
|
136
|
-
* Used to determine the label displayed for a given value option.
|
|
137
|
-
* @param {ValueOptions} value The current value option.
|
|
138
|
-
* @returns {string} The text to be displayed.
|
|
139
|
-
*/
|
|
140
|
-
getOptionLabel: _propTypes.default.func,
|
|
141
|
-
/**
|
|
142
|
-
* Used to determine the value used for a value option.
|
|
143
|
-
* @param {ValueOptions} value The current value option.
|
|
144
|
-
* @returns {string} The value to be used.
|
|
145
|
-
*/
|
|
146
|
-
getOptionValue: _propTypes.default.func,
|
|
147
107
|
item: _propTypes.default.shape({
|
|
148
108
|
field: _propTypes.default.string.isRequired,
|
|
149
109
|
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
|
|
@@ -15,26 +15,24 @@ var _styles = require("@mui/material/styles");
|
|
|
15
15
|
var _useGridRootProps = require("../../../hooks/utils/useGridRootProps");
|
|
16
16
|
var _filterPanelUtils = require("./filterPanelUtils");
|
|
17
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "
|
|
18
|
+
const _excluded = ["item", "applyValue", "type", "apiRef", "focusElementRef", "placeholder", "tabIndex", "label", "isFilterActive", "clearButton", "InputLabelProps"];
|
|
19
19
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
21
|
const renderSingleSelectOptions = ({
|
|
22
|
-
column
|
|
23
|
-
valueOptions,
|
|
24
|
-
field
|
|
25
|
-
},
|
|
22
|
+
column,
|
|
26
23
|
OptionComponent,
|
|
27
24
|
getOptionLabel,
|
|
28
25
|
getOptionValue,
|
|
29
26
|
isSelectNative,
|
|
30
27
|
baseSelectOptionProps
|
|
31
28
|
}) => {
|
|
32
|
-
const iterableColumnValues =
|
|
33
|
-
field
|
|
34
|
-
})] : ['', ...(valueOptions || [])];
|
|
29
|
+
const iterableColumnValues = ['', ...((0, _filterPanelUtils.getValueOptions)(column) || [])];
|
|
35
30
|
return iterableColumnValues.map(option => {
|
|
36
31
|
const value = getOptionValue(option);
|
|
37
|
-
|
|
32
|
+
let label = getOptionLabel(option);
|
|
33
|
+
if (label === '') {
|
|
34
|
+
label = ' '; // To force the height of the empty option
|
|
35
|
+
}
|
|
38
36
|
return /*#__PURE__*/(0, _react.createElement)(OptionComponent, (0, _extends2.default)({}, baseSelectOptionProps, {
|
|
39
37
|
native: isSelectNative,
|
|
40
38
|
key: value,
|
|
@@ -57,19 +55,17 @@ function GridFilterInputSingleSelect(props) {
|
|
|
57
55
|
type,
|
|
58
56
|
apiRef,
|
|
59
57
|
focusElementRef,
|
|
60
|
-
getOptionLabel: getOptionLabelProp,
|
|
61
|
-
getOptionValue: getOptionValueProp,
|
|
62
58
|
placeholder,
|
|
63
59
|
tabIndex,
|
|
64
60
|
label: labelProp,
|
|
65
61
|
clearButton
|
|
66
62
|
} = props,
|
|
67
63
|
others = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
68
|
-
const
|
|
64
|
+
const filterValue = item.value ?? '';
|
|
69
65
|
const id = (0, _utils.unstable_useId)();
|
|
70
66
|
const labelId = (0, _utils.unstable_useId)();
|
|
71
67
|
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
72
|
-
const isSelectNative = rootProps.slotProps?.baseSelect?.native ??
|
|
68
|
+
const isSelectNative = rootProps.slotProps?.baseSelect?.native ?? false;
|
|
73
69
|
let resolvedColumn = null;
|
|
74
70
|
if (item.field) {
|
|
75
71
|
const column = apiRef.current.getColumn(item.field);
|
|
@@ -77,52 +73,27 @@ function GridFilterInputSingleSelect(props) {
|
|
|
77
73
|
resolvedColumn = column;
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
|
-
const getOptionValue =
|
|
81
|
-
const getOptionLabel =
|
|
76
|
+
const getOptionValue = resolvedColumn?.getOptionValue;
|
|
77
|
+
const getOptionLabel = resolvedColumn?.getOptionLabel;
|
|
82
78
|
const currentValueOptions = React.useMemo(() => {
|
|
83
|
-
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
return typeof resolvedColumn.valueOptions === 'function' ? resolvedColumn.valueOptions({
|
|
87
|
-
field: resolvedColumn.field
|
|
88
|
-
}) : resolvedColumn.valueOptions;
|
|
79
|
+
return (0, _filterPanelUtils.getValueOptions)(resolvedColumn);
|
|
89
80
|
}, [resolvedColumn]);
|
|
90
81
|
const onFilterChange = React.useCallback(event => {
|
|
91
82
|
let value = event.target.value;
|
|
92
83
|
|
|
93
84
|
// NativeSelect casts the value to a string.
|
|
94
85
|
value = (0, _filterPanelUtils.getValueFromValueOptions)(value, currentValueOptions, getOptionValue);
|
|
95
|
-
setFilterValueState(String(value));
|
|
96
86
|
applyValue((0, _extends2.default)({}, item, {
|
|
97
87
|
value
|
|
98
88
|
}));
|
|
99
89
|
}, [currentValueOptions, getOptionValue, applyValue, item]);
|
|
100
|
-
React.useEffect(() => {
|
|
101
|
-
let itemValue;
|
|
102
|
-
if (currentValueOptions !== undefined) {
|
|
103
|
-
// sanitize if valueOptions are provided
|
|
104
|
-
itemValue = (0, _filterPanelUtils.getValueFromValueOptions)(item.value, currentValueOptions, getOptionValue);
|
|
105
|
-
if (itemValue !== item.value) {
|
|
106
|
-
applyValue((0, _extends2.default)({}, item, {
|
|
107
|
-
value: itemValue
|
|
108
|
-
}));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
itemValue = item.value;
|
|
113
|
-
}
|
|
114
|
-
itemValue = itemValue ?? '';
|
|
115
|
-
setFilterValueState(String(itemValue));
|
|
116
|
-
}, [item, currentValueOptions, applyValue, getOptionValue]);
|
|
117
|
-
if (!(0, _filterPanelUtils.isSingleSelectColDef)(resolvedColumn)) {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
90
|
if (!(0, _filterPanelUtils.isSingleSelectColDef)(resolvedColumn)) {
|
|
121
91
|
return null;
|
|
122
92
|
}
|
|
123
93
|
const label = labelProp ?? apiRef.current.getLocaleText('filterPanelInputLabel');
|
|
124
94
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(SingleSelectOperatorContainer, {
|
|
125
95
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(rootProps.slots.baseFormControl, {
|
|
96
|
+
fullWidth: true,
|
|
126
97
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseInputLabel, (0, _extends2.default)({}, rootProps.slotProps?.baseInputLabel, {
|
|
127
98
|
id: labelId,
|
|
128
99
|
htmlFor: id,
|
|
@@ -133,7 +104,7 @@ function GridFilterInputSingleSelect(props) {
|
|
|
133
104
|
id: id,
|
|
134
105
|
label: label,
|
|
135
106
|
labelId: labelId,
|
|
136
|
-
value:
|
|
107
|
+
value: filterValue,
|
|
137
108
|
onChange: onFilterChange,
|
|
138
109
|
variant: "standard",
|
|
139
110
|
type: type || 'text',
|
|
@@ -167,18 +138,6 @@ process.env.NODE_ENV !== "production" ? GridFilterInputSingleSelect.propTypes =
|
|
|
167
138
|
applyValue: _propTypes.default.func.isRequired,
|
|
168
139
|
clearButton: _propTypes.default.node,
|
|
169
140
|
focusElementRef: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.func, _propTypes.default.object]),
|
|
170
|
-
/**
|
|
171
|
-
* Used to determine the label displayed for a given value option.
|
|
172
|
-
* @param {ValueOptions} value The current value option.
|
|
173
|
-
* @returns {string} The text to be displayed.
|
|
174
|
-
*/
|
|
175
|
-
getOptionLabel: _propTypes.default.func,
|
|
176
|
-
/**
|
|
177
|
-
* Used to determine the value used for a value option.
|
|
178
|
-
* @param {ValueOptions} value The current value option.
|
|
179
|
-
* @returns {string} The value to be used.
|
|
180
|
-
*/
|
|
181
|
-
getOptionValue: _propTypes.default.func,
|
|
182
141
|
/**
|
|
183
142
|
* It is `true` if the filter either has a value or an operator with no value
|
|
184
143
|
* required is selected (e.g. `isEmpty`)
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.getLabelFromValueOption = void 0;
|
|
7
7
|
exports.getValueFromValueOptions = getValueFromValueOptions;
|
|
8
|
+
exports.getValueOptions = getValueOptions;
|
|
8
9
|
exports.isSingleSelectColDef = isSingleSelectColDef;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
11
|
function isSingleSelectColDef(colDef) {
|
|
10
12
|
return colDef?.type === 'singleSelect';
|
|
11
13
|
}
|
|
14
|
+
function getValueOptions(column, additionalParams) {
|
|
15
|
+
if (!column) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return typeof column.valueOptions === 'function' ? column.valueOptions((0, _extends2.default)({
|
|
19
|
+
field: column.field
|
|
20
|
+
}, additionalParams)) : column.valueOptions;
|
|
21
|
+
}
|
|
12
22
|
function getValueFromValueOptions(value, valueOptions, getOptionValue) {
|
|
13
23
|
if (valueOptions === undefined) {
|
|
14
24
|
return undefined;
|
|
@@ -18,9 +28,4 @@ function getValueFromValueOptions(value, valueOptions, getOptionValue) {
|
|
|
18
28
|
return String(optionValue) === String(value);
|
|
19
29
|
});
|
|
20
30
|
return getOptionValue(result);
|
|
21
|
-
}
|
|
22
|
-
const getLabelFromValueOption = valueOption => {
|
|
23
|
-
const label = typeof valueOption === 'object' ? valueOption.label : valueOption;
|
|
24
|
-
return label != null ? String(label) : '';
|
|
25
|
-
};
|
|
26
|
-
exports.getLabelFromValueOption = getLabelFromValueOption;
|
|
31
|
+
}
|
|
@@ -22,6 +22,7 @@ var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
|
|
|
22
22
|
var _gridDetailPanelToggleField = require("../../../constants/gridDetailPanelToggleField");
|
|
23
23
|
var _gridClasses = require("../../../constants/gridClasses");
|
|
24
24
|
var _domUtils = require("../../../utils/domUtils");
|
|
25
|
+
var _utils = require("./utils");
|
|
25
26
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
26
27
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
27
28
|
const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
@@ -67,11 +68,10 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
67
68
|
});
|
|
68
69
|
const {
|
|
69
70
|
checkboxSelection,
|
|
70
|
-
disableMultipleRowSelection,
|
|
71
71
|
disableRowSelectionOnClick,
|
|
72
72
|
isRowSelectable: propIsRowSelectable
|
|
73
73
|
} = props;
|
|
74
|
-
const canHaveMultipleSelection =
|
|
74
|
+
const canHaveMultipleSelection = (0, _utils.isMultipleRowSelectionEnabled)(props);
|
|
75
75
|
const visibleRows = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef, props);
|
|
76
76
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
77
77
|
let endId = id;
|
|
@@ -101,7 +101,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
101
101
|
* API METHODS
|
|
102
102
|
*/
|
|
103
103
|
const setRowSelectionModel = React.useCallback(model => {
|
|
104
|
-
if (props.signature === _useGridApiEventHandler.GridSignature.DataGrid && !
|
|
104
|
+
if (props.signature === _useGridApiEventHandler.GridSignature.DataGrid && !canHaveMultipleSelection && Array.isArray(model) && model.length > 1) {
|
|
105
105
|
throw new Error(['MUI: `rowSelectionModel` can only contain 1 item in DataGrid.', 'You need to upgrade to DataGridPro or DataGridPremium component to unlock multiple selection.'].join('\n'));
|
|
106
106
|
}
|
|
107
107
|
const currentModel = (0, _gridRowSelectionSelector.gridRowSelectionStateSelector)(apiRef.current.state);
|
|
@@ -112,7 +112,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
112
112
|
}));
|
|
113
113
|
apiRef.current.forceUpdate();
|
|
114
114
|
}
|
|
115
|
-
}, [apiRef, logger, props.rowSelection, props.signature,
|
|
115
|
+
}, [apiRef, logger, props.rowSelection, props.signature, canHaveMultipleSelection]);
|
|
116
116
|
const isRowSelected = React.useCallback(id => (0, _gridRowSelectionSelector.gridRowSelectionStateSelector)(apiRef.current.state).includes(id), [apiRef]);
|
|
117
117
|
const isRowSelectable = React.useCallback(id => {
|
|
118
118
|
if (propIsRowSelectable && !propIsRowSelectable(apiRef.current.getRowParams(id))) {
|
|
@@ -263,24 +263,24 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
263
263
|
if (rowNode.type === 'pinnedRow') {
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
266
|
-
if (event.shiftKey &&
|
|
266
|
+
if (event.shiftKey && canHaveMultipleSelection) {
|
|
267
267
|
expandMouseRowRangeSelection(params.id);
|
|
268
268
|
} else {
|
|
269
269
|
handleSingleRowSelection(params.id, event);
|
|
270
270
|
}
|
|
271
|
-
}, [disableRowSelectionOnClick, canHaveMultipleSelection,
|
|
271
|
+
}, [disableRowSelectionOnClick, canHaveMultipleSelection, apiRef, expandMouseRowRangeSelection, handleSingleRowSelection]);
|
|
272
272
|
const preventSelectionOnShift = React.useCallback((params, event) => {
|
|
273
273
|
if (canHaveMultipleSelection && event.shiftKey) {
|
|
274
274
|
window.getSelection()?.removeAllRanges();
|
|
275
275
|
}
|
|
276
276
|
}, [canHaveMultipleSelection]);
|
|
277
277
|
const handleRowSelectionCheckboxChange = React.useCallback((params, event) => {
|
|
278
|
-
if (event.nativeEvent.shiftKey) {
|
|
278
|
+
if (canHaveMultipleSelection && event.nativeEvent.shiftKey) {
|
|
279
279
|
expandMouseRowRangeSelection(params.id);
|
|
280
280
|
} else {
|
|
281
|
-
apiRef.current.selectRow(params.id, params.value);
|
|
281
|
+
apiRef.current.selectRow(params.id, params.value, !canHaveMultipleSelection);
|
|
282
282
|
}
|
|
283
|
-
}, [apiRef, expandMouseRowRangeSelection]);
|
|
283
|
+
}, [apiRef, expandMouseRowRangeSelection, canHaveMultipleSelection]);
|
|
284
284
|
const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
|
|
285
285
|
const shouldLimitSelectionToCurrentPage = props.checkboxSelectionVisibleOnly && props.pagination;
|
|
286
286
|
const rowsToBeSelected = shouldLimitSelectionToCurrentPage ? (0, _pagination.gridPaginatedVisibleSortedGridRowIdsSelector)(apiRef) : (0, _gridFilterSelector.gridExpandedSortedRowIdsSelector)(apiRef);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isMultipleRowSelectionEnabled = isMultipleRowSelectionEnabled;
|
|
7
|
+
var _useGridApiEventHandler = require("../../utils/useGridApiEventHandler");
|
|
8
|
+
function isMultipleRowSelectionEnabled(props) {
|
|
9
|
+
if (props.signature === _useGridApiEventHandler.GridSignature.DataGrid) {
|
|
10
|
+
// DataGrid Community has multiple row selection enabled only if checkbox selection is enabled.
|
|
11
|
+
return props.checkboxSelection && props.disableMultipleRowSelection !== true;
|
|
12
|
+
}
|
|
13
|
+
return !props.disableMultipleRowSelection;
|
|
14
|
+
}
|
|
@@ -10,6 +10,7 @@ var _useGridRootProps = require("./useGridRootProps");
|
|
|
10
10
|
var _gridColumnGroupsSelector = require("../features/columnGrouping/gridColumnGroupsSelector");
|
|
11
11
|
var _gridRowsSelector = require("../features/rows/gridRowsSelector");
|
|
12
12
|
var _useGridPrivateApiContext = require("./useGridPrivateApiContext");
|
|
13
|
+
var _utils = require("../features/rowSelection/utils");
|
|
13
14
|
const useGridAriaAttributes = () => {
|
|
14
15
|
const apiRef = (0, _useGridPrivateApiContext.useGridPrivateApiContext)();
|
|
15
16
|
const rootProps = (0, _useGridRootProps.useGridRootProps)();
|
|
@@ -25,7 +26,7 @@ const useGridAriaAttributes = () => {
|
|
|
25
26
|
role,
|
|
26
27
|
'aria-colcount': visibleColumns.length,
|
|
27
28
|
'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + totalRowCount,
|
|
28
|
-
'aria-multiselectable':
|
|
29
|
+
'aria-multiselectable': (0, _utils.isMultipleRowSelectionEnabled)(rootProps)
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
exports.useGridAriaAttributes = useGridAriaAttributes;
|
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-data-grid",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.6",
|
|
4
4
|
"description": "The community edition of the data grid component (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@babel/runtime": "^7.23.5",
|
|
40
|
-
"@mui/system": "^5.
|
|
41
|
-
"@mui/utils": "^5.
|
|
40
|
+
"@mui/system": "^5.15.0",
|
|
41
|
+
"@mui/utils": "^5.15.0",
|
|
42
42
|
"clsx": "^2.0.0",
|
|
43
43
|
"prop-types": "^15.8.1",
|
|
44
44
|
"reselect": "^4.1.8"
|