From c05bc511a88f9b15ee45e8a008e2d0d849597f93 Mon Sep 17 00:00:00 2001 From: bqy_fe <1743369777@qq.com> Date: Tue, 29 Mar 2022 15:48:50 +0800 Subject: [PATCH] fix(components): [autocomplete] can not fetch suggestions after clear (#6847) * fix(components): [autocomplete] can not fetch suggestions after clear * style: define valuePresented constant --- docs/examples/input/autocomplete.vue | 2 ++ packages/components/autocomplete/src/autocomplete.vue | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/examples/input/autocomplete.vue b/docs/examples/input/autocomplete.vue index 47d346c3a6..af3eb1f776 100644 --- a/docs/examples/input/autocomplete.vue +++ b/docs/examples/input/autocomplete.vue @@ -7,6 +7,7 @@ ([]) @@ -191,15 +192,21 @@ const getData = (queryString: string) => { } const debouncedGetData = debounce(getData, props.debounce) const handleInput = (value: string) => { + const valuePresented = Boolean(value) + emit('input', value) emit(UPDATE_MODEL_EVENT, value) suggestionDisabled.value = false - activated.value = Boolean(value) + activated.value ||= isClear && valuePresented + if (!props.triggerOnFocus && !value) { suggestionDisabled.value = true suggestions.value = [] return } + if (isClear && valuePresented) { + isClear = false + } debouncedGetData(value) } const handleChange = (value: string) => { @@ -217,6 +224,7 @@ const handleBlur = (evt: FocusEvent) => { } const handleClear = () => { activated.value = false + isClear = true emit(UPDATE_MODEL_EVENT, '') emit('clear') }