ui: fix user_select_multi

pull/340/head
undefined 3 years ago
parent 8f4a63006a
commit 43c4866eb2

@ -32,7 +32,7 @@ export default class UserSelectAutoComplete<Multi extends boolean> extends AutoC
}
value(): Multi extends true ? number[] : string {
if (this.options.multi) return this.ref?.getSelectedItems().map((item) => item._id) ?? this.$dom.val();
if (this.options.multi) return this.ref?.getSelectedItemKeys().map((i) => +i) ?? this.$dom.val();
return this.ref?.getSelectedItems()[0] ?? null;
}

@ -103,14 +103,12 @@ const AutoComplete = forwardRef(function Impl<T>(props: AutoCompleteProps<T>, re
setCurrentItem(null);
};
const calculateValue = () => {
const dispatchChange = () => {
const query = inputRef.current?.value;
if (!query) return multi ? selectedKeys.join(',') : '';
return (multi && selectedKeys.length) ? `${selectedKeys.join(',')},${query}` : query;
const val = [...selectedKeys, query].filter((i) => i).join(',');
onChange(val);
};
const dispatchChange = () => onChange(calculateValue());
useEffect(() => {
dispatchChange();
}, [selectedKeys, multi]);

Loading…
Cancel
Save