@@ -2,11 +2,7 @@ import React from 'react';
2
2
import classNames from 'classnames' ;
3
3
import CSSMotionList from 'rc-animate/lib/CSSMotionList' ;
4
4
import TransBtn from '../TransBtn' ;
5
- import {
6
- LabelValueType ,
7
- RawValueType ,
8
- CustomTagProps ,
9
- } from '../interface/generator' ;
5
+ import { LabelValueType , RawValueType , CustomTagProps } from '../interface/generator' ;
10
6
import { RenderNode } from '../interface' ;
11
7
import { InnerSelectorProps } from '.' ;
12
8
import Input from './Input' ;
@@ -21,9 +17,7 @@ interface SelectorProps extends InnerSelectorProps {
21
17
// Tags
22
18
maxTagCount ?: number ;
23
19
maxTagTextLength ?: number ;
24
- maxTagPlaceholder ?:
25
- | React . ReactNode
26
- | ( ( omittedValues : LabelValueType [ ] ) => React . ReactNode ) ;
20
+ maxTagPlaceholder ?: React . ReactNode | ( ( omittedValues : LabelValueType [ ] ) => React . ReactNode ) ;
27
21
tokenSeparators ?: string [ ] ;
28
22
tagRender ?: ( props : CustomTagProps ) => React . ReactElement ;
29
23
@@ -55,8 +49,7 @@ const SelectSelector: React.FC<SelectorProps> = ({
55
49
56
50
maxTagCount,
57
51
maxTagTextLength,
58
- maxTagPlaceholder = ( omittedValues : LabelValueType [ ] ) =>
59
- `+ ${ omittedValues . length } ...` ,
52
+ maxTagPlaceholder = ( omittedValues : LabelValueType [ ] ) => `+ ${ omittedValues . length } ...` ,
60
53
tagRender,
61
54
62
55
onSelect,
@@ -74,12 +67,13 @@ const SelectSelector: React.FC<SelectorProps> = ({
74
67
} , [ ] ) ;
75
68
76
69
// ===================== Search ======================
70
+ const inputValue = open ? searchValue : '' ;
77
71
const inputEditable : boolean = mode === 'tags' || ( open && showSearch ) ;
78
72
79
73
// We measure width and set to the input immediately
80
74
useLayoutEffect ( ( ) => {
81
75
setInputWidth ( measureRef . current . scrollWidth ) ;
82
- } , [ searchValue ] ) ;
76
+ } , [ inputValue ] ) ;
83
77
84
78
// ==================== Selection ====================
85
79
let displayValues : LabelValueType [ ] = values ;
@@ -142,12 +136,7 @@ const SelectSelector: React.FC<SelectorProps> = ({
142
136
} ;
143
137
144
138
return typeof tagRender === 'function' ? (
145
- < span
146
- key = { mergedKey }
147
- onMouseDown = { onMouseDown }
148
- className = { className }
149
- style = { style }
150
- >
139
+ < span key = { mergedKey } onMouseDown = { onMouseDown } className = { className } style = { style } >
151
140
{ tagRender ( {
152
141
label,
153
142
value,
@@ -164,9 +153,7 @@ const SelectSelector: React.FC<SelectorProps> = ({
164
153
} ) }
165
154
style = { style }
166
155
>
167
- < span className = { `${ prefixCls } -selection-item-content` } >
168
- { label }
169
- </ span >
156
+ < span className = { `${ prefixCls } -selection-item-content` } > { label } </ span >
170
157
{ closable && (
171
158
< TransBtn
172
159
className = { `${ prefixCls } -selection-item-remove` }
@@ -187,10 +174,7 @@ const SelectSelector: React.FC<SelectorProps> = ({
187
174
< >
188
175
{ selectionNode }
189
176
190
- < span
191
- className = { `${ prefixCls } -selection-search` }
192
- style = { { width : inputWidth } }
193
- >
177
+ < span className = { `${ prefixCls } -selection-search` } style = { { width : inputWidth } } >
194
178
< Input
195
179
ref = { inputRef }
196
180
open = { open }
@@ -201,27 +185,21 @@ const SelectSelector: React.FC<SelectorProps> = ({
201
185
autoFocus = { autoFocus }
202
186
editable = { inputEditable }
203
187
accessibilityIndex = { accessibilityIndex }
204
- value = { searchValue }
188
+ value = { inputValue }
205
189
onKeyDown = { onInputKeyDown }
206
190
onMouseDown = { onInputMouseDown }
207
191
onChange = { onInputChange }
208
192
tabIndex = { tabIndex }
209
193
/>
210
194
211
195
{ /* Measure Node */ }
212
- < span
213
- ref = { measureRef }
214
- className = { `${ prefixCls } -selection-search-mirror` }
215
- aria-hidden
216
- >
217
- { searchValue }
196
+ < span ref = { measureRef } className = { `${ prefixCls } -selection-search-mirror` } aria-hidden >
197
+ { inputValue }
218
198
</ span >
219
199
</ span >
220
200
221
- { ! values . length && ! searchValue && (
222
- < span className = { `${ prefixCls } -selection-placeholder` } >
223
- { placeholder }
224
- </ span >
201
+ { ! values . length && ! inputValue && (
202
+ < span className = { `${ prefixCls } -selection-placeholder` } > { placeholder } </ span >
225
203
) }
226
204
</ >
227
205
) ;
0 commit comments