@@ -106,17 +106,26 @@ export type SelectHandler<ValueType, OptionType extends BaseOptionType = Default
106
106
) => void ;
107
107
108
108
type ArrayElementType < T > = T extends ( infer E ) [ ] ? E : T ;
109
-
109
+ interface ShowSearch < OptionType > {
110
+ searchValue ?: string ;
111
+ autoClearSearchValue ?: boolean ;
112
+ onSearch ?: ( value : string ) => void ;
113
+ tokenSeparators ?: string | string [ ] ;
114
+ filterOption ?: boolean | FilterFunc < OptionType > ;
115
+ filterSort ?: ( optionA : OptionType , optionB : OptionType , info : { searchValue : string } ) => number ;
116
+ optionFilterProp ?: string ;
117
+ optionLabelProp ?: string ;
118
+ }
110
119
export interface SelectProps < ValueType = any , OptionType extends BaseOptionType = DefaultOptionType >
111
- extends BaseSelectPropsWithoutPrivate {
120
+ extends Omit < BaseSelectPropsWithoutPrivate , 'showSearch' > {
112
121
prefixCls ?: string ;
113
122
id ?: string ;
114
123
115
124
backfill ?: boolean ;
116
125
117
126
// >>> Field Names
118
127
fieldNames ?: FieldNames ;
119
-
128
+ showSearch ?: boolean | ShowSearch < OptionType > ;
120
129
searchValue ?: string ;
121
130
onSearch ?: ( value : string ) => void ;
122
131
autoClearSearchValue ?: boolean ;
@@ -171,22 +180,12 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
171
180
prefixCls = 'rc-select' ,
172
181
backfill,
173
182
fieldNames,
174
-
175
183
// Search
176
- searchValue,
177
- onSearch,
178
- autoClearSearchValue = true ,
179
-
184
+ showSearch,
180
185
// Select
181
186
onSelect,
182
187
onDeselect,
183
188
popupMatchSelectWidth = true ,
184
-
185
- // Options
186
- filterOption,
187
- filterSort,
188
- optionFilterProp,
189
- optionLabelProp,
190
189
options,
191
190
optionRender,
192
191
children,
@@ -208,6 +207,31 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
208
207
...restProps
209
208
} = props ;
210
209
210
+ const legacySearchProps = [
211
+ 'filterOption' ,
212
+ 'searchValue' ,
213
+ 'optionFilterProp' ,
214
+ 'optionLabelProp' ,
215
+ 'filterSort' ,
216
+ 'onSearch' ,
217
+ 'autoClearSearchValue' ,
218
+ 'tokenSeparators' ,
219
+ ] ;
220
+ const legacyShowSearch : ShowSearch < DefaultOptionType > = { } ;
221
+ legacySearchProps . forEach ( ( propsName ) => {
222
+ legacyShowSearch [ propsName ] = restProps ?. [ propsName ] ;
223
+ } ) ;
224
+ const mergedShowSearch = typeof showSearch === 'object' ? showSearch : legacyShowSearch ;
225
+ const {
226
+ filterOption,
227
+ searchValue,
228
+ optionFilterProp,
229
+ optionLabelProp,
230
+ filterSort,
231
+ onSearch,
232
+ autoClearSearchValue,
233
+ } = mergedShowSearch ;
234
+
211
235
const mergedId = useId ( id ) ;
212
236
const multiple = isMultiple ( mode ) ;
213
237
const childrenAsData = ! ! ( ! options && children ) ;
@@ -671,6 +695,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
671
695
// >>> Trigger
672
696
direction = { direction }
673
697
// >>> Search
698
+ showSearch = { showSearch === undefined ? undefined : ! ! showSearch }
674
699
searchValue = { mergedSearchValue }
675
700
onSearch = { onInternalSearch }
676
701
autoClearSearchValue = { autoClearSearchValue }
0 commit comments