@neovici/cosmoz-autocomplete 13.4.0 → 13.5.0
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.
|
@@ -65,6 +65,7 @@ export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onTe
|
|
|
65
65
|
keepOpened,
|
|
66
66
|
setOpened,
|
|
67
67
|
onSelect,
|
|
68
|
+
valueProperty,
|
|
68
69
|
});
|
|
69
70
|
const [, , state] = usePromise(source$);
|
|
70
71
|
return {
|
|
@@ -111,22 +112,22 @@ export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onTe
|
|
|
111
112
|
if (disabled)
|
|
112
113
|
return;
|
|
113
114
|
meta.onSelect?.(newVal, meta);
|
|
114
|
-
const { onChange, onText, limit, min, value: val, keepQuery, keepOpened, setOpened, } = meta;
|
|
115
|
+
const { onChange, onText, limit, min, value: val, keepQuery, keepOpened, setOpened, valueProperty, } = meta;
|
|
115
116
|
if (!keepQuery)
|
|
116
117
|
onText('');
|
|
117
118
|
if (!keepOpened)
|
|
118
119
|
setOpened(false);
|
|
119
|
-
const value = array(val), deselect = value.
|
|
120
|
+
const value = array(val), predicate = prop(valueProperty), deselect = value.some((v) => predicate(v) === predicate(newVal));
|
|
120
121
|
if (deselect && value.length === min)
|
|
121
122
|
return;
|
|
122
123
|
onChange((deselect
|
|
123
|
-
? without(newVal)(value)
|
|
124
|
+
? without(newVal, predicate)(value)
|
|
124
125
|
: [...value, newVal]).slice(-limit));
|
|
125
126
|
}, [disabled, meta]),
|
|
126
127
|
onDeselect: useCallback((val) => {
|
|
127
128
|
if (disabled)
|
|
128
129
|
return;
|
|
129
|
-
meta.onChange(without(val)(meta.value));
|
|
130
|
+
meta.onChange(without(val, prop(meta.valueProperty))(meta.value));
|
|
130
131
|
}, [disabled, meta]),
|
|
131
132
|
// whenever there is a query, override defaultIndex to 0, so the first result gets selected
|
|
132
133
|
defaultIndex: query !== undefined && query?.length > 0 ? 0 : defaultIndex,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import './autocomplete/';
|
|
2
|
+
import './excluding/';
|
|
2
3
|
export { AUTOCOMPLETE_DESELECT_LAST, autocompleteKeybindings, } from './autocomplete/autocomplete-keybindings';
|
|
3
4
|
export type { Source } from './autocomplete/use-autocomplete';
|
|
4
5
|
export { LISTBOX_NAVIGATE_DOWN, LISTBOX_NAVIGATE_UP, LISTBOX_SELECT, listboxKeybindings, } from './listbox/listbox-keybindings';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import './autocomplete/';
|
|
2
|
+
import './excluding/';
|
|
2
3
|
export { AUTOCOMPLETE_DESELECT_LAST, autocompleteKeybindings, } from './autocomplete/autocomplete-keybindings';
|
|
3
4
|
export { LISTBOX_NAVIGATE_DOWN, LISTBOX_NAVIGATE_UP, LISTBOX_SELECT, listboxKeybindings, } from './listbox/listbox-keybindings';
|