@@ -10,7 +10,7 @@ import React, {
1010} from 'react' ;
1111import BaseInput from './BaseInput' ;
1212import useCount from './hooks/useCount' ;
13- import type { InputProps , InputRef } from './interface' ;
13+ import type { ChangeEventInfo , InputProps , InputRef } from './interface' ;
1414import type { InputFocusOptions } from './utils/commonUtils' ;
1515import { resolveOnChange , triggerFocus } from './utils/commonUtils' ;
1616
@@ -40,7 +40,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
4040 } = props ;
4141
4242 const [ focused , setFocused ] = useState < boolean > ( false ) ;
43- const compositionRef = React . useRef ( false ) ;
43+ const compositionRef = useRef ( false ) ;
4444
4545 const inputRef = useRef < HTMLInputElement > ( null ) ;
4646
@@ -58,7 +58,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
5858 value === undefined || value === null ? '' : String ( value ) ;
5959
6060 // =================== Select Range ===================
61- const [ selection , setSelection ] = React . useState <
61+ const [ selection , setSelection ] = useState <
6262 [ start : number , end : number ] | null
6363 > ( null ) ;
6464
@@ -97,6 +97,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
9797 | React . ChangeEvent < HTMLInputElement >
9898 | React . CompositionEvent < HTMLInputElement > ,
9999 currentValue : string ,
100+ info : ChangeEventInfo ,
100101 ) => {
101102 let cutValue = currentValue ;
102103
@@ -116,6 +117,10 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
116117 inputRef . current ?. selectionEnd || 0 ,
117118 ] ) ;
118119 }
120+ } else if ( info . source === 'compositionEnd' ) {
121+ // Avoid triggering twice
122+ // https://github.com/ant-design/ant-design/issues/46587
123+ return ;
119124 }
120125 setValue ( cutValue ) ;
121126
@@ -124,21 +129,25 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
124129 }
125130 } ;
126131
127- React . useEffect ( ( ) => {
132+ useEffect ( ( ) => {
128133 if ( selection ) {
129134 inputRef . current ?. setSelectionRange ( ...selection ) ;
130135 }
131136 } , [ selection ] ) ;
132137
133138 const onInternalChange : React . ChangeEventHandler < HTMLInputElement > = ( e ) => {
134- triggerChange ( e , e . target . value ) ;
139+ triggerChange ( e , e . target . value , {
140+ source : 'change' ,
141+ } ) ;
135142 } ;
136143
137144 const onInternalCompositionEnd = (
138145 e : React . CompositionEvent < HTMLInputElement > ,
139146 ) => {
140147 compositionRef . current = false ;
141- triggerChange ( e , e . currentTarget . value ) ;
148+ triggerChange ( e , e . currentTarget . value , {
149+ source : 'compositionEnd' ,
150+ } ) ;
142151 onCompositionEnd ?.( e ) ;
143152 } ;
144153
0 commit comments