@@ -56,6 +56,7 @@ import type { FlattenOptionData } from './interface';
56
56
import { hasValue , isComboNoValue , toArray } from './utils/commonUtil' ;
57
57
import { fillFieldNames , flattenOptions , injectPropsWithOption } from './utils/valueUtil' ;
58
58
import warningProps , { warningNullOptions } from './utils/warningPropsUtil' ;
59
+ import useSearchConfig from './hooks/useSearchConfig' ;
59
60
60
61
const OMIT_DOM_PROPS = [ 'inputValue' ] ;
61
62
@@ -110,7 +111,7 @@ type ArrayElementType<T> = T extends (infer E)[] ? E : T;
110
111
111
112
export type SemanticName = BaseSelectSemanticName ;
112
113
export type PopupSemantic = 'listItem' | 'list' ;
113
- interface SearchConfig < OptionType > {
114
+ export interface SearchConfig < OptionType > {
114
115
searchValue ?: string ;
115
116
autoClearSearchValue ?: boolean ;
116
117
onSearch ?: ( value : string ) => void ;
@@ -222,21 +223,22 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
222
223
...restProps
223
224
} = props ;
224
225
225
- const legacySearchProps = [
226
- 'filterOption' ,
227
- 'searchValue' ,
228
- 'optionFilterProp' ,
229
- 'optionLabelProp' ,
230
- 'filterSort' ,
231
- 'onSearch' ,
232
- 'autoClearSearchValue' ,
233
- 'tokenSeparators' ,
234
- ] ;
235
- const legacyShowSearch : SearchConfig < DefaultOptionType > = { } ;
236
- legacySearchProps . forEach ( ( propsName ) => {
237
- legacyShowSearch [ propsName ] = props ?. [ propsName ] ;
238
- } ) ;
239
- const mergedShowSearch = typeof showSearch === 'object' ? showSearch : legacyShowSearch ;
226
+ // const legacySearchProps = [
227
+ // 'filterOption',
228
+ // 'searchValue',
229
+ // 'optionFilterProp',
230
+ // 'optionLabelProp',
231
+ // 'filterSort',
232
+ // 'onSearch',
233
+ // 'autoClearSearchValue',
234
+ // 'tokenSeparators',
235
+ // ];
236
+ // const legacyShowSearch: SearchConfig<DefaultOptionType> = {};
237
+ // legacySearchProps.forEach((propsName) => {
238
+ // legacyShowSearch[propsName] = props?.[propsName];
239
+ // });
240
+ const [ mergedShowSearch , searchConfig ] = useSearchConfig ( showSearch , props ) ;
241
+ // const mergedShowSearch = typeof showSearch === 'object' ? showSearch : legacyShowSearch;
240
242
const {
241
243
filterOption,
242
244
searchValue,
@@ -246,7 +248,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
246
248
onSearch,
247
249
autoClearSearchValue = true ,
248
250
tokenSeparators,
249
- } = mergedShowSearch ;
251
+ } = searchConfig ;
250
252
251
253
const mergedId = useId ( id ) ;
252
254
const multiple = isMultiple ( mode ) ;
@@ -719,7 +721,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
719
721
// >>> Trigger
720
722
direction = { direction }
721
723
// >>> Search
722
- showSearch = { showSearch === undefined ? undefined : ! ! showSearch }
724
+ showSearch = { mergedShowSearch }
723
725
searchValue = { mergedSearchValue }
724
726
onSearch = { onInternalSearch }
725
727
autoClearSearchValue = { autoClearSearchValue }
0 commit comments