mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 09:36:08 +08:00
ui: autocomplete: fix value() method
This commit is contained in:
2 files changed
+5
-8
No files matched your search
@@ -77,8 +77,8 @@ const AutoComplete = forwardRef(function AutoComplete(props, ref) {
|
||||
}, 300);
|
||||
|
||||
const toggleItem = (item) => {
|
||||
const key = itemKey(item);
|
||||
if (multi) {
|
||||
const key = itemKey(item);
|
||||
const idx = selectedKeys.indexOf(key);
|
||||
if (idx !== -1) {
|
||||
setSelected((s) => {
|
||||
@@ -99,7 +99,8 @@ const AutoComplete = forwardRef(function AutoComplete(props, ref) {
|
||||
inputRef.current.focus();
|
||||
} else {
|
||||
setSelected([item]);
|
||||
inputRef.current.value = itemKey(item);
|
||||
setSelectedKeys([key]);
|
||||
inputRef.current.value = key;
|
||||
dispatchChange();
|
||||
}
|
||||
setItemList([]);
|
||||
|
||||
@@ -71,12 +71,8 @@ export default class AutoComplete extends DOMAttachedObject {
|
||||
}
|
||||
|
||||
value() {
|
||||
if (this.ref?.getSelectedItems) {
|
||||
const selected = this.ref.getSelectedItems();
|
||||
if (this.options.multi) return selected;
|
||||
return selected[0];
|
||||
}
|
||||
return this.$dom.val();
|
||||
if (this.options.multi) return this.$dom.val();
|
||||
return this.ref?.getSelectedItems()[0] ?? null;
|
||||
}
|
||||
|
||||
detach() {
|
||||
|
||||
Reference in new issue
Block a user