@neovici/cosmoz-autocomplete 13.4.0 → 13.4.1

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.
@@ -15,6 +15,7 @@ interface Base<I> {
15
15
  interface Meta<I> extends Omit<Base<I>, 'value'> {
16
16
  setOpened: (opened: boolean) => void;
17
17
  value: I[];
18
+ valueProperty?: string;
18
19
  }
19
20
  export interface Props<I> extends Base<I> {
20
21
  text?: string;
@@ -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.includes(newVal);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-autocomplete",
3
- "version": "13.4.0",
3
+ "version": "13.4.1",
4
4
  "type": "module",
5
5
  "description": "A autocomplete input web component",
6
6
  "keywords": [