@rescui/select 0.11.7 → 0.11.9-RUI-226-Update-card-cn-6e43cc89.60
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/lib/_virtual/check.js +90 -21
- package/lib/_virtual/close.js +90 -21
- package/lib/_virtual/down.js +90 -21
- package/lib/_virtual/index.css.js +12 -7
- package/lib/_virtual/loading.js +106 -29
- package/lib/_virtual/warning.js +90 -21
- package/lib/common-prop-types.js +6 -6
- package/lib/index.css +287 -303
- package/lib/key-codes.js +7 -7
- package/lib/parts/common-select.p.module.css.js +12 -12
- package/lib/parts/foldable.js +158 -220
- package/lib/parts/form-trigger-wrapper.js +22 -17
- package/lib/parts/form-trigger.p.module.css.js +10 -10
- package/lib/parts/multiselect.js +132 -202
- package/lib/parts/native-select.js +85 -117
- package/lib/parts/native-select.p.module.css.js +6 -6
- package/lib/parts/throttle.js +9 -12
- package/lib/parts/trigger.js +94 -122
- package/lib/parts/trigger.p.module.css.js +27 -27
- package/lib/parts/use-observable-force-rerender.js +5 -12
- package/lib/public-api.p.css +181 -112
- package/lib/public-api.pcss +181 -112
- package/lib/select.js +118 -195
- package/lib/utils.js +44 -90
- package/package.json +12 -12
package/lib/parts/multiselect.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
4
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
5
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
6
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
7
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
8
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
9
|
-
var _excluded = ["options", "size", "mode", "theme", "className", "value", "onChange", "placeholder", "isSingleLine", "isClearable", "isLoading", "isDisabled", "noOptionsMessage", "placement", "boldLabel"];
|
|
10
|
-
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
|
|
15
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
16
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
17
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
18
1
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
19
|
-
import "core-js/modules/es.object.to-string.js";
|
|
20
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
21
|
-
import "core-js/modules/es.function.name.js";
|
|
22
2
|
import React, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
|
23
3
|
import PropTypes from 'prop-types';
|
|
24
4
|
import cn from 'classnames';
|
|
@@ -35,37 +15,36 @@ import FormTriggerWrapper from './form-trigger-wrapper.js';
|
|
|
35
15
|
import { useObservableForceRerender } from './use-observable-force-rerender.js';
|
|
36
16
|
import styles from './common-select.p.module.css.js'; // eslint-disable-next-line complexity
|
|
37
17
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
18
|
+
const Option = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
selected,
|
|
21
|
+
cursorIndex,
|
|
22
|
+
item,
|
|
23
|
+
isSingleLine,
|
|
24
|
+
isLastItem,
|
|
25
|
+
highlightedItemRef,
|
|
26
|
+
handleHighlightIndex,
|
|
27
|
+
handleSelectIndex
|
|
28
|
+
} = _ref;
|
|
47
29
|
|
|
48
30
|
if (item.type === OptionGroupTypes.OPTION) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
className: styles.checkIcon
|
|
31
|
+
const {
|
|
32
|
+
index,
|
|
33
|
+
label
|
|
34
|
+
} = item;
|
|
35
|
+
const value = getOptionValue(item);
|
|
36
|
+
const isItemSelected = Boolean(selected && selected.length && selected.some(s => value === getOptionValue(s)));
|
|
37
|
+
const isHighlighted = isIndexMatchCursor(cursorIndex, index);
|
|
38
|
+
const icon = isSingleLine && isItemSelected ? /*#__PURE__*/React.createElement(CheckIcon, {
|
|
39
|
+
className: styles.checkIcon,
|
|
40
|
+
"data-render-all-sizes": true
|
|
58
41
|
}) : null;
|
|
59
42
|
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
60
43
|
selected: isItemSelected,
|
|
61
44
|
highlighted: isHighlighted,
|
|
62
45
|
ref: isHighlighted ? highlightedItemRef : null,
|
|
63
|
-
onMouseMove:
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
onClick: function onClick() {
|
|
67
|
-
return handleSelectIndex(index);
|
|
68
|
-
},
|
|
46
|
+
onMouseMove: () => handleHighlightIndex(index),
|
|
47
|
+
onClick: () => handleSelectIndex(index),
|
|
69
48
|
className: cn(isLastItem && styles.lastOption),
|
|
70
49
|
icon: icon
|
|
71
50
|
}, label);
|
|
@@ -78,59 +57,57 @@ var Option = function Option(_ref) {
|
|
|
78
57
|
}
|
|
79
58
|
|
|
80
59
|
if (item.type === OptionGroupTypes.HEADER) {
|
|
81
|
-
|
|
60
|
+
const {
|
|
61
|
+
label
|
|
62
|
+
} = item;
|
|
82
63
|
return /*#__PURE__*/React.createElement(GroupHeader, {
|
|
83
|
-
text:
|
|
64
|
+
text: label
|
|
84
65
|
});
|
|
85
66
|
}
|
|
86
67
|
|
|
87
68
|
return null;
|
|
88
69
|
};
|
|
89
70
|
|
|
90
|
-
|
|
71
|
+
const getOptionKey = (item, i) => {
|
|
91
72
|
if (item.type === OptionGroupTypes.OPTION) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var value = getOptionValue(item);
|
|
95
|
-
return _concatInstanceProperty(_context = "".concat(value, "_")).call(_context, item.index[0]);
|
|
73
|
+
const value = getOptionValue(item);
|
|
74
|
+
return `${value}_${item.index[0]}`;
|
|
96
75
|
} else if (item.type === OptionGroupTypes.DIVIDER) {
|
|
97
|
-
return
|
|
76
|
+
return `divider${i}`;
|
|
98
77
|
} else if (item.type === OptionGroupTypes.HEADER) {
|
|
99
|
-
return
|
|
78
|
+
return `header${i}`;
|
|
100
79
|
}
|
|
101
80
|
|
|
102
81
|
return null;
|
|
103
82
|
};
|
|
104
83
|
|
|
105
84
|
function filterSelected(groups, selected) {
|
|
106
|
-
|
|
85
|
+
const selectedValues = {};
|
|
107
86
|
|
|
108
87
|
if (selected) {
|
|
109
|
-
selected.forEach(
|
|
88
|
+
selected.forEach(s => {
|
|
110
89
|
selectedValues[getOptionValue(s)] = true;
|
|
111
90
|
});
|
|
112
91
|
}
|
|
113
92
|
|
|
114
|
-
return
|
|
115
|
-
|
|
93
|
+
return groups.map(g => {
|
|
94
|
+
let newOptions = [];
|
|
116
95
|
|
|
117
96
|
if (g.options) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
newOptions = _filterInstanceProperty(_context2 = g.options).call(_context2, function (opt) {
|
|
121
|
-
return !selectedValues[getOptionValue(opt)];
|
|
122
|
-
});
|
|
97
|
+
newOptions = g.options.filter(opt => !selectedValues[getOptionValue(opt)]);
|
|
123
98
|
}
|
|
124
99
|
|
|
125
|
-
return
|
|
100
|
+
return { ...g,
|
|
126
101
|
options: newOptions
|
|
127
|
-
}
|
|
102
|
+
};
|
|
128
103
|
});
|
|
129
104
|
}
|
|
130
105
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
106
|
+
const NativeSelectedOptions = _ref2 => {
|
|
107
|
+
let {
|
|
108
|
+
name,
|
|
109
|
+
selected
|
|
110
|
+
} = _ref2;
|
|
134
111
|
|
|
135
112
|
if (!selected || !Array.isArray(selected) || !selected.length) {
|
|
136
113
|
return /*#__PURE__*/React.createElement("input", {
|
|
@@ -140,8 +117,10 @@ var NativeSelectedOptions = function NativeSelectedOptions(_ref2) {
|
|
|
140
117
|
});
|
|
141
118
|
}
|
|
142
119
|
|
|
143
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
144
|
-
|
|
120
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, selected.map(_ref3 => {
|
|
121
|
+
let {
|
|
122
|
+
value
|
|
123
|
+
} = _ref3;
|
|
145
124
|
return /*#__PURE__*/React.createElement("input", {
|
|
146
125
|
key: value,
|
|
147
126
|
type: "hidden",
|
|
@@ -151,101 +130,61 @@ var NativeSelectedOptions = function NativeSelectedOptions(_ref2) {
|
|
|
151
130
|
}));
|
|
152
131
|
};
|
|
153
132
|
|
|
154
|
-
|
|
133
|
+
const SIZE_STYLES = {
|
|
155
134
|
s: styles.sizeS,
|
|
156
135
|
m: styles.sizeM,
|
|
157
136
|
l: styles.sizeL
|
|
158
137
|
};
|
|
159
|
-
|
|
138
|
+
const MENU_SIZE_STYLES = {
|
|
160
139
|
s: styles.menuSizeS,
|
|
161
140
|
m: styles.menuSizeM,
|
|
162
141
|
l: styles.menuSizeL
|
|
163
142
|
}; // eslint-disable-next-line complexity
|
|
164
143
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
restProps = _objectWithoutProperties(_ref4, _excluded);
|
|
193
|
-
|
|
194
|
-
var _useState = useState(null),
|
|
195
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
196
|
-
triggerFormWrapperRef = _useState2[0],
|
|
197
|
-
setTriggerFormWrapperRef = _useState2[1];
|
|
198
|
-
|
|
199
|
-
var dropdownRef = useRef(null);
|
|
200
|
-
var highlightedItemRef = useRef();
|
|
201
|
-
var theme = useThemeWithUndefined(themeFromProps);
|
|
202
|
-
|
|
203
|
-
var _useState3 = useState(false),
|
|
204
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
205
|
-
isKeyboardNavigating = _useState4[0],
|
|
206
|
-
setIsKeyboardNavigating = _useState4[1];
|
|
207
|
-
|
|
208
|
-
var skipScrollingRef = useRef(false);
|
|
209
|
-
var groups = useStrongMemo(function () {
|
|
210
|
-
return convertToOptionGroupsIfNeeded(options);
|
|
211
|
-
}, [options]);
|
|
212
|
-
var filteredGroups = useStrongMemo(function () {
|
|
144
|
+
const Multiselect = _ref4 => {
|
|
145
|
+
let {
|
|
146
|
+
options,
|
|
147
|
+
size = 'm',
|
|
148
|
+
mode = 'classic',
|
|
149
|
+
theme: themeFromProps,
|
|
150
|
+
className = null,
|
|
151
|
+
value = undefined,
|
|
152
|
+
onChange,
|
|
153
|
+
placeholder,
|
|
154
|
+
isSingleLine = false,
|
|
155
|
+
isClearable = false,
|
|
156
|
+
isLoading = false,
|
|
157
|
+
isDisabled = false,
|
|
158
|
+
noOptionsMessage,
|
|
159
|
+
placement = 'bottom',
|
|
160
|
+
boldLabel,
|
|
161
|
+
...restProps
|
|
162
|
+
} = _ref4;
|
|
163
|
+
const [triggerFormWrapperRef, setTriggerFormWrapperRef] = useState(null);
|
|
164
|
+
const dropdownRef = useRef(null);
|
|
165
|
+
const highlightedItemRef = useRef();
|
|
166
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
167
|
+
const [isKeyboardNavigating, setIsKeyboardNavigating] = useState(false);
|
|
168
|
+
const skipScrollingRef = useRef(false);
|
|
169
|
+
const groups = useStrongMemo(() => convertToOptionGroupsIfNeeded(options), [options]);
|
|
170
|
+
const filteredGroups = useStrongMemo(() => {
|
|
213
171
|
if (isSingleLine) {
|
|
214
172
|
return groups;
|
|
215
173
|
}
|
|
216
174
|
|
|
217
175
|
return filterSelected(groups, value);
|
|
218
176
|
}, [isSingleLine, value, groups]);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
menuIsOpen = _useState6[0],
|
|
223
|
-
setMenuIsOpen = _useState6[1];
|
|
224
|
-
|
|
225
|
-
var _useState7 = useState(function () {
|
|
226
|
-
return getDefaultCursorIndex(filteredGroups);
|
|
227
|
-
}),
|
|
228
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
229
|
-
cursorIndex = _useState8[0],
|
|
230
|
-
setCursorIndex = _useState8[1];
|
|
231
|
-
|
|
232
|
-
useEffect(function () {
|
|
177
|
+
const [menuIsOpen, setMenuIsOpen] = useState(false);
|
|
178
|
+
const [cursorIndex, setCursorIndex] = useState(() => getDefaultCursorIndex(filteredGroups));
|
|
179
|
+
useEffect(() => {
|
|
233
180
|
setCursorIndex(getDefaultCursorIndex(filteredGroups));
|
|
234
181
|
}, [filteredGroups, value]);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
var selectedOption = filteredGroups[index[0]].options[index[1]];
|
|
242
|
-
var selectedOptionValue = getOptionValue(selectedOption);
|
|
243
|
-
var optionAdded = !value.some(function (option) {
|
|
244
|
-
return getOptionValue(option) === selectedOptionValue;
|
|
245
|
-
});
|
|
246
|
-
var newSelected = optionAdded ? _concatInstanceProperty(_context3 = []).call(_context3, _toConsumableArray(value), [selectedOption]) : _filterInstanceProperty(value).call(value, function (option) {
|
|
247
|
-
return getOptionValue(option) !== selectedOptionValue;
|
|
248
|
-
});
|
|
182
|
+
const isEmptyMenu = useMemo(() => isGroupsEmpty(filteredGroups), [filteredGroups]);
|
|
183
|
+
const handleSelectIndex = useCallback(index => {
|
|
184
|
+
const selectedOption = filteredGroups[index[0]].options[index[1]];
|
|
185
|
+
const selectedOptionValue = getOptionValue(selectedOption);
|
|
186
|
+
const optionAdded = !value.some(option => getOptionValue(option) === selectedOptionValue);
|
|
187
|
+
const newSelected = optionAdded ? [...value, selectedOption] : value.filter(option => getOptionValue(option) !== selectedOptionValue);
|
|
249
188
|
|
|
250
189
|
if (onChange) {
|
|
251
190
|
onChange(newSelected);
|
|
@@ -254,32 +193,28 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
254
193
|
setMenuIsOpen(false);
|
|
255
194
|
setIsKeyboardNavigating(false);
|
|
256
195
|
}, [onChange, filteredGroups, value]);
|
|
257
|
-
useEffect(
|
|
196
|
+
useEffect(() => {
|
|
258
197
|
if (dropdownRef.current) {
|
|
259
198
|
dropdownRef.current.scheduleUpdate();
|
|
260
199
|
}
|
|
261
200
|
}, [value]);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}, []);
|
|
265
|
-
useEffect(function () {
|
|
201
|
+
const handleMouseMove = useCallback(() => setIsKeyboardNavigating(false), []);
|
|
202
|
+
useEffect(() => {
|
|
266
203
|
if (isKeyboardNavigating) {
|
|
267
204
|
document.addEventListener('mousemove', handleMouseMove);
|
|
268
205
|
}
|
|
269
206
|
|
|
270
|
-
return
|
|
271
|
-
return document.removeEventListener('mousemove', handleMouseMove);
|
|
272
|
-
};
|
|
207
|
+
return () => document.removeEventListener('mousemove', handleMouseMove);
|
|
273
208
|
}, [handleMouseMove, isKeyboardNavigating]);
|
|
274
|
-
useEffect(
|
|
209
|
+
useEffect(() => {
|
|
275
210
|
if (isKeyboardNavigating && highlightedItemRef.current) {
|
|
276
211
|
if (skipScrollingRef.current) {
|
|
277
212
|
skipScrollingRef.current = false;
|
|
278
213
|
} else {
|
|
279
|
-
|
|
214
|
+
let elementToScrollTo = highlightedItemRef.current;
|
|
280
215
|
|
|
281
216
|
if (cursorIndex[0] === 0 && cursorIndex[1] === 0) {
|
|
282
|
-
|
|
217
|
+
const groupHeader = highlightedItemRef.current.previousSibling;
|
|
283
218
|
|
|
284
219
|
if (groupHeader) {
|
|
285
220
|
elementToScrollTo = groupHeader;
|
|
@@ -295,14 +230,14 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
295
230
|
}
|
|
296
231
|
}
|
|
297
232
|
}, [highlightedItemRef, cursorIndex, isKeyboardNavigating]);
|
|
298
|
-
|
|
233
|
+
const handleClose = useCallback(() => {
|
|
299
234
|
setMenuIsOpen(false);
|
|
300
235
|
setIsKeyboardNavigating(false);
|
|
301
236
|
}, []);
|
|
302
|
-
|
|
303
|
-
|
|
237
|
+
const handleKeyNavigation = useCallback( // eslint-disable-next-line complexity
|
|
238
|
+
e => {
|
|
304
239
|
if (e.key === ARROW_DOWN || e.key === ARROW_UP) {
|
|
305
|
-
|
|
240
|
+
const isDownDirection = e.key === ARROW_DOWN;
|
|
306
241
|
setCursorIndex(getMovedCursorIndex(filteredGroups, cursorIndex, isDownDirection));
|
|
307
242
|
setIsKeyboardNavigating(true);
|
|
308
243
|
e.preventDefault();
|
|
@@ -322,16 +257,14 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
322
257
|
handleClose();
|
|
323
258
|
}
|
|
324
259
|
}, [filteredGroups, cursorIndex, handleClose, handleSelectIndex]);
|
|
325
|
-
|
|
260
|
+
const handleClick = useCallback(() => {
|
|
326
261
|
if (isDisabled) {
|
|
327
262
|
return;
|
|
328
263
|
}
|
|
329
264
|
|
|
330
|
-
setMenuIsOpen(
|
|
331
|
-
return !currentMenuIsOpen;
|
|
332
|
-
});
|
|
265
|
+
setMenuIsOpen(currentMenuIsOpen => !currentMenuIsOpen);
|
|
333
266
|
}, [isDisabled]);
|
|
334
|
-
|
|
267
|
+
const handleClearClick = useCallback(() => {
|
|
335
268
|
setCursorIndex(getDefaultCursorIndex(groups));
|
|
336
269
|
setMenuIsOpen(false);
|
|
337
270
|
|
|
@@ -340,7 +273,7 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
340
273
|
}
|
|
341
274
|
}, [groups, onChange]); // eslint-disable-next-line complexity
|
|
342
275
|
|
|
343
|
-
|
|
276
|
+
const handleTriggerKeyDown = useCallback(e => {
|
|
344
277
|
if (e.key === ESCAPE) {
|
|
345
278
|
handleClose();
|
|
346
279
|
e.preventDefault();
|
|
@@ -353,9 +286,9 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
353
286
|
if (menuIsOpen) {
|
|
354
287
|
handleKeyNavigation(e);
|
|
355
288
|
} else {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
289
|
+
const target = e.target;
|
|
290
|
+
const trigger = target.closest('[data-target="trigger"]');
|
|
291
|
+
const isTriggerTarget = trigger === target;
|
|
359
292
|
|
|
360
293
|
if (shouldOpenSelect(e.key, isTriggerTarget)) {
|
|
361
294
|
setMenuIsOpen(true);
|
|
@@ -372,28 +305,25 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
372
305
|
}
|
|
373
306
|
}
|
|
374
307
|
}, [handleClearClick, handleClose, handleKeyNavigation, isClearable, isDisabled, menuIsOpen]);
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
var newSelected = _filterInstanceProperty(value).call(value, function (option) {
|
|
379
|
-
return getOptionValue(option) !== unselectedOptionValue;
|
|
380
|
-
});
|
|
308
|
+
const handleUnselectClick = useCallback(unselectedOption => {
|
|
309
|
+
const unselectedOptionValue = getOptionValue(unselectedOption);
|
|
310
|
+
const newSelected = value.filter(option => getOptionValue(option) !== unselectedOptionValue);
|
|
381
311
|
|
|
382
312
|
if (onChange) {
|
|
383
313
|
onChange(newSelected);
|
|
384
314
|
}
|
|
385
315
|
}, [onChange, value]);
|
|
386
|
-
|
|
316
|
+
const handleHighlightIndex = useCallback(index => {
|
|
387
317
|
if (!isIndexMatchCursor(cursorIndex, index)) {
|
|
388
318
|
setCursorIndex(index);
|
|
389
319
|
}
|
|
390
320
|
}, [cursorIndex]); // We use invisible and "untouchable" dummy element to observe `size` changes from css to trigger force rerenders
|
|
391
321
|
|
|
392
|
-
|
|
393
|
-
|
|
322
|
+
const observableRef = useObservableForceRerender();
|
|
323
|
+
let sizeFromCss = null;
|
|
394
324
|
|
|
395
325
|
if (triggerFormWrapperRef && menuIsOpen) {
|
|
396
|
-
var
|
|
326
|
+
var _context;
|
|
397
327
|
|
|
398
328
|
// In theory this part of the code might cause issues with SSR.
|
|
399
329
|
// But in this specific context, because of checking ref "triggerFormWrapperRef",
|
|
@@ -402,14 +332,14 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
402
332
|
// Also, there will be no layout shifts on the following renders because
|
|
403
333
|
// it's a dropdown-content and in most cases it opens only on-demand.
|
|
404
334
|
// In additional, we use "observable" el to watch size changes between rerenders (@media query case).
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
sizeFromCss = _includesInstanceProperty(
|
|
335
|
+
const triggerFormWrapperStyles = getComputedStyle(triggerFormWrapperRef);
|
|
336
|
+
const rawSizeFromCss = triggerFormWrapperStyles.getPropertyValue('--_rs-select-size');
|
|
337
|
+
sizeFromCss = _includesInstanceProperty(_context = ['s', 'm', 'l']).call(_context, rawSizeFromCss) ? rawSizeFromCss : null;
|
|
408
338
|
}
|
|
409
339
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
340
|
+
const actualSize = sizeFromCss || size;
|
|
341
|
+
const maxHeight = calculateMaxHeight(actualSize);
|
|
342
|
+
const withGroupsLabel = !withoutGroupsLabel(filteredGroups);
|
|
413
343
|
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
414
344
|
theme: theme,
|
|
415
345
|
onRequestClose: handleClose,
|
|
@@ -422,8 +352,10 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
422
352
|
maxHeight: maxHeight,
|
|
423
353
|
leastMaxHeight: maxHeight,
|
|
424
354
|
disableFocusLock: true,
|
|
425
|
-
trigger:
|
|
426
|
-
|
|
355
|
+
trigger: _ref5 => {
|
|
356
|
+
let {
|
|
357
|
+
ref
|
|
358
|
+
} = _ref5;
|
|
427
359
|
return /*#__PURE__*/React.createElement(FormTriggerWrapper, {
|
|
428
360
|
ref: setTriggerFormWrapperRef,
|
|
429
361
|
className: cn(className, SIZE_STYLES[size]),
|
|
@@ -468,19 +400,17 @@ var Multiselect = function Multiselect(_ref4) {
|
|
|
468
400
|
disableCursor: isKeyboardNavigating,
|
|
469
401
|
iconPlacement: 'right',
|
|
470
402
|
enableKeyboardNavigation: false
|
|
471
|
-
}, !isEmptyMenu ?
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
});
|
|
483
|
-
}) : /*#__PURE__*/React.createElement(MenuItem, {
|
|
403
|
+
}, !isEmptyMenu ? getPlainOptionsFromGroups(filteredGroups).map((item, i, collection) => /*#__PURE__*/React.createElement(Option, {
|
|
404
|
+
key: getOptionKey(item, i),
|
|
405
|
+
selected: value,
|
|
406
|
+
cursorIndex: cursorIndex,
|
|
407
|
+
item: item,
|
|
408
|
+
isSingleLine: isSingleLine,
|
|
409
|
+
isLastItem: i === collection.length - 1,
|
|
410
|
+
highlightedItemRef: highlightedItemRef,
|
|
411
|
+
handleSelectIndex: handleSelectIndex,
|
|
412
|
+
handleHighlightIndex: handleHighlightIndex
|
|
413
|
+
})) : /*#__PURE__*/React.createElement(MenuItem, {
|
|
484
414
|
disabled: true
|
|
485
415
|
}, getEmptyMessage(isLoading, false, noOptionsMessage))));
|
|
486
416
|
};
|