mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui: fix user_select_multi
This commit is contained in:
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 {
|
||||
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]);
|
||||
|
||||
Reference in new issue
Block a user