@@ -114,6 +114,7 @@ class Select extends Component {
114
114
// inputValue = value.length ? String(value[0].value) : '';
115
115
// }
116
116
this . saveInputRef = saveRef . bind ( this , 'inputInstance' ) ;
117
+ this . saveInputMirrorRef = saveRef . bind ( this , 'inputMirrorInstance' ) ;
117
118
this . state = {
118
119
value,
119
120
inputValue,
@@ -123,11 +124,13 @@ class Select extends Component {
123
124
}
124
125
125
126
componentDidMount ( ) {
126
- if ( this . state . inputValue ) {
127
+ if ( isMultipleOrTags ( this . props ) ) {
127
128
const inputNode = this . getInputDOMNode ( ) ;
128
- if ( inputNode && inputNode . value ) {
129
+ if ( inputNode . value ) {
130
+ inputNode . style . width = '' ;
131
+ inputNode . style . width = `${ this . inputMirrorInstance . clientWidth } px` ;
132
+ } else {
129
133
inputNode . style . width = '' ;
130
- inputNode . style . width = `${ inputNode . scrollWidth } px` ;
131
134
}
132
135
}
133
136
}
@@ -189,7 +192,7 @@ class Select extends Component {
189
192
const inputNode = this . getInputDOMNode ( ) ;
190
193
if ( inputNode . value ) {
191
194
inputNode . style . width = '' ;
192
- inputNode . style . width = `${ inputNode . scrollWidth } px` ;
195
+ inputNode . style . width = `${ this . inputMirrorInstance . clientWidth } px` ;
193
196
} else {
194
197
inputNode . style . width = '' ;
195
198
}
@@ -441,17 +444,31 @@ class Select extends Component {
441
444
442
445
getInputElement ( ) {
443
446
const { inputValue } = this . state ;
447
+ const { prefixCls, disabled } = this . props ;
444
448
return (
445
- < span className = { `${ this . props . prefixCls } -search__field__wrap` } >
449
+ < span className = { `${ prefixCls } -search__field__wrap` } >
446
450
< input
447
451
ref = { this . saveInputRef }
448
452
onChange = { this . onInputChange }
449
453
onKeyDown = { this . onInputKeyDown }
450
454
value = { inputValue }
451
- disabled = { this . props . disabled }
452
- className = { `${ this . props . prefixCls } -search__field` }
455
+ disabled = { disabled }
456
+ className = { `${ prefixCls } -search__field` }
453
457
role = "textbox"
454
458
/>
459
+ < span
460
+ ref = { this . saveInputMirrorRef }
461
+ className = { `${ prefixCls } -search__field__mirror` }
462
+ style = { {
463
+ position : 'absolute' ,
464
+ top : '0' ,
465
+ left : '-9999px' ,
466
+ whiteSpace : 'pre' ,
467
+ pointerEvents : 'none' ,
468
+ } }
469
+ >
470
+ { inputValue }
471
+ </ span >
455
472
{ isMultipleOrTags ( this . props ) ? null : this . getSearchPlaceholderElement ( ! ! inputValue ) }
456
473
</ span >
457
474
) ;
0 commit comments