Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): 修复input和textarea在ios输入法上中文快速输入导致的光标丢失问题 #5261

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/uni-components/src/helpers/useField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ function useValueSync(
return {
trigger,
triggerInput,
cancelValueChange: () => valueChangeFn!.cancel(),
}
}

Expand Down Expand Up @@ -406,6 +407,7 @@ function useEvent(
props: Props,
trigger: CustomEventTrigger,
triggerInput: Function,
cancelValueChange: Function,
beforeInput?: (event: Event, state: State) => any
) {
function checkSelection() {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down