@pushwoosh/dumb-components 2.9.16 → 2.9.18
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useId, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { DEFAULT_DEBOUNCE_MS, FieldInput, FieldShell, defaultGetKey, resolveDropdownText, useActiveIndex, useDropdownItems, useFieldOpenEffects, useListNavigation, useShellMouseDown, useToggleOpen } from '../shared/dropdownField';
|
|
4
4
|
function FreeCombobox({
|
|
5
5
|
items,
|
|
@@ -101,6 +101,7 @@ function FreeCombobox({
|
|
|
101
101
|
onChange(event.target.value, {
|
|
102
102
|
source: 'input'
|
|
103
103
|
});
|
|
104
|
+
setActiveIndex(-1);
|
|
104
105
|
if (!isOpen) open();
|
|
105
106
|
};
|
|
106
107
|
return _jsx(FieldShell, {
|
|
@@ -120,6 +121,7 @@ function FreeCombobox({
|
|
|
120
121
|
onChange('', {
|
|
121
122
|
source: 'input'
|
|
122
123
|
});
|
|
124
|
+
setActiveIndex(-1);
|
|
123
125
|
inputRef.current?.focus();
|
|
124
126
|
},
|
|
125
127
|
dropdownItems: dropdownItems,
|
|
@@ -198,13 +200,30 @@ function SelectCombobox({
|
|
|
198
200
|
const valueLabel = hasValue ? getLabel(value) : '';
|
|
199
201
|
const selectedKey = hasValue ? getKey(value) : null;
|
|
200
202
|
const inputValue = isOpen ? query : valueLabel;
|
|
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]);
|
|
201
209
|
const open = useCallback(() => {
|
|
202
210
|
if (isOpen) return;
|
|
203
211
|
setIsOpen(true);
|
|
204
212
|
setQuery('');
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
activateSelected();
|
|
214
|
+
}, [isOpen, activateSelected]);
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
if (!isOpen || query || userMovedRef.current || selectedIndex < 0) return;
|
|
217
|
+
setActiveIndex(selectedIndex);
|
|
218
|
+
}, [isOpen, query, selectedIndex, setActiveIndex]);
|
|
219
|
+
const moveActive = useCallback(next => {
|
|
220
|
+
userMovedRef.current = true;
|
|
221
|
+
setActiveIndex(next);
|
|
222
|
+
}, [setActiveIndex]);
|
|
223
|
+
const search = event => {
|
|
224
|
+
setQuery(event.target.value);
|
|
225
|
+
if (event.target.value) moveActive(0);else activateSelected();
|
|
226
|
+
};
|
|
208
227
|
const close = useCallback(() => {
|
|
209
228
|
setIsOpen(false);
|
|
210
229
|
setQuery('');
|
|
@@ -221,7 +240,7 @@ function SelectCombobox({
|
|
|
221
240
|
open,
|
|
222
241
|
itemCount: filteredItems.length,
|
|
223
242
|
activeIndex,
|
|
224
|
-
setActiveIndex,
|
|
243
|
+
setActiveIndex: moveActive,
|
|
225
244
|
onSelectIndex: index => commit(filteredItems[index]),
|
|
226
245
|
onEscape: close,
|
|
227
246
|
onReachEnd: loadMore
|
|
@@ -282,7 +301,7 @@ function SelectCombobox({
|
|
|
282
301
|
ref: inputRef,
|
|
283
302
|
autosize: autosize,
|
|
284
303
|
value: inputValue,
|
|
285
|
-
onChange:
|
|
304
|
+
onChange: search,
|
|
286
305
|
onKeyDown: onInputKeyDown,
|
|
287
306
|
onFocus: open,
|
|
288
307
|
placeholder: placeholder,
|
|
@@ -92,7 +92,8 @@ export function ComboboxMulti({
|
|
|
92
92
|
const close = useCallback(() => {
|
|
93
93
|
setIsOpen(false);
|
|
94
94
|
setQuery('');
|
|
95
|
-
|
|
95
|
+
setActiveIndex(0);
|
|
96
|
+
}, [setActiveIndex]);
|
|
96
97
|
const toggle = useCallback(item => {
|
|
97
98
|
const key = getKey(item);
|
|
98
99
|
if (selectedKeys.has(key)) {
|
|
@@ -202,7 +203,10 @@ export function ComboboxMulti({
|
|
|
202
203
|
ref: inputRef,
|
|
203
204
|
autosize: autosize,
|
|
204
205
|
value: query,
|
|
205
|
-
onChange: e =>
|
|
206
|
+
onChange: e => {
|
|
207
|
+
setQuery(e.target.value);
|
|
208
|
+
setActiveIndex(0);
|
|
209
|
+
},
|
|
206
210
|
onKeyDown: onInputKeyDown,
|
|
207
211
|
onFocus: open,
|
|
208
212
|
placeholder: hasTags ? undefined : placeholder,
|
package/package.json
CHANGED
|
@@ -20,6 +20,7 @@ export const FieldInput = forwardRef(({
|
|
|
20
20
|
ref: ref,
|
|
21
21
|
value: value,
|
|
22
22
|
placeholder: placeholder,
|
|
23
|
+
spellCheck: false,
|
|
23
24
|
...rest
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -28,6 +29,7 @@ export const FieldInput = forwardRef(({
|
|
|
28
29
|
ref: ref,
|
|
29
30
|
value: value,
|
|
30
31
|
placeholder: placeholder,
|
|
32
|
+
spellCheck: false,
|
|
31
33
|
style: {
|
|
32
34
|
flex: 'none',
|
|
33
35
|
minWidth: 0,
|