mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
fix(components): [autocomplete] can not fetch suggestions after clear (#6847)
* fix(components): [autocomplete] can not fetch suggestions after clear * style: define valuePresented constant
This commit is contained in:
parent
58ca971e39
commit
c05bc511a8
@ -7,6 +7,7 @@
|
||||
<el-autocomplete
|
||||
v-model="state1"
|
||||
:fetch-suggestions="querySearch"
|
||||
clearable
|
||||
class="inline-input"
|
||||
placeholder="Please Input"
|
||||
@select="handleSelect"
|
||||
@ -20,6 +21,7 @@
|
||||
v-model="state2"
|
||||
:fetch-suggestions="querySearch"
|
||||
:trigger-on-focus="false"
|
||||
clearable
|
||||
class="inline-input"
|
||||
placeholder="Please Input"
|
||||
@select="handleSelect"
|
||||
|
@ -128,6 +128,7 @@ const { compatTeleported } = useDeprecateAppendToBody(
|
||||
COMPONENT_NAME,
|
||||
'popperAppendToBody'
|
||||
)
|
||||
let isClear = false
|
||||
const attrs = useAttrs()
|
||||
const compAttrs = useCompAttrs()
|
||||
const suggestions = ref<any[]>([])
|
||||
@ -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')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user