@@ -12,11 +12,7 @@ import * as React from 'react';
12
12
import KeyCode from 'rc-util/lib/KeyCode' ;
13
13
import MultipleSelector from './MultipleSelector' ;
14
14
import SingleSelector from './SingleSelector' ;
15
- import {
16
- LabelValueType ,
17
- RawValueType ,
18
- CustomTagProps ,
19
- } from '../interface/generator' ;
15
+ import { LabelValueType , RawValueType , CustomTagProps } from '../interface/generator' ;
20
16
import { RenderNode , Mode } from '../interface' ;
21
17
import useLock from '../hooks/useLock' ;
22
18
@@ -36,15 +32,9 @@ export interface InnerSelectorProps {
36
32
open : boolean ;
37
33
tabIndex ?: number ;
38
34
39
- onInputKeyDown : React . KeyboardEventHandler <
40
- HTMLInputElement | HTMLTextAreaElement
41
- > ;
42
- onInputMouseDown : React . MouseEventHandler <
43
- HTMLInputElement | HTMLTextAreaElement
44
- > ;
45
- onInputChange : React . ChangeEventHandler <
46
- HTMLInputElement | HTMLTextAreaElement
47
- > ;
35
+ onInputKeyDown : React . KeyboardEventHandler < HTMLInputElement | HTMLTextAreaElement > ;
36
+ onInputMouseDown : React . MouseEventHandler < HTMLInputElement | HTMLTextAreaElement > ;
37
+ onInputChange : React . ChangeEventHandler < HTMLInputElement | HTMLTextAreaElement > ;
48
38
}
49
39
50
40
export interface RefSelectorProps {
@@ -75,9 +65,7 @@ export interface SelectorProps {
75
65
// Tags
76
66
maxTagCount ?: number ;
77
67
maxTagTextLength ?: number ;
78
- maxTagPlaceholder ?:
79
- | React . ReactNode
80
- | ( ( omittedValues : LabelValueType [ ] ) => React . ReactNode ) ;
68
+ maxTagPlaceholder ?: React . ReactNode | ( ( omittedValues : LabelValueType [ ] ) => React . ReactNode ) ;
81
69
tagRender ?: ( props : CustomTagProps ) => React . ReactElement ;
82
70
83
71
// Motion
@@ -87,9 +75,7 @@ export interface SelectorProps {
87
75
/** `onSearch` returns go next step boolean to check if need do toggle open */
88
76
onSearch : ( searchValue : string ) => boolean ;
89
77
onSelect : ( value : RawValueType , option : { selected : boolean } ) => void ;
90
- onInputKeyDown ?: React . KeyboardEventHandler <
91
- HTMLInputElement | HTMLTextAreaElement
92
- > ;
78
+ onInputKeyDown ?: React . KeyboardEventHandler < HTMLInputElement | HTMLTextAreaElement > ;
93
79
94
80
/**
95
81
* @private get real dom for trigger align.
@@ -98,17 +84,15 @@ export interface SelectorProps {
98
84
domRef : React . Ref < HTMLDivElement > ;
99
85
}
100
86
101
- const Selector : React . RefForwardingComponent <
102
- RefSelectorProps ,
103
- SelectorProps
104
- > = ( props , ref ) => {
87
+ const Selector : React . RefForwardingComponent < RefSelectorProps , SelectorProps > = ( props , ref ) => {
105
88
const inputRef = React . useRef < HTMLInputElement > ( null ) ;
106
89
107
90
const {
108
91
prefixCls,
109
92
multiple,
110
93
open,
111
94
mode,
95
+ showSearch,
112
96
113
97
onSearch,
114
98
onToggleOpen,
@@ -130,9 +114,7 @@ const Selector: React.RefForwardingComponent<
130
114
// ====================== Input ======================
131
115
const [ getInputMouseDown , setInputMouseDown ] = useLock ( 0 ) ;
132
116
133
- const onInternalInputKeyDown : React . KeyboardEventHandler <
134
- HTMLInputElement
135
- > = event => {
117
+ const onInternalInputKeyDown : React . KeyboardEventHandler < HTMLInputElement > = event => {
136
118
const { which } = event ;
137
119
138
120
if ( which === KeyCode . UP || which === KeyCode . DOWN ) {
@@ -143,11 +125,7 @@ const Selector: React.RefForwardingComponent<
143
125
onInputKeyDown ( event ) ;
144
126
}
145
127
146
- if (
147
- ! [ KeyCode . SHIFT , KeyCode . TAB , KeyCode . BACKSPACE , KeyCode . ESC ] . includes (
148
- which ,
149
- )
150
- ) {
128
+ if ( ! [ KeyCode . SHIFT , KeyCode . TAB , KeyCode . BACKSPACE , KeyCode . ESC ] . includes ( which ) ) {
151
129
onToggleOpen ( true ) ;
152
130
}
153
131
} ;
@@ -156,9 +134,7 @@ const Selector: React.RefForwardingComponent<
156
134
* We can not use `findDOMNode` sine it will get warning,
157
135
* have to use timer to check if is input element.
158
136
*/
159
- const onInternalInputMouseDown : React . MouseEventHandler <
160
- HTMLInputElement
161
- > = ( ) => {
137
+ const onInternalInputMouseDown : React . MouseEventHandler < HTMLInputElement > = ( ) => {
162
138
setInputMouseDown ( true ) ;
163
139
} ;
164
140
@@ -177,11 +153,12 @@ const Selector: React.RefForwardingComponent<
177
153
} ;
178
154
179
155
const onMouseDown : React . MouseEventHandler < HTMLElement > = event => {
180
- if ( event . target !== inputRef . current && ! getInputMouseDown ( ) ) {
156
+ const inputMouseDown = getInputMouseDown ( ) ;
157
+ if ( event . target !== inputRef . current && ! inputMouseDown ) {
181
158
event . preventDefault ( ) ;
182
159
}
183
160
184
- if ( mode !== 'combobox' || ! open ) {
161
+ if ( ( mode !== 'combobox' && ( ! showSearch || ! inputMouseDown ) ) || ! open ) {
185
162
onToggleOpen ( ) ;
186
163
}
187
164
} ;
@@ -212,9 +189,7 @@ const Selector: React.RefForwardingComponent<
212
189
) ;
213
190
} ;
214
191
215
- const ForwardSelector = React . forwardRef < RefSelectorProps , SelectorProps > (
216
- Selector ,
217
- ) ;
192
+ const ForwardSelector = React . forwardRef < RefSelectorProps , SelectorProps > ( Selector ) ;
218
193
ForwardSelector . displayName = 'Selector' ;
219
194
220
195
export default ForwardSelector ;
0 commit comments