@@ -7,53 +7,27 @@ import { meta, input } from '@data-driven-forms/common/src/prop-types-templates'
77import MUISelect from './select/integration-select' ;
88import { useFieldApi } from '@data-driven-forms/react-form-renderer' ;
99
10- const selectValue = ( option ) => option . sort ( ( a , b ) => a . label . localeCompare ( b . label , 'en' , { sensitivity : 'base' } ) ) . map ( ( item ) => item . value ) ;
11-
1210const Select = ( props ) => {
13- const {
14- input,
15- isReadOnly,
16- isDisabled,
17- placeholder,
18- isRequired,
19- label,
20- helperText,
21- validateOnMount,
22- meta,
23- options,
24- isSearchable,
25- description,
26- ...rest
27- } = useFieldApi ( props ) ;
11+ const { input, placeholder, label, helperText, validateOnMount, meta, isSearchable, description, ...rest } = useFieldApi ( props ) ;
2812 const invalid = validationError ( meta , validateOnMount ) ;
2913
3014 return (
3115 < FormFieldGrid >
3216 < MUISelect
3317 fullWidth
3418 { ...input }
35- options = { options . filter ( ( option ) => Object . prototype . hasOwnProperty . call ( option , 'value' ) && option . value !== null ) }
36- placeholder = { placeholder || 'Please choose' }
37- value = { options . filter ( ( { value } ) => ( rest . isMulti ? input . value . includes ( value ) : value === input . value ) ) }
38- isMulti = { rest . isMulti }
3919 isSearchable = { ! ! isSearchable }
4020 isClearable = { false }
41- hideSelectedOptions = { false }
42- closeMenuOnSelect = { ! rest . isMulti }
43- noOptionsMessage = { ( ) => 'No option found' }
4421 invalid = { invalid }
45- isDisabled = { isDisabled }
4622 textFieldProps = { {
4723 label,
4824 color : invalid ? 'red' : 'blue' ,
4925 InputLabelProps : {
5026 shrink : true
5127 }
5228 } }
53- onChange = { ( option ) => input . onChange ( rest . isMulti ? selectValue ( option ) : option ? option . value : undefined ) }
5429 input = { input }
5530 label = { label }
56- isRequired = { isRequired }
5731 helperText = { invalid || helperText || description }
5832 { ...rest }
5933 />
@@ -64,10 +38,7 @@ const Select = (props) => {
6438Select . propTypes = {
6539 input,
6640 meta,
67- isReadOnly : PropTypes . bool ,
68- isDisabled : PropTypes . bool ,
6941 placeholder : PropTypes . node ,
70- isRequired : PropTypes . bool ,
7142 label : PropTypes . node ,
7243 helperText : PropTypes . node ,
7344 validateOnMount : PropTypes . bool ,
@@ -76,4 +47,9 @@ Select.propTypes = {
7647 description : PropTypes . node
7748} ;
7849
50+ Select . defaultProps = {
51+ placeholder : 'Please choose' ,
52+ noOptionsMessage : 'No option found'
53+ } ;
54+
7955export default Select ;
0 commit comments