@@ -122,7 +122,6 @@ const Input = forwardRefWithStatics(
122122 // inputPreRef 用于预存输入框宽度,应用在 auto width 模式中
123123 const inputPreRef : React . RefObject < HTMLInputElement > = useRef ( null ) ;
124124 const wrapperRef : React . RefObject < HTMLDivElement > = useRef ( null ) ;
125- const isClickingIconRef = useRef ( false ) ;
126125
127126 const [ isHover , toggleIsHover ] = useState ( false ) ;
128127 const [ isFocused , toggleIsFocused ] = useState ( false ) ;
@@ -139,14 +138,15 @@ const Input = forwardRefWithStatics(
139138 const prefixIconContent = renderIcon ( classPrefix , 'prefix' , parseTNode ( prefixIcon ) ) ;
140139 let suffixIconNew = suffixIcon ;
141140
142- if ( isShowClearIcon )
141+ if ( isShowClearIcon ) {
143142 suffixIconNew = (
144143 < CloseCircleFilledIcon
145144 className = { `${ classPrefix } -input__suffix-clear` }
146- onMouseDown = { handleMouseDown }
145+ onMouseDown = { handleIconMouseDown }
147146 onClick = { handleClear }
148147 />
149148 ) ;
149+ }
150150 if ( type === 'password' && typeof suffixIcon === 'undefined' ) {
151151 const PASSWORD_ICON_MAP = {
152152 password : BrowseOffIcon ,
@@ -155,11 +155,7 @@ const Input = forwardRefWithStatics(
155155 const PasswordIcon = PASSWORD_ICON_MAP [ renderType ] ;
156156 if ( PasswordIcon ) {
157157 suffixIconNew = (
158- < PasswordIcon
159- className = { `${ classPrefix } -input__suffix-clear` }
160- onMouseDown = { handleMouseDown }
161- onClick = { togglePasswordVisible }
162- />
158+ < PasswordIcon className = { `${ classPrefix } -input__suffix-clear` } onClick = { togglePasswordVisible } />
163159 ) ;
164160 }
165161 }
@@ -273,6 +269,7 @@ const Input = forwardRefWithStatics(
273269 } ) }
274270 onMouseEnter = { handleMouseEnter }
275271 onMouseLeave = { handleMouseLeave }
272+ onMouseDown = { handleMouseDown }
276273 onWheel = { ( e ) => onWheel ?.( { e } ) }
277274 onClick = { ( e ) => {
278275 inputRef . current ?. focus ( ) ;
@@ -308,7 +305,6 @@ const Input = forwardRefWithStatics(
308305
309306 requestAnimationFrame ( ( ) => {
310307 inputEl ?. setSelectionRange ( cursorPosition , cursorPosition ) ;
311- isClickingIconRef . current = false ;
312308 } ) ;
313309 }
314310
@@ -328,20 +324,20 @@ const Input = forwardRefWithStatics(
328324 onChange ( newStr , { e, trigger } ) ;
329325 }
330326 }
331- // 添加MouseDown阻止冒泡,防止點擊Clear value會導致彈窗閃爍一下
332- // https://github.com/Tencent/tdesign-react/issues/2320
333- function handleMouseDown ( e : React . MouseEvent < SVGSVGElement , globalThis . MouseEvent > ) {
327+ function handleIconMouseDown ( e : React . MouseEvent < SVGSVGElement > ) {
328+ e . preventDefault ( ) ;
329+ // 阻止冒泡,防止点击 icon 会导致弹窗闪烁一下
330+ // https://github.com/Tencent/tdesign-react/issues/2320
334331 e . stopPropagation ( ) ;
335- // 兼容React16
332+ // 兼容 React 16
336333 e . nativeEvent . stopImmediatePropagation ( ) ;
337- isClickingIconRef . current = true ;
334+ }
335+ function handleMouseDown ( e : React . MouseEvent < HTMLDivElement > ) {
336+ e . preventDefault ( ) ; // 防止焦点转移
338337 }
339338 function handleClear ( e : React . MouseEvent < SVGSVGElement > ) {
340339 onChange ?.( '' , { e, trigger : 'clear' } ) ;
341340 onClear ?.( { e } ) ;
342- requestAnimationFrame ( ( ) => {
343- isClickingIconRef . current = false ;
344- } ) ;
345341 }
346342 function handleKeyDown ( e : React . KeyboardEvent < HTMLInputElement > ) {
347343 const {
@@ -382,7 +378,6 @@ const Input = forwardRefWithStatics(
382378 }
383379
384380 function handleFocus ( e : React . FocusEvent < HTMLInputElement > ) {
385- if ( isClickingIconRef . current ) return ;
386381 const {
387382 currentTarget : { value } ,
388383 } = e ;
@@ -392,7 +387,6 @@ const Input = forwardRefWithStatics(
392387 }
393388
394389 function handleBlur ( e : React . FocusEvent < HTMLInputElement > ) {
395- if ( isClickingIconRef . current ) return ;
396390 const {
397391 currentTarget : { value } ,
398392 } = e ;
0 commit comments