@@ -40,6 +40,7 @@ const Select = ({
4040 noOptionsMessage,
4141 value,
4242 onChange,
43+ loadOptionsChangeCounter,
4344 ...props
4445} ) => {
4546 const [ state , dispatch ] = useReducer ( reducer , {
@@ -53,12 +54,12 @@ const Select = ({
5354 dispatch ( { type : 'startLoading' } ) ;
5455
5556 return loadOptions ( ) . then ( ( data ) => {
56- if ( Array . isArray ( value ) ) {
57+ if ( value && Array . isArray ( value ) ) {
5758 const selectValue = value . filter ( ( value ) =>
5859 typeof value === 'object' ? data . find ( ( option ) => value . value === option . value ) : data . find ( ( option ) => value === option . value )
5960 ) ;
6061 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 ) ) {
6263 onChange ( undefined ) ;
6364 }
6465
@@ -84,11 +85,11 @@ const Select = ({
8485 if ( loadOptionsStr && state . isMounted ) {
8586 updateOptions ( ) ;
8687 }
87- } , [ loadOptionsStr ] ) ;
88+ } , [ loadOptionsStr , loadOptionsChangeCounter ] ) ;
8889
8990 useEffect ( ( ) => {
9091 if ( state . isMounted ) {
91- if ( ! propsOptions . map ( ( { value } ) => value ) . includes ( value ) ) {
92+ if ( value && ! propsOptions . map ( ( { value } ) => value ) . includes ( value ) ) {
9293 onChange ( undefined ) ;
9394 }
9495
@@ -97,11 +98,20 @@ const Select = ({
9798 } , [ propsOptions ] ) ;
9899
99100 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+ ) ;
101111 }
102112
103113 const onInputChange = ( inputValue ) => {
104- if ( loadOptions && state . promises [ inputValue ] === undefined ) {
114+ if ( inputValue && loadOptions && state . promises [ inputValue ] === undefined && props . isSearchable ) {
105115 dispatch ( { type : 'setPromises' , payload : { [ inputValue ] : true } } ) ;
106116
107117 loadOptions ( inputValue )
@@ -133,6 +143,7 @@ const Select = ({
133143 'has-error' : invalid
134144 } ) }
135145 { ...props }
146+ isDisabled = { props . isDisabled || props . isReadOnly }
136147 options = { state . options }
137148 classNamePrefix = { classNamePrefix }
138149 isMulti = { isMulti }
@@ -157,6 +168,7 @@ Select.propTypes = {
157168 pluckSingleValue : PropTypes . bool ,
158169 value : PropTypes . any ,
159170 placeholder : PropTypes . string ,
171+ loadOptionsChangeCounter : PropTypes . number ,
160172 ...input
161173} ;
162174
0 commit comments