@pushwoosh/dumb-components 2.9.17 → 2.9.19
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/Combobox/Combobox.js +11 -9
- package/package.json +2 -2
package/Combobox/Combobox.js
CHANGED
|
@@ -201,26 +201,28 @@ function SelectCombobox({
|
|
|
201
201
|
const selectedKey = hasValue ? getKey(value) : null;
|
|
202
202
|
const inputValue = isOpen ? query : valueLabel;
|
|
203
203
|
const userMovedRef = useRef(false);
|
|
204
|
+
const selectedIndex = sourceItems.findIndex(it => getKey(it) === selectedKey);
|
|
205
|
+
const activateSelected = useCallback(() => {
|
|
206
|
+
userMovedRef.current = false;
|
|
207
|
+
setActiveIndex(selectedIndex >= 0 ? selectedIndex : 0);
|
|
208
|
+
}, [selectedIndex, setActiveIndex]);
|
|
204
209
|
const open = useCallback(() => {
|
|
205
210
|
if (isOpen) return;
|
|
206
211
|
setIsOpen(true);
|
|
207
212
|
setQuery('');
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
setActiveIndex(idx >= 0 ? idx : 0);
|
|
211
|
-
}, [isOpen, sourceItems, getKey, selectedKey, setActiveIndex]);
|
|
213
|
+
activateSelected();
|
|
214
|
+
}, [isOpen, activateSelected]);
|
|
212
215
|
useEffect(() => {
|
|
213
|
-
if (!isOpen || query || userMovedRef.current) return;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}, [isOpen, query, sourceItems, getKey, selectedKey, setActiveIndex]);
|
|
216
|
+
if (!isOpen || query || userMovedRef.current || selectedIndex < 0) return;
|
|
217
|
+
setActiveIndex(selectedIndex);
|
|
218
|
+
}, [isOpen, query, selectedIndex, setActiveIndex]);
|
|
217
219
|
const moveActive = useCallback(next => {
|
|
218
220
|
userMovedRef.current = true;
|
|
219
221
|
setActiveIndex(next);
|
|
220
222
|
}, [setActiveIndex]);
|
|
221
223
|
const search = event => {
|
|
222
224
|
setQuery(event.target.value);
|
|
223
|
-
moveActive(0);
|
|
225
|
+
if (event.target.value) moveActive(0);else activateSelected();
|
|
224
226
|
};
|
|
225
227
|
const close = useCallback(() => {
|
|
226
228
|
setIsOpen(false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/dumb-components",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.19",
|
|
4
4
|
"description": "React components to build Pushwoosh products",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@lezer/highlight": "^1.2.1",
|
|
41
41
|
"@pushwoosh/kit-constants": "^2.1.0",
|
|
42
42
|
"@pushwoosh/kit-helpers": "^4.12.7",
|
|
43
|
-
"@pushwoosh/kit-icons": "^2.3.
|
|
43
|
+
"@pushwoosh/kit-icons": "^2.3.7",
|
|
44
44
|
"@pushwoosh/kit-typography": "^1.8.7",
|
|
45
45
|
"@tippyjs/react": "^4.2.6",
|
|
46
46
|
"@uiw/codemirror-themes": "^4.23.8",
|