@rescui/select 0.11.7 → 0.11.9
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
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"themeLight": "
|
|
3
|
-
"themeDark": "
|
|
4
|
-
"sizeS": "
|
|
5
|
-
"sizeM": "
|
|
6
|
-
"sizeL": "
|
|
7
|
-
"classic": "
|
|
8
|
-
"rock": "
|
|
9
|
-
"main": "
|
|
10
|
-
"open": "
|
|
11
|
-
"focused": "
|
|
12
|
-
"searchFocused": "
|
|
13
|
-
"error": "
|
|
14
|
-
"searchKeyFocused": "
|
|
15
|
-
"enabled": "
|
|
16
|
-
"disabled": "
|
|
17
|
-
"isMulti": "
|
|
18
|
-
"iconsWrapper": "
|
|
19
|
-
"labelWrapper": "
|
|
20
|
-
"label": "
|
|
21
|
-
"labelNotSelected": "
|
|
22
|
-
"searchInput": "
|
|
23
|
-
"multi": "
|
|
24
|
-
"tagsContainer": "
|
|
25
|
-
"tag": "
|
|
26
|
-
"toggle": "
|
|
27
|
-
"icon": "
|
|
28
|
-
"clearIcon": "
|
|
2
|
+
"themeLight": "_themeLight_dm5qw9_27",
|
|
3
|
+
"themeDark": "_themeDark_dm5qw9_30",
|
|
4
|
+
"sizeS": "_sizeS_dm5qw9_34",
|
|
5
|
+
"sizeM": "_sizeM_dm5qw9_37",
|
|
6
|
+
"sizeL": "_sizeL_dm5qw9_40",
|
|
7
|
+
"classic": "_classic_dm5qw9_44",
|
|
8
|
+
"rock": "_rock_dm5qw9_47",
|
|
9
|
+
"main": "_main_dm5qw9_51",
|
|
10
|
+
"open": "_open_dm5qw9_73",
|
|
11
|
+
"focused": "_focused_dm5qw9_77",
|
|
12
|
+
"searchFocused": "_searchFocused_dm5qw9_78",
|
|
13
|
+
"error": "_error_dm5qw9_80",
|
|
14
|
+
"searchKeyFocused": "_searchKeyFocused_dm5qw9_85",
|
|
15
|
+
"enabled": "_enabled_dm5qw9_89",
|
|
16
|
+
"disabled": "_disabled_dm5qw9_95",
|
|
17
|
+
"isMulti": "_isMulti_dm5qw9_125",
|
|
18
|
+
"iconsWrapper": "_iconsWrapper_dm5qw9_143",
|
|
19
|
+
"labelWrapper": "_labelWrapper_dm5qw9_168",
|
|
20
|
+
"label": "_label_dm5qw9_168",
|
|
21
|
+
"labelNotSelected": "_labelNotSelected_dm5qw9_218",
|
|
22
|
+
"searchInput": "_searchInput_dm5qw9_231",
|
|
23
|
+
"multi": "_multi_dm5qw9_271",
|
|
24
|
+
"tagsContainer": "_tagsContainer_dm5qw9_291",
|
|
25
|
+
"tag": "_tag_dm5qw9_291",
|
|
26
|
+
"toggle": "_toggle_dm5qw9_313",
|
|
27
|
+
"icon": "_icon_dm5qw9_143",
|
|
28
|
+
"clearIcon": "_clearIcon_dm5qw9_380"
|
|
29
29
|
};
|
|
30
30
|
export { styles as default };
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
2
1
|
import { useRef, useState } from 'react';
|
|
3
2
|
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
10
|
-
setDummyState = _useState2[1];
|
|
11
|
-
|
|
12
|
-
useResizeObserver(observableRef, function () {
|
|
4
|
+
const useObservableForceRerender = () => {
|
|
5
|
+
const observableRef = useRef(null);
|
|
6
|
+
const [, setDummyState] = useState(false);
|
|
7
|
+
useResizeObserver(observableRef, () => {
|
|
13
8
|
//force rerender
|
|
14
|
-
setDummyState(
|
|
15
|
-
return !s;
|
|
16
|
-
});
|
|
9
|
+
setDummyState(s => !s);
|
|
17
10
|
}, {
|
|
18
11
|
ignoreFirstCall: true
|
|
19
12
|
});
|
package/lib/select.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
|
-
import "core-js/modules/es.object.to-string.js";
|
|
2
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
4
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
5
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
6
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
7
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
8
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
9
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
10
|
-
var _excluded = ["options", "size", "mode", "theme", "className", "value", "onChange", "placeholder", "isClearable", "isLoading", "isDisabled", "isSearchable", "noOptionsMessage", "placement", "boldLabel"];
|
|
11
|
-
|
|
12
|
-
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; }
|
|
13
|
-
|
|
14
|
-
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; }
|
|
15
|
-
|
|
16
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
17
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
18
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
19
1
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
20
|
-
import "core-js/modules/es.array.join.js";
|
|
21
|
-
import "core-js/modules/es.regexp.constructor.js";
|
|
22
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
23
|
-
import "core-js/modules/es.regexp.to-string.js";
|
|
24
|
-
import "core-js/modules/es.function.name.js";
|
|
25
2
|
import React, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
|
26
3
|
import PropTypes from 'prop-types';
|
|
27
4
|
import cn from 'classnames';
|
|
@@ -37,35 +14,33 @@ import { useStrongMemo, getDefaultCursorIndex, isGroupsEmpty, getMovedCursorInde
|
|
|
37
14
|
import { ARROW_DOWN, ARROW_UP, ENTER, SPACE, TAB, ESCAPE, BACKSPACE } from './key-codes.js';
|
|
38
15
|
import styles from './parts/common-select.p.module.css.js'; // eslint-disable-next-line complexity
|
|
39
16
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
17
|
+
const Option = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
selected,
|
|
20
|
+
cursorIndex,
|
|
21
|
+
item,
|
|
22
|
+
isLastItem,
|
|
23
|
+
highlightedItemRef,
|
|
24
|
+
handleSelectIndex,
|
|
25
|
+
handleHighlightIndex
|
|
26
|
+
} = _ref;
|
|
48
27
|
|
|
49
28
|
if (item.type === OptionGroupTypes.OPTION) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
29
|
+
const {
|
|
30
|
+
index,
|
|
31
|
+
label
|
|
32
|
+
} = item;
|
|
33
|
+
const value = getOptionValue(item);
|
|
34
|
+
const isSelected = selected && value === getOptionValue(selected);
|
|
35
|
+
const isHighlighted = isIndexMatchCursor(cursorIndex, index);
|
|
57
36
|
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
58
37
|
selected: isSelected,
|
|
59
38
|
highlighted: isHighlighted,
|
|
60
39
|
ref: isHighlighted ? highlightedItemRef : null,
|
|
61
|
-
onMouseMove:
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
onClick: function onClick() {
|
|
65
|
-
return handleSelectIndex(index);
|
|
66
|
-
},
|
|
40
|
+
onMouseMove: () => handleHighlightIndex(index),
|
|
41
|
+
onClick: () => handleSelectIndex(index),
|
|
67
42
|
className: cn(isLastItem && styles.lastOption),
|
|
68
|
-
"data-test":
|
|
43
|
+
"data-test": ['select-menu-item', isHighlighted && 'select-menu-item-highlighted', isSelected && 'select-menu-item-selected'].filter(Boolean).join(' ')
|
|
69
44
|
}, label);
|
|
70
45
|
}
|
|
71
46
|
|
|
@@ -76,140 +51,96 @@ var Option = function Option(_ref) {
|
|
|
76
51
|
}
|
|
77
52
|
|
|
78
53
|
if (item.type === OptionGroupTypes.HEADER) {
|
|
79
|
-
|
|
54
|
+
const {
|
|
55
|
+
label
|
|
56
|
+
} = item;
|
|
80
57
|
return /*#__PURE__*/React.createElement(GroupHeader, {
|
|
81
|
-
text:
|
|
58
|
+
text: label
|
|
82
59
|
});
|
|
83
60
|
}
|
|
84
61
|
|
|
85
62
|
return null;
|
|
86
63
|
};
|
|
87
64
|
|
|
88
|
-
|
|
65
|
+
const getOptionKey = (item, i) => {
|
|
89
66
|
if (item.type === OptionGroupTypes.OPTION) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var value = getOptionValue(item);
|
|
93
|
-
return _concatInstanceProperty(_context2 = "".concat(value, "_")).call(_context2, item.index[0]);
|
|
67
|
+
const value = getOptionValue(item);
|
|
68
|
+
return `${value}_${item.index[0]}`;
|
|
94
69
|
} else if (item.type === OptionGroupTypes.DIVIDER) {
|
|
95
|
-
return
|
|
70
|
+
return `divider${i}`;
|
|
96
71
|
} else if (item.type === OptionGroupTypes.HEADER) {
|
|
97
|
-
return
|
|
72
|
+
return `header${i}`;
|
|
98
73
|
}
|
|
99
74
|
|
|
100
75
|
return null;
|
|
101
76
|
};
|
|
102
77
|
|
|
103
|
-
|
|
78
|
+
const SIZE_STYLES = {
|
|
104
79
|
s: styles.sizeS,
|
|
105
80
|
m: styles.sizeM,
|
|
106
81
|
l: styles.sizeL
|
|
107
82
|
};
|
|
108
|
-
|
|
83
|
+
const MENU_SIZE_STYLES = {
|
|
109
84
|
s: styles.menuSizeS,
|
|
110
85
|
m: styles.menuSizeM,
|
|
111
86
|
l: styles.menuSizeL
|
|
112
87
|
}; // eslint-disable-next-line complexity
|
|
113
88
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var _useState = useState(null),
|
|
144
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
145
|
-
triggerFormWrapperRef = _useState2[0],
|
|
146
|
-
setTriggerFormWrapperRef = _useState2[1];
|
|
147
|
-
|
|
148
|
-
var theme = useThemeWithUndefined(themeFromProps);
|
|
149
|
-
var dropdownRef = useRef(null);
|
|
150
|
-
var highlightedItemRef = /*#__PURE__*/React.createRef();
|
|
151
|
-
|
|
152
|
-
var _useState3 = useState(false),
|
|
153
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
154
|
-
isKeyboardNavigating = _useState4[0],
|
|
155
|
-
setIsKeyboardNavigating = _useState4[1];
|
|
156
|
-
|
|
157
|
-
var skipScrollingRef = useRef(false);
|
|
158
|
-
|
|
159
|
-
var _useState5 = useState(''),
|
|
160
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
161
|
-
searchString = _useState6[0],
|
|
162
|
-
setSearchString = _useState6[1];
|
|
163
|
-
|
|
164
|
-
var groups = useStrongMemo(function () {
|
|
165
|
-
return convertToOptionGroupsIfNeeded(options);
|
|
166
|
-
}, [options]);
|
|
167
|
-
var filteredGroups = useStrongMemo(function () {
|
|
89
|
+
const Select = _ref2 => {
|
|
90
|
+
let {
|
|
91
|
+
options,
|
|
92
|
+
size = 'm',
|
|
93
|
+
mode = 'classic',
|
|
94
|
+
theme: themeFromProps,
|
|
95
|
+
className = null,
|
|
96
|
+
value = undefined,
|
|
97
|
+
onChange,
|
|
98
|
+
placeholder,
|
|
99
|
+
isClearable = false,
|
|
100
|
+
isLoading = false,
|
|
101
|
+
isDisabled = false,
|
|
102
|
+
isSearchable = false,
|
|
103
|
+
noOptionsMessage,
|
|
104
|
+
placement = 'bottom',
|
|
105
|
+
boldLabel,
|
|
106
|
+
...restProps
|
|
107
|
+
} = _ref2;
|
|
108
|
+
const [triggerFormWrapperRef, setTriggerFormWrapperRef] = useState(null);
|
|
109
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
110
|
+
const dropdownRef = useRef(null);
|
|
111
|
+
const highlightedItemRef = /*#__PURE__*/React.createRef();
|
|
112
|
+
const [isKeyboardNavigating, setIsKeyboardNavigating] = useState(false);
|
|
113
|
+
const skipScrollingRef = useRef(false);
|
|
114
|
+
const [searchString, setSearchString] = useState('');
|
|
115
|
+
const groups = useStrongMemo(() => convertToOptionGroupsIfNeeded(options), [options]);
|
|
116
|
+
const filteredGroups = useStrongMemo(() => {
|
|
168
117
|
if (searchString === '') {
|
|
169
118
|
return groups;
|
|
170
119
|
}
|
|
171
120
|
|
|
172
|
-
|
|
173
|
-
return
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
182
|
-
});
|
|
121
|
+
const filter = new RegExp(`(?:^|\\s)${escapeRegex(searchString)}`, 'i');
|
|
122
|
+
return groups.map(g => ({ ...g,
|
|
123
|
+
options: g.options.filter(_ref3 => {
|
|
124
|
+
let {
|
|
125
|
+
label
|
|
126
|
+
} = _ref3;
|
|
127
|
+
return filter.test(label);
|
|
128
|
+
})
|
|
129
|
+
}));
|
|
183
130
|
}, [searchString, groups]);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
menuIsOpen = _useState8[0],
|
|
188
|
-
setMenuIsOpen = _useState8[1];
|
|
189
|
-
|
|
190
|
-
var _useState9 = useState(function () {
|
|
191
|
-
return getDefaultCursorIndex(filteredGroups);
|
|
192
|
-
}),
|
|
193
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
194
|
-
cursorIndex = _useState10[0],
|
|
195
|
-
setCursorIndex = _useState10[1];
|
|
196
|
-
|
|
197
|
-
useEffect(function () {
|
|
131
|
+
const [menuIsOpen, setMenuIsOpen] = useState(false);
|
|
132
|
+
const [cursorIndex, setCursorIndex] = useState(() => getDefaultCursorIndex(filteredGroups));
|
|
133
|
+
useEffect(() => {
|
|
198
134
|
setCursorIndex(getDefaultCursorIndex(filteredGroups));
|
|
199
135
|
|
|
200
136
|
if (searchString !== '') {
|
|
201
137
|
setMenuIsOpen(true);
|
|
202
138
|
}
|
|
203
139
|
}, [searchString, filteredGroups]);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
var _index = _slicedToArray(index, 2),
|
|
209
|
-
grpIndex = _index[0],
|
|
210
|
-
optIndex = _index[1];
|
|
211
|
-
|
|
212
|
-
var selectedOption = filteredGroups[grpIndex].options[optIndex];
|
|
140
|
+
const isEmptyMenu = useMemo(() => isGroupsEmpty(filteredGroups), [filteredGroups]);
|
|
141
|
+
const handleSelectIndex = useCallback(index => {
|
|
142
|
+
const [grpIndex, optIndex] = index;
|
|
143
|
+
const selectedOption = filteredGroups[grpIndex].options[optIndex];
|
|
213
144
|
setMenuIsOpen(false);
|
|
214
145
|
setSearchString('');
|
|
215
146
|
setIsKeyboardNavigating(false);
|
|
@@ -218,32 +149,28 @@ var Select = function Select(_ref2) {
|
|
|
218
149
|
onChange(selectedOption);
|
|
219
150
|
}
|
|
220
151
|
}, [onChange, filteredGroups]);
|
|
221
|
-
useEffect(
|
|
152
|
+
useEffect(() => {
|
|
222
153
|
if (dropdownRef.current) {
|
|
223
154
|
dropdownRef.current.scheduleUpdate();
|
|
224
155
|
}
|
|
225
156
|
}, [searchString]);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}, []);
|
|
229
|
-
useEffect(function () {
|
|
157
|
+
const handleMouseMove = useCallback(() => setIsKeyboardNavigating(false), []);
|
|
158
|
+
useEffect(() => {
|
|
230
159
|
if (isKeyboardNavigating) {
|
|
231
160
|
document.addEventListener('mousemove', handleMouseMove);
|
|
232
161
|
}
|
|
233
162
|
|
|
234
|
-
return
|
|
235
|
-
return document.removeEventListener('mousemove', handleMouseMove);
|
|
236
|
-
};
|
|
163
|
+
return () => document.removeEventListener('mousemove', handleMouseMove);
|
|
237
164
|
}, [handleMouseMove, isKeyboardNavigating]);
|
|
238
|
-
useEffect(
|
|
165
|
+
useEffect(() => {
|
|
239
166
|
if (isKeyboardNavigating && highlightedItemRef.current) {
|
|
240
167
|
if (skipScrollingRef.current) {
|
|
241
168
|
skipScrollingRef.current = false;
|
|
242
169
|
} else {
|
|
243
|
-
|
|
170
|
+
let elementToScrollTo = highlightedItemRef.current;
|
|
244
171
|
|
|
245
172
|
if (cursorIndex[0] === 0 && cursorIndex[1] === 0) {
|
|
246
|
-
|
|
173
|
+
const groupHeader = highlightedItemRef.current.previousSibling;
|
|
247
174
|
|
|
248
175
|
if (groupHeader) {
|
|
249
176
|
elementToScrollTo = groupHeader;
|
|
@@ -259,15 +186,15 @@ var Select = function Select(_ref2) {
|
|
|
259
186
|
}
|
|
260
187
|
}
|
|
261
188
|
}, [highlightedItemRef, cursorIndex, isKeyboardNavigating]);
|
|
262
|
-
|
|
189
|
+
const handleClose = useCallback(() => {
|
|
263
190
|
setSearchString('');
|
|
264
191
|
setMenuIsOpen(false);
|
|
265
192
|
setIsKeyboardNavigating(false);
|
|
266
193
|
}, []);
|
|
267
|
-
|
|
268
|
-
|
|
194
|
+
const handleKeyNavigation = useCallback( // eslint-disable-next-line complexity
|
|
195
|
+
e => {
|
|
269
196
|
if (e.key === ARROW_DOWN || e.key === ARROW_UP) {
|
|
270
|
-
|
|
197
|
+
const isDownDirection = e.key === ARROW_DOWN;
|
|
271
198
|
setCursorIndex(getMovedCursorIndex(filteredGroups, cursorIndex, isDownDirection));
|
|
272
199
|
setIsKeyboardNavigating(true);
|
|
273
200
|
e.preventDefault();
|
|
@@ -287,20 +214,16 @@ var Select = function Select(_ref2) {
|
|
|
287
214
|
handleClose();
|
|
288
215
|
}
|
|
289
216
|
}, [filteredGroups, cursorIndex, handleClose, handleSelectIndex, isSearchable]);
|
|
290
|
-
|
|
217
|
+
const handleClick = useCallback(() => {
|
|
291
218
|
if (isDisabled) {
|
|
292
219
|
return;
|
|
293
220
|
}
|
|
294
221
|
|
|
295
|
-
setMenuIsOpen(
|
|
296
|
-
return !currentMenuIsOpen;
|
|
297
|
-
});
|
|
222
|
+
setMenuIsOpen(currentMenuIsOpen => !currentMenuIsOpen);
|
|
298
223
|
setSearchString('');
|
|
299
224
|
}, [isDisabled]);
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}, []);
|
|
303
|
-
var handleClearClick = useCallback(function () {
|
|
225
|
+
const handleSearchInputChange = useCallback(searchValue => setSearchString(searchValue), []);
|
|
226
|
+
const handleClearClick = useCallback(() => {
|
|
304
227
|
setCursorIndex(getDefaultCursorIndex(filteredGroups));
|
|
305
228
|
setMenuIsOpen(false);
|
|
306
229
|
|
|
@@ -308,7 +231,7 @@ var Select = function Select(_ref2) {
|
|
|
308
231
|
onChange(null);
|
|
309
232
|
}
|
|
310
233
|
}, [filteredGroups, onChange]);
|
|
311
|
-
|
|
234
|
+
const handleTriggerKeyDown = useCallback(e => {
|
|
312
235
|
if (e.key === ESCAPE) {
|
|
313
236
|
handleClose();
|
|
314
237
|
e.preventDefault();
|
|
@@ -321,9 +244,9 @@ var Select = function Select(_ref2) {
|
|
|
321
244
|
if (menuIsOpen) {
|
|
322
245
|
handleKeyNavigation(e);
|
|
323
246
|
} else {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
247
|
+
const target = e.target;
|
|
248
|
+
const trigger = target.closest('[data-target="trigger"]');
|
|
249
|
+
const isTriggerTarget = trigger === target;
|
|
327
250
|
|
|
328
251
|
if (shouldOpenSelect(e.key, isTriggerTarget)) {
|
|
329
252
|
setMenuIsOpen(true);
|
|
@@ -341,17 +264,17 @@ var Select = function Select(_ref2) {
|
|
|
341
264
|
}
|
|
342
265
|
}
|
|
343
266
|
}, [menuIsOpen, isDisabled, isClearable, handleClose, handleClearClick, handleKeyNavigation]);
|
|
344
|
-
|
|
267
|
+
const handleHighlightIndex = useCallback(index => {
|
|
345
268
|
if (!isIndexMatchCursor(cursorIndex, index)) {
|
|
346
269
|
setCursorIndex(index);
|
|
347
270
|
}
|
|
348
271
|
}, [cursorIndex]); // We use invisible and "untouchable" dummy element to observe `size` changes from css to trigger force rerenders
|
|
349
272
|
|
|
350
|
-
|
|
351
|
-
|
|
273
|
+
const observableRef = useObservableForceRerender();
|
|
274
|
+
let sizeFromCss = null;
|
|
352
275
|
|
|
353
276
|
if (triggerFormWrapperRef && menuIsOpen) {
|
|
354
|
-
var
|
|
277
|
+
var _context;
|
|
355
278
|
|
|
356
279
|
// In theory this part of the code might cause issues with SSR.
|
|
357
280
|
// But in this specific context, because of checking ref "triggerFormWrapperRef",
|
|
@@ -360,14 +283,14 @@ var Select = function Select(_ref2) {
|
|
|
360
283
|
// Also, there will be no layout shifts on the following renders because
|
|
361
284
|
// it's a dropdown-content and in most cases it opens only on-demand.
|
|
362
285
|
// In additional, we use "observable" el to watch size changes between rerenders (@media query case).
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
sizeFromCss = _includesInstanceProperty(
|
|
286
|
+
const triggerFormWrapperStyles = getComputedStyle(triggerFormWrapperRef);
|
|
287
|
+
const rawSizeFromCss = triggerFormWrapperStyles.getPropertyValue('--_rs-select-size');
|
|
288
|
+
sizeFromCss = _includesInstanceProperty(_context = ['s', 'm', 'l']).call(_context, rawSizeFromCss) ? rawSizeFromCss : null;
|
|
366
289
|
}
|
|
367
290
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
291
|
+
const actualSize = sizeFromCss || size;
|
|
292
|
+
const maxHeight = calculateMaxHeight(actualSize);
|
|
293
|
+
const withGroupsLabel = !withoutGroupsLabel(filteredGroups);
|
|
371
294
|
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
372
295
|
theme: theme,
|
|
373
296
|
onRequestClose: handleClose,
|
|
@@ -380,8 +303,10 @@ var Select = function Select(_ref2) {
|
|
|
380
303
|
maxHeight: maxHeight,
|
|
381
304
|
leastMaxHeight: maxHeight,
|
|
382
305
|
disableFocusLock: true,
|
|
383
|
-
trigger:
|
|
384
|
-
|
|
306
|
+
trigger: _ref4 => {
|
|
307
|
+
let {
|
|
308
|
+
ref
|
|
309
|
+
} = _ref4;
|
|
385
310
|
return /*#__PURE__*/React.createElement(FormTriggerWrapper, {
|
|
386
311
|
ref: setTriggerFormWrapperRef,
|
|
387
312
|
className: cn(className, SIZE_STYLES[size]),
|
|
@@ -426,18 +351,16 @@ var Select = function Select(_ref2) {
|
|
|
426
351
|
disableCursor: isKeyboardNavigating,
|
|
427
352
|
className: cn(styles.menu, withGroupsLabel && styles.withGroupsLabel, MENU_SIZE_STYLES[actualSize]),
|
|
428
353
|
enableKeyboardNavigation: false
|
|
429
|
-
}, !isEmptyMenu ?
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
});
|
|
440
|
-
}) : /*#__PURE__*/React.createElement(MenuItem, {
|
|
354
|
+
}, !isEmptyMenu ? getPlainOptionsFromGroups(filteredGroups).map((item, i, collection) => /*#__PURE__*/React.createElement(Option, {
|
|
355
|
+
item: item,
|
|
356
|
+
isLastItem: i === collection.length - 1,
|
|
357
|
+
key: getOptionKey(item, i),
|
|
358
|
+
selected: value,
|
|
359
|
+
cursorIndex: cursorIndex,
|
|
360
|
+
highlightedItemRef: highlightedItemRef,
|
|
361
|
+
handleSelectIndex: handleSelectIndex,
|
|
362
|
+
handleHighlightIndex: handleHighlightIndex
|
|
363
|
+
})) : /*#__PURE__*/React.createElement(MenuItem, {
|
|
441
364
|
disabled: true
|
|
442
365
|
}, getEmptyMessage(isLoading, isSearchable && searchString.length > 0, noOptionsMessage))));
|
|
443
366
|
};
|