@@ -8,7 +8,7 @@ import type {
8
8
} from '../Select' ;
9
9
import { injectPropsWithOption } from '../utils/valueUtil' ;
10
10
import type { Ref } from 'vue' ;
11
- import { computed } from 'vue' ;
11
+ import { toRaw , computed } from 'vue' ;
12
12
13
13
function includes ( test : any , search : string ) {
14
14
return toArray ( test ) . join ( '' ) . toUpperCase ( ) . includes ( search ) ;
@@ -22,22 +22,24 @@ export default (
22
22
optionFilterProp ?: Ref < string > ,
23
23
) =>
24
24
computed ( ( ) => {
25
- if ( ! searchValue . value || filterOption . value === false ) {
25
+ const searchValueVal = searchValue . value ;
26
+ const optionFilterPropValue = optionFilterProp ?. value ;
27
+ const filterOptionValue = filterOption ?. value ;
28
+ if ( ! searchValueVal || filterOptionValue === false ) {
26
29
return options . value ;
27
30
}
28
-
29
31
const { options : fieldOptions , label : fieldLabel , value : fieldValue } = fieldNames . value ;
30
32
const filteredOptions : DefaultOptionType [ ] = [ ] ;
31
33
32
- const customizeFilter = typeof filterOption . value === 'function' ;
34
+ const customizeFilter = typeof filterOptionValue === 'function' ;
33
35
34
- const upperSearch = searchValue . value . toUpperCase ( ) ;
36
+ const upperSearch = searchValueVal . toUpperCase ( ) ;
35
37
const filterFunc = customizeFilter
36
- ? ( filterOption . value as FilterFunc < BaseOptionType > )
38
+ ? ( filterOptionValue as FilterFunc < BaseOptionType > )
37
39
: ( _ : string , option : DefaultOptionType ) => {
38
40
// Use provided `optionFilterProp`
39
- if ( optionFilterProp . value ) {
40
- return includes ( option [ optionFilterProp . value ] , upperSearch ) ;
41
+ if ( optionFilterPropValue ) {
42
+ return includes ( option [ optionFilterPropValue ] , upperSearch ) ;
41
43
}
42
44
43
45
// Auto select `label` or `value` by option type
@@ -53,17 +55,17 @@ export default (
53
55
? opt => injectPropsWithOption ( opt )
54
56
: opt => opt ;
55
57
56
- options . value . forEach ( item => {
58
+ toRaw ( options . value ) . forEach ( item => {
57
59
// Group should check child options
58
60
if ( item [ fieldOptions ] ) {
59
61
// Check group first
60
- const matchGroup = filterFunc ( searchValue . value , wrapOption ( item ) ) ;
62
+ const matchGroup = filterFunc ( searchValueVal , wrapOption ( item ) ) ;
61
63
if ( matchGroup ) {
62
64
filteredOptions . push ( item ) ;
63
65
} else {
64
66
// Check option
65
67
const subOptions = item [ fieldOptions ] . filter ( ( subItem : DefaultOptionType ) =>
66
- filterFunc ( searchValue . value , wrapOption ( subItem ) ) ,
68
+ filterFunc ( searchValueVal , wrapOption ( subItem ) ) ,
67
69
) ;
68
70
if ( subOptions . length ) {
69
71
filteredOptions . push ( {
@@ -76,10 +78,9 @@ export default (
76
78
return ;
77
79
}
78
80
79
- if ( filterFunc ( searchValue . value , wrapOption ( item ) ) ) {
81
+ if ( filterFunc ( searchValueVal , wrapOption ( item ) ) ) {
80
82
filteredOptions . push ( item ) ;
81
83
}
82
84
} ) ;
83
-
84
85
return filteredOptions ;
85
86
} ) ;
0 commit comments