From 369eeb6fe10e74aea3dbbe3ec00da8749c4bf97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=B8=89?= Date: Wed, 18 Dec 2024 19:19:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8Dinput=E5=92=8Ctex?= =?UTF-8?q?tarea=E5=9C=A8ios=E8=BE=93=E5=85=A5=E6=B3=95=E4=B8=8A=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E5=BF=AB=E9=80=9F=E8=BE=93=E5=85=A5=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E5=85=89=E6=A0=87=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-components/src/helpers/useField.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/uni-components/src/helpers/useField.ts b/packages/uni-components/src/helpers/useField.ts index 1f29e70e0a9..83a35f88f3f 100644 --- a/packages/uni-components/src/helpers/useField.ts +++ b/packages/uni-components/src/helpers/useField.ts @@ -331,6 +331,7 @@ function useValueSync( return { trigger, triggerInput, + cancelValueChange: () => valueChangeFn!.cancel(), } } @@ -406,6 +407,7 @@ function useEvent( props: Props, trigger: CustomEventTrigger, triggerInput: Function, + cancelValueChange: Function, beforeInput?: (event: Event, state: State) => any ) { function checkSelection() { @@ -458,6 +460,8 @@ function useEvent( if (isFunction(beforeInput) && beforeInput(event, state) === false) { return } + // 修复ios输入法composition快速输入光标丢失问题 + cancelValueChange() state.value = field.value if (!state.composing || !props.ignoreCompositionEvent) { triggerInput( @@ -523,12 +527,25 @@ export function useField( ) { UniViewJSBridgeSubscribe() const { fieldRef, state, trigger } = useBase(props, rootRef, emit) - const { triggerInput } = useValueSync(props, state, emit, trigger) + const { triggerInput, cancelValueChange } = useValueSync( + props, + state, + emit, + trigger + ) useAutoFocus(props, fieldRef) useKeyboard(props, fieldRef, trigger) const { state: scopedAttrsState } = useScopedAttrs() useFormField('name', state) - useEvent(fieldRef, state, props, trigger, triggerInput, beforeInput) + useEvent( + fieldRef, + state, + props, + trigger, + triggerInput, + cancelValueChange, + beforeInput + ) // Safari 14 以上修正禁用状态颜色 // TODO fixDisabledColor 可以调整到beforeMount或mounted做修正,确保不影响SSR