mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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);
|
}, 300);
|
||||||
|
|
||||||
const toggleItem = (item) => {
|
const toggleItem = (item) => {
|
||||||
|
const key = itemKey(item);
|
||||||
if (multi) {
|
if (multi) {
|
||||||
const key = itemKey(item);
|
|
||||||
const idx = selectedKeys.indexOf(key);
|
const idx = selectedKeys.indexOf(key);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
setSelected((s) => {
|
setSelected((s) => {
|
||||||
@@ -99,7 +99,8 @@ const AutoComplete = forwardRef(function AutoComplete(props, ref) {
|
|||||||
inputRef.current.focus();
|
inputRef.current.focus();
|
||||||
} else {
|
} else {
|
||||||
setSelected([item]);
|
setSelected([item]);
|
||||||
inputRef.current.value = itemKey(item);
|
setSelectedKeys([key]);
|
||||||
|
inputRef.current.value = key;
|
||||||
dispatchChange();
|
dispatchChange();
|
||||||
}
|
}
|
||||||
setItemList([]);
|
setItemList([]);
|
||||||
|
|||||||
@@ -71,12 +71,8 @@ export default class AutoComplete extends DOMAttachedObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value() {
|
value() {
|
||||||
if (this.ref?.getSelectedItems) {
|
if (this.options.multi) return this.$dom.val();
|
||||||
const selected = this.ref.getSelectedItems();
|
return this.ref?.getSelectedItems()[0] ?? null;
|
||||||
if (this.options.multi) return selected;
|
|
||||||
return selected[0];
|
|
||||||
}
|
|
||||||
return this.$dom.val();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
detach() {
|
detach() {
|
||||||
|
|||||||
Reference in new issue
Block a user