1
- import type { SearchConfig , DefaultOptionType } from '@/Select' ;
1
+ import type { SearchConfig , DefaultOptionType , SelectProps } from '@/Select' ;
2
2
import * as React from 'react' ;
3
3
const legacySearchProps = [
4
4
'filterOption' ,
@@ -11,7 +11,7 @@ const legacySearchProps = [
11
11
// Convert `showSearch` to unique config
12
12
export default function useSearchConfig (
13
13
showSearch : boolean | SearchConfig < DefaultOptionType > | undefined ,
14
- props : any ,
14
+ props : SelectProps ,
15
15
) {
16
16
const {
17
17
filterOption,
@@ -22,19 +22,25 @@ export default function useSearchConfig(
22
22
autoClearSearchValue,
23
23
} = props || { } ;
24
24
return React . useMemo < [ boolean | undefined , SearchConfig < DefaultOptionType > ] > ( ( ) => {
25
- const legacyShowSearch : SearchConfig < DefaultOptionType > = { } ;
26
- legacySearchProps . forEach ( ( name ) => {
27
- const val = props ?. [ name ] ;
28
- if ( val !== undefined ) legacyShowSearch [ name ] = val ;
29
- } ) ;
30
- const searchConfig : SearchConfig < DefaultOptionType > =
31
- typeof showSearch === 'object' ? showSearch : legacyShowSearch ;
32
- if ( showSearch === undefined ) {
33
- return [ undefined , searchConfig ] ;
25
+ const legacyShowSearch : SearchConfig < DefaultOptionType > = {
26
+ filterOption,
27
+ searchValue,
28
+ optionFilterProp,
29
+ filterSort,
30
+ onSearch,
31
+ autoClearSearchValue,
32
+ } ;
33
+
34
+ if ( showSearch === undefined || showSearch === true ) {
35
+ return [ showSearch as undefined | boolean , legacyShowSearch ] ;
34
36
}
35
37
if ( ! showSearch ) {
36
38
return [ false , { } ] ;
37
39
}
40
+ const searchConfig = {
41
+ ...legacyShowSearch ,
42
+ ...showSearch ,
43
+ } ;
38
44
return [ true , searchConfig ] ;
39
45
} , [
40
46
showSearch ,
0 commit comments