1- import type { ChangeEvent , CompositionEvent , CSSProperties , FocusEvent , FormEvent , TouchEvent } from 'react' ;
1+ import type { ChangeEvent , CompositionEvent , CSSProperties , FocusEvent , InputEvent , TouchEvent } from 'react' ;
22import React , { forwardRef , useEffect , useImperativeHandle , useMemo , useRef , useState } from 'react' ;
33import classNames from 'classnames' ;
44import { isFunction } from 'lodash-es' ;
@@ -111,8 +111,11 @@ const Input = forwardRef<InputRefProps, InputProps>((props, ref) => {
111111 inputRef . current ?. blur ( ) ;
112112 }
113113
114- const handleInputValue = ( e : FormEvent < HTMLInputElement > ) => {
115- const { value } = e . target as HTMLInputElement ;
114+ const handleInputValue = (
115+ e : ChangeEvent < HTMLInputElement > | CompositionEvent < HTMLInputElement > | InputEvent < HTMLInputElement > ,
116+ ) => {
117+ const target = e . currentTarget || ( e . target as HTMLInputElement ) ;
118+ const { value } = target ;
116119 const { allowInputOverMax, maxcharacter } = props ;
117120
118121 // 如果允许超出最大输入限制,直接更新值并返回
@@ -139,12 +142,10 @@ const Input = forwardRef<InputRefProps, InputProps>((props, ref) => {
139142 return finalValue ;
140143 } ;
141144
142- const handleInput = ( e : ChangeEvent < HTMLInputElement > ) => {
145+ const handleInput = ( e : InputEvent < HTMLInputElement > ) => {
143146 const finalValue = handleInputValue ( e ) ;
144- // react 中为合成事件,需要通过 nativeEvent 获取原始的事件
145- const nativeEvent = e . nativeEvent as InputEvent ;
146147 // 中文输入的时候 inputType 是 insertCompositionText 所以中文输入的时候禁止触发。
147- if ( nativeEvent . isComposing || nativeEvent . inputType === 'insertCompositionText' ) {
148+ if ( e . nativeEvent . isComposing || e . nativeEvent . inputType === 'insertCompositionText' ) {
148149 composingRef . current = true ;
149150 setComposingValue ( finalValue ) ;
150151 return ;
0 commit comments