diff --git a/packages/uni-components/src/helpers/useField.ts b/packages/uni-components/src/helpers/useField.ts index 9f4638a9168421fee9932f97cefa24bdec0f40c3..2520ff0ea8b51d819076fbf55a2f0c721336258d 100644 --- a/packages/uni-components/src/helpers/useField.ts +++ b/packages/uni-components/src/helpers/useField.ts @@ -314,7 +314,8 @@ function useEvent( field && state.focus && state.selectionStart > -1 && - state.selectionEnd > -1 + state.selectionEnd > -1 && + field.type !== 'number' ) { field.selectionStart = state.selectionStart field.selectionEnd = state.selectionEnd @@ -327,7 +328,8 @@ function useEvent( state.focus && state.selectionStart < 0 && state.selectionEnd < 0 && - state.cursor > -1 + state.cursor > -1 && + field.type !== 'number' ) { field.selectionEnd = field.selectionStart = state.cursor } @@ -370,9 +372,18 @@ function useEvent( onInput(event, true) } state.focus = false + const field = event.target! as HTMLInputElement + let cursor + if (field.type === 'number') { + field.type = 'text' + cursor = field.selectionEnd + field.type = 'number' + } else { + cursor = field.selectionEnd + } trigger('blur', event, { value: state.value, - cursor: (event.target as HTMLFieldElement).selectionEnd, + cursor, }) } // 避免触发父组件 change 事件