@@ -110,16 +110,26 @@ type ArrayElementType<T> = T extends (infer E)[] ? E : T;
110
110
111
111
export type SemanticName = BaseSelectSemanticName ;
112
112
export type PopupSemantic = 'listItem' | 'list' ;
113
+ interface ShowSearch < OptionType > {
114
+ searchValue ?: string ;
115
+ autoClearSearchValue ?: boolean ;
116
+ onSearch ?: ( value : string ) => void ;
117
+ tokenSeparators ?: string | string [ ] ;
118
+ filterOption ?: boolean | FilterFunc < OptionType > ;
119
+ filterSort ?: ( optionA : OptionType , optionB : OptionType , info : { searchValue : string } ) => number ;
120
+ optionFilterProp ?: string ;
121
+ optionLabelProp ?: string ;
122
+ }
113
123
export interface SelectProps < ValueType = any , OptionType extends BaseOptionType = DefaultOptionType >
114
- extends BaseSelectPropsWithoutPrivate {
124
+ extends Omit < BaseSelectPropsWithoutPrivate , 'showSearch' > {
115
125
prefixCls ?: string ;
116
126
id ?: string ;
117
127
118
128
backfill ?: boolean ;
119
129
120
130
// >>> Field Names
121
131
fieldNames ?: FieldNames ;
122
-
132
+ showSearch ?: boolean | ShowSearch < OptionType > ;
123
133
searchValue ?: string ;
124
134
onSearch ?: ( value : string ) => void ;
125
135
autoClearSearchValue ?: boolean ;
@@ -176,22 +186,12 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
176
186
prefixCls = 'rc-select' ,
177
187
backfill,
178
188
fieldNames,
179
-
180
189
// Search
181
- searchValue,
182
- onSearch,
183
- autoClearSearchValue = true ,
184
-
190
+ showSearch,
185
191
// Select
186
192
onSelect,
187
193
onDeselect,
188
194
popupMatchSelectWidth = true ,
189
-
190
- // Options
191
- filterOption,
192
- filterSort,
193
- optionFilterProp,
194
- optionLabelProp,
195
195
options,
196
196
optionRender,
197
197
children,
@@ -214,6 +214,31 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
214
214
...restProps
215
215
} = props ;
216
216
217
+ const legacySearchProps = [
218
+ 'filterOption' ,
219
+ 'searchValue' ,
220
+ 'optionFilterProp' ,
221
+ 'optionLabelProp' ,
222
+ 'filterSort' ,
223
+ 'onSearch' ,
224
+ 'autoClearSearchValue' ,
225
+ 'tokenSeparators' ,
226
+ ] ;
227
+ const legacyShowSearch : ShowSearch < DefaultOptionType > = { } ;
228
+ legacySearchProps . forEach ( ( propsName ) => {
229
+ legacyShowSearch [ propsName ] = restProps ?. [ propsName ] ;
230
+ } ) ;
231
+ const mergedShowSearch = typeof showSearch === 'object' ? showSearch : legacyShowSearch ;
232
+ const {
233
+ filterOption,
234
+ searchValue,
235
+ optionFilterProp,
236
+ optionLabelProp,
237
+ filterSort,
238
+ onSearch,
239
+ autoClearSearchValue,
240
+ } = mergedShowSearch ;
241
+
217
242
const mergedId = useId ( id ) ;
218
243
const multiple = isMultiple ( mode ) ;
219
244
const childrenAsData = ! ! ( ! options && children ) ;
@@ -685,6 +710,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
685
710
// >>> Trigger
686
711
direction = { direction }
687
712
// >>> Search
713
+ showSearch = { showSearch === undefined ? undefined : ! ! showSearch }
688
714
searchValue = { mergedSearchValue }
689
715
onSearch = { onInternalSearch }
690
716
autoClearSearchValue = { autoClearSearchValue }
0 commit comments