@@ -2,7 +2,7 @@ import TransBtn from '../TransBtn';
2
2
import type { InnerSelectorProps } from './interface' ;
3
3
import Input from './Input' ;
4
4
import type { Ref , PropType } from 'vue' ;
5
- import { computed , defineComponent , onMounted , shallowRef , watch } from 'vue' ;
5
+ import { ref , watchEffect , computed , defineComponent , onMounted , shallowRef , watch } from 'vue' ;
6
6
import classNames from '../../_util/classNames' ;
7
7
import pickAttrs from '../../_util/pickAttrs' ;
8
8
import PropTypes from '../../_util/vue-types' ;
@@ -24,6 +24,8 @@ type SelectorProps = InnerSelectorProps & {
24
24
tagRender ?: ( props : CustomTagProps ) => VueNode ;
25
25
onToggleOpen : any ;
26
26
27
+ compositionStatus : boolean ;
28
+
27
29
// Motion
28
30
choiceTransitionName ?: string ;
29
31
@@ -46,7 +48,7 @@ const props = {
46
48
autocomplete : String ,
47
49
activeDescendantId : String ,
48
50
tabindex : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
49
-
51
+ compositionStatus : Boolean ,
50
52
removeIcon : PropTypes . any ,
51
53
choiceTransitionName : String ,
52
54
@@ -91,11 +93,14 @@ const SelectSelector = defineComponent<SelectorProps>({
91
93
( ) =>
92
94
props . mode === 'tags' || ( ( props . showSearch && ( props . open || focused . value ) ) as boolean ) ,
93
95
) ;
94
-
96
+ const targetValue = ref ( '' ) ;
97
+ watchEffect ( ( ) => {
98
+ targetValue . value = inputValue . value ;
99
+ } ) ;
95
100
// We measure width and set to the input immediately
96
101
onMounted ( ( ) => {
97
102
watch (
98
- inputValue ,
103
+ targetValue ,
99
104
( ) => {
100
105
inputWidth . value = measureRef . value . scrollWidth ;
101
106
} ,
@@ -202,6 +207,14 @@ const SelectSelector = defineComponent<SelectorProps>({
202
207
return defaultRenderSelector ( content , content , false ) ;
203
208
}
204
209
210
+ const handleInput = ( e : Event ) => {
211
+ const composing = ( e . target as any ) . composing ;
212
+ targetValue . value = ( e . target as any ) . value ;
213
+ if ( ! composing ) {
214
+ props . onInputChange ( e ) ;
215
+ }
216
+ } ;
217
+
205
218
return ( ) => {
206
219
const {
207
220
id,
@@ -215,14 +228,13 @@ const SelectSelector = defineComponent<SelectorProps>({
215
228
autocomplete,
216
229
activeDescendantId,
217
230
tabindex,
218
- onInputChange ,
231
+ compositionStatus ,
219
232
onInputPaste,
220
233
onInputKeyDown,
221
234
onInputMouseDown,
222
235
onInputCompositionStart,
223
236
onInputCompositionEnd,
224
237
} = props ;
225
-
226
238
// >>> Input Node
227
239
const inputNode = (
228
240
< div
@@ -241,10 +253,10 @@ const SelectSelector = defineComponent<SelectorProps>({
241
253
autocomplete = { autocomplete }
242
254
editable = { inputEditable . value }
243
255
activeDescendantId = { activeDescendantId }
244
- value = { inputValue . value }
256
+ value = { targetValue . value }
245
257
onKeydown = { onInputKeyDown }
246
258
onMousedown = { onInputMouseDown }
247
- onChange = { onInputChange }
259
+ onChange = { handleInput }
248
260
onPaste = { onInputPaste }
249
261
onCompositionstart = { onInputCompositionStart }
250
262
onCompositionend = { onInputCompositionEnd }
@@ -256,7 +268,7 @@ const SelectSelector = defineComponent<SelectorProps>({
256
268
257
269
{ /* Measure Node */ }
258
270
< span ref = { measureRef } class = { `${ selectionPrefixCls . value } -search-mirror` } aria-hidden >
259
- { inputValue . value }
271
+ { targetValue . value }
260
272
</ span >
261
273
</ div >
262
274
) ;
@@ -277,7 +289,7 @@ const SelectSelector = defineComponent<SelectorProps>({
277
289
return (
278
290
< >
279
291
{ selectionNode }
280
- { ! values . length && ! inputValue . value && (
292
+ { ! values . length && ! inputValue . value && ! compositionStatus && (
281
293
< span class = { `${ selectionPrefixCls . value } -placeholder` } > { placeholder } </ span >
282
294
) }
283
295
</ >
0 commit comments