@@ -14,6 +14,7 @@ import MultipleSelector from './MultipleSelector';
14
14
import SingleSelector from './SingleSelector' ;
15
15
import { LabelValueType , RawValueType } from '../interface/generator' ;
16
16
import { RenderNode , Mode } from '../interface' ;
17
+ import useLock from '../hooks/useLock' ;
17
18
18
19
export interface InnerSelectorProps {
19
20
prefixCls : string ;
@@ -32,6 +33,7 @@ export interface InnerSelectorProps {
32
33
tabIndex ?: number ;
33
34
34
35
onInputKeyDown : React . KeyboardEventHandler < HTMLInputElement | HTMLTextAreaElement > ;
36
+ onInputMouseDown : React . MouseEventHandler < HTMLInputElement | HTMLTextAreaElement > ;
35
37
onInputChange : React . ChangeEventHandler < HTMLInputElement | HTMLTextAreaElement > ;
36
38
}
37
39
@@ -98,6 +100,8 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
98
100
} ) ) ;
99
101
100
102
// ====================== Input ======================
103
+ const [ getInputMouseDown , setInputMouseDown ] = useLock ( 0 ) ;
104
+
101
105
const onInternalInputKeyDown : React . KeyboardEventHandler < HTMLInputElement > = event => {
102
106
const { which } = event ;
103
107
@@ -114,6 +118,14 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
114
118
}
115
119
} ;
116
120
121
+ /**
122
+ * We can not use `findDOMNode` sine it will get warning,
123
+ * have to use timer to check if is input element.
124
+ */
125
+ const onInternalInputMouseDown : React . MouseEventHandler < HTMLInputElement > = event => {
126
+ setInputMouseDown ( true ) ;
127
+ } ;
128
+
117
129
const onInputChange = ( { target : { value } } ) => {
118
130
if ( onSearch ( value ) !== false ) {
119
131
onToggleOpen ( true ) ;
@@ -129,7 +141,7 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
129
141
} ;
130
142
131
143
const onMouseDown : React . MouseEventHandler < HTMLElement > = event => {
132
- if ( event . target !== inputRef . current ) {
144
+ if ( event . target !== inputRef . current && ! getInputMouseDown ( ) ) {
133
145
event . preventDefault ( ) ;
134
146
}
135
147
@@ -140,6 +152,7 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
140
152
const sharedProps = {
141
153
inputRef,
142
154
onInputKeyDown : onInternalInputKeyDown ,
155
+ onInputMouseDown : onInternalInputMouseDown ,
143
156
onInputChange,
144
157
} ;
145
158
0 commit comments