1
1
import * as React from 'react' ;
2
+ import { useState } from 'react' ;
2
3
import classNames from 'classnames' ;
3
4
import pickAttrs from 'rc-util/lib/pickAttrs' ;
4
5
import { CSSMotionList } from 'rc-motion' ;
@@ -64,9 +65,10 @@ const SelectSelector: React.FC<SelectorProps> = props => {
64
65
onInputCompositionEnd,
65
66
} = props ;
66
67
67
- const [ motionAppear , setMotionAppear ] = React . useState ( false ) ;
68
+ const [ motionAppear , setMotionAppear ] = useState ( false ) ;
68
69
const measureRef = React . useRef < HTMLSpanElement > ( null ) ;
69
- const [ inputWidth , setInputWidth ] = React . useState ( 0 ) ;
70
+ const [ inputWidth , setInputWidth ] = useState ( 0 ) ;
71
+ const [ focused , setFocused ] = useState ( false ) ;
70
72
71
73
// ===================== Motion ======================
72
74
React . useEffect ( ( ) => {
@@ -75,7 +77,7 @@ const SelectSelector: React.FC<SelectorProps> = props => {
75
77
76
78
// ===================== Search ======================
77
79
const inputValue = open || mode === 'tags' ? searchValue : '' ;
78
- const inputEditable : boolean = mode === 'tags' || ( open && showSearch ) ;
80
+ const inputEditable : boolean = mode === 'tags' || ( showSearch && ( open || focused ) ) ;
79
81
80
82
// We measure width and set to the input immediately
81
83
useLayoutEffect ( ( ) => {
@@ -181,7 +183,16 @@ const SelectSelector: React.FC<SelectorProps> = props => {
181
183
< >
182
184
{ selectionNode }
183
185
184
- < span className = { `${ prefixCls } -selection-search` } style = { { width : inputWidth } } >
186
+ < span
187
+ className = { `${ prefixCls } -selection-search` }
188
+ style = { { width : inputWidth } }
189
+ onFocus = { ( ) => {
190
+ setFocused ( true ) ;
191
+ } }
192
+ onBlur = { ( ) => {
193
+ setFocused ( false ) ;
194
+ } }
195
+ >
185
196
< Input
186
197
ref = { inputRef }
187
198
open = { open }
0 commit comments