Skip to content
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,
Copy link

Copilot AI May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an explicit TypeScript type annotation for the 'cancelValueChange' parameter in the useEvent function to improve type safety and clarity.

Suggested change
cancelValueChange: Function,
cancelValueChange: (value: any) => void,

Copilot uses AI. Check for mistakes.

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