@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
55import clsx from 'clsx' ;
66import isEqual from 'lodash/isEqual' ;
77import fnToString from '../utils/fn-to-string' ;
8- import reducer from './reducer' ;
8+ import reducer , { init } from './reducer' ;
99import useIsMounted from '../hooks/use-is-mounted' ;
1010
1111const getSelectValue = ( stateValue , simpleValue , isMulti , allOptions ) => {
@@ -16,7 +16,9 @@ const getSelectValue = (stateValue, simpleValue, isMulti, allOptions) => {
1616
1717 if ( hasSelectAll || hasSelectNone ) {
1818 enhancedValue = enhancedValue || [ ] ;
19- const optionsLength = allOptions . filter ( ( { selectAll, selectNone } ) => ! selectAll && ! selectNone ) . length ;
19+ const optionsLength = allOptions . filter (
20+ ( { selectAll, selectNone, divider, options } ) => ! selectAll && ! selectNone && ! divider && ! options
21+ ) . length ;
2022
2123 const selectedAll = optionsLength === enhancedValue . length ;
2224 const selectedNone = enhancedValue . length === 0 ;
@@ -43,7 +45,7 @@ const handleSelectChange = (option, simpleValue, isMulti, onChange, allOptions,
4345 const sanitizedOption = ! enhanceOption && isMulti ? [ ] : enhanceOption ;
4446
4547 if ( isMulti && sanitizedOption . find ( ( { selectAll } ) => selectAll ) ) {
46- return onChange ( allOptions . filter ( ( { selectAll, selectNone } ) => ! selectAll && ! selectNone ) . map ( ( { value } ) => value ) ) ;
48+ return onChange ( allOptions . filter ( ( { selectAll, selectNone, value } ) => ! selectAll && ! selectNone && value ) . map ( ( { value } ) => value ) ) ;
4749 }
4850
4951 if ( isMulti && sanitizedOption . find ( ( { selectNone } ) => selectNone ) ) {
@@ -73,14 +75,11 @@ const Select = ({
7375 loadOptionsChangeCounter,
7476 SelectComponent,
7577 noValueUpdates,
78+ optionsTransformer,
7679 ...props
7780} ) => {
78- const [ state , dispatch ] = useReducer ( reducer , {
79- isLoading : false ,
80- options : propsOptions ,
81- promises : { } ,
82- isInitialLoaded : false ,
83- } ) ;
81+ const [ state , originalDispatch ] = useReducer ( reducer , { optionsTransformer, propsOptions } , init ) ;
82+ const dispatch = ( action ) => originalDispatch ( { ...action , optionsTransformer } ) ;
8483
8584 const isMounted = useIsMounted ( ) ;
8685
@@ -145,6 +144,7 @@ const Select = ({
145144 onChange = { ( ) => { } }
146145 { ...loadingProps }
147146 noOptionsMessage = { renderNoOptionsMessage ( ) }
147+ { ...( state . originalOptions && { originalOptions : state . originalOptions } ) }
148148 />
149149 ) ;
150150 }
@@ -194,6 +194,7 @@ const Select = ({
194194 noOptionsMessage = { renderNoOptionsMessage ( ) }
195195 hideSelectedOptions = { false }
196196 closeMenuOnSelect = { ! isMulti }
197+ { ...( state . originalOptions && { originalOptions : state . originalOptions } ) }
197198 />
198199 ) ;
199200} ;
@@ -220,6 +221,7 @@ Select.propTypes = {
220221 isSearchable : PropTypes . bool ,
221222 SelectComponent : PropTypes . elementType . isRequired ,
222223 noValueUpdates : PropTypes . bool ,
224+ optionsTransformer : PropTypes . func ,
223225} ;
224226
225227Select . defaultProps = {
0 commit comments