From 8e8073d17ed74c91b3ec7b15cb6cc3f01b30c822 Mon Sep 17 00:00:00 2001 From: hippo <53283780+hippo2cat@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:29:38 +0800 Subject: [PATCH] fix: input clear error (#7523) --- components/vc-input/Input.tsx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/components/vc-input/Input.tsx b/components/vc-input/Input.tsx index 039a8d3975..55312b310f 100644 --- a/components/vc-input/Input.tsx +++ b/components/vc-input/Input.tsx @@ -15,7 +15,7 @@ import { triggerFocus, } from './utils/commonUtils'; import BaseInput from './BaseInput'; -import BaseInputCore from '../_util/BaseInput'; +import BaseInputCore, { type BaseInputExpose } from '../_util/BaseInput'; export default defineComponent({ name: 'VCInput', @@ -24,7 +24,7 @@ export default defineComponent({ setup(props, { slots, attrs, expose, emit }) { const stateValue = shallowRef(props.value === undefined ? props.defaultValue : props.value); const focused = shallowRef(false); - const inputRef = shallowRef(); + const inputRef = shallowRef(); const rootRef = shallowRef(); watch( () => props.value, @@ -42,12 +42,12 @@ export default defineComponent({ ); const focus = (option?: InputFocusOptions) => { if (inputRef.value) { - triggerFocus(inputRef.value, option); + triggerFocus(inputRef.value.input, option); } }; const blur = () => { - inputRef.value?.blur(); + inputRef.value.input?.blur(); }; const setSelectionRange = ( @@ -55,17 +55,17 @@ export default defineComponent({ end: number, direction?: 'forward' | 'backward' | 'none', ) => { - inputRef.value?.setSelectionRange(start, end, direction); + inputRef.value.input?.setSelectionRange(start, end, direction); }; const select = () => { - inputRef.value?.select(); + inputRef.value.input?.select(); }; expose({ focus, blur, - input: computed(() => (inputRef.value as any)?.input), + input: computed(() => (inputRef.value.input as any)?.input), stateValue, setSelectionRange, select, @@ -81,7 +81,7 @@ export default defineComponent({ stateValue.value = value; } else { nextTick(() => { - if (inputRef.value.value !== stateValue.value) { + if (inputRef.value.input.value !== stateValue.value) { rootRef.value?.$forceUpdate(); } }); @@ -94,7 +94,7 @@ export default defineComponent({ const { value } = e.target as any; if (stateValue.value === value) return; const newVal = e.target.value; - resolveOnChange(inputRef.value, e, triggerChange); + resolveOnChange(inputRef.value.input as HTMLInputElement, e, triggerChange); setValue(newVal); }; @@ -116,7 +116,7 @@ export default defineComponent({ }; const handleReset = (e: MouseEvent) => { - resolveOnChange(inputRef.value, e, triggerChange); + resolveOnChange(inputRef.value.input as HTMLInputElement, e, triggerChange); setValue('', () => { focus(); });