ui: fix user_select_multi

This commit is contained in:
undefined committed 2022-04-05 06:07:30 +08:00
1 parent 8f4a63006a
commit 43c4866eb2
2 files changed
+4 -6

No files matched your search

@@ -32,7 +32,7 @@ export default class UserSelectAutoComplete<Multi extends boolean> extends AutoC
} }
value(): Multi extends true ? number[] : string { 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; return this.ref?.getSelectedItems()[0] ?? null;
} }
@@ -103,14 +103,12 @@ const AutoComplete = forwardRef(function Impl<T>(props: AutoCompleteProps<T>, re
setCurrentItem(null); setCurrentItem(null);
}; };
const calculateValue = () => { const dispatchChange = () => {
const query = inputRef.current?.value; const query = inputRef.current?.value;
if (!query) return multi ? selectedKeys.join(',') : ''; const val = [...selectedKeys, query].filter((i) => i).join(',');
return (multi && selectedKeys.length) ? `${selectedKeys.join(',')},${query}` : query; onChange(val);
}; };
const dispatchChange = () => onChange(calculateValue());
useEffect(() => { useEffect(() => {
dispatchChange(); dispatchChange();
}, [selectedKeys, multi]); }, [selectedKeys, multi]);