@@ -40,6 +40,7 @@ const Select = ({
40
40
noOptionsMessage,
41
41
value,
42
42
onChange,
43
+ loadOptionsChangeCounter,
43
44
...props
44
45
} ) => {
45
46
const [ state , dispatch ] = useReducer ( reducer , {
@@ -53,12 +54,12 @@ const Select = ({
53
54
dispatch ( { type : 'startLoading' } ) ;
54
55
55
56
return loadOptions ( ) . then ( ( data ) => {
56
- if ( Array . isArray ( value ) ) {
57
+ if ( value && Array . isArray ( value ) ) {
57
58
const selectValue = value . filter ( ( value ) =>
58
59
typeof value === 'object' ? data . find ( ( option ) => value . value === option . value ) : data . find ( ( option ) => value === option . value )
59
60
) ;
60
61
onChange ( selectValue . length === 0 ? undefined : selectValue ) ;
61
- } else if ( ! data . find ( ( { value : internalValue } ) => internalValue === value ) ) {
62
+ } else if ( value && ! data . find ( ( { value : internalValue } ) => internalValue === value ) ) {
62
63
onChange ( undefined ) ;
63
64
}
64
65
@@ -84,11 +85,11 @@ const Select = ({
84
85
if ( loadOptionsStr && state . isMounted ) {
85
86
updateOptions ( ) ;
86
87
}
87
- } , [ loadOptionsStr ] ) ;
88
+ } , [ loadOptionsStr , loadOptionsChangeCounter ] ) ;
88
89
89
90
useEffect ( ( ) => {
90
91
if ( state . isMounted ) {
91
- if ( ! propsOptions . map ( ( { value } ) => value ) . includes ( value ) ) {
92
+ if ( value && ! propsOptions . map ( ( { value } ) => value ) . includes ( value ) ) {
92
93
onChange ( undefined ) ;
93
94
}
94
95
@@ -97,11 +98,20 @@ const Select = ({
97
98
} , [ propsOptions ] ) ;
98
99
99
100
if ( state . isLoading ) {
100
- return < ReactSelect isDisabled = { true } placeholder = { loadingMessage } options = { state . options } { ...loadingProps } /> ;
101
+ return (
102
+ < ReactSelect
103
+ { ...props }
104
+ classNamePrefix = { classNamePrefix }
105
+ isDisabled = { true }
106
+ placeholder = { loadingMessage }
107
+ options = { state . options }
108
+ { ...loadingProps }
109
+ />
110
+ ) ;
101
111
}
102
112
103
113
const onInputChange = ( inputValue ) => {
104
- if ( loadOptions && state . promises [ inputValue ] === undefined ) {
114
+ if ( inputValue && loadOptions && state . promises [ inputValue ] === undefined && props . isSearchable ) {
105
115
dispatch ( { type : 'setPromises' , payload : { [ inputValue ] : true } } ) ;
106
116
107
117
loadOptions ( inputValue )
@@ -133,6 +143,7 @@ const Select = ({
133
143
'has-error' : invalid
134
144
} ) }
135
145
{ ...props }
146
+ isDisabled = { props . isDisabled || props . isReadOnly }
136
147
options = { state . options }
137
148
classNamePrefix = { classNamePrefix }
138
149
isMulti = { isMulti }
@@ -157,6 +168,7 @@ Select.propTypes = {
157
168
pluckSingleValue : PropTypes . bool ,
158
169
value : PropTypes . any ,
159
170
placeholder : PropTypes . string ,
171
+ loadOptionsChangeCounter : PropTypes . number ,
160
172
...input
161
173
} ;
162
174
0 commit comments