ui: autocomplete: fix value() method

This commit is contained in:
无限UCW committed 2021-08-25 18:06:20 +08:00
1 parent 329d047699
commit 73e9c49a8f
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() {