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