@@ -7,53 +7,27 @@ import { meta, input } from '@data-driven-forms/common/src/prop-types-templates'
7
7
import MUISelect from './select/integration-select' ;
8
8
import { useFieldApi } from '@data-driven-forms/react-form-renderer' ;
9
9
10
- const selectValue = ( option ) => option . sort ( ( a , b ) => a . label . localeCompare ( b . label , 'en' , { sensitivity : 'base' } ) ) . map ( ( item ) => item . value ) ;
11
-
12
10
const 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 ) ;
28
12
const invalid = validationError ( meta , validateOnMount ) ;
29
13
30
14
return (
31
15
< FormFieldGrid >
32
16
< MUISelect
33
17
fullWidth
34
18
{ ...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 }
39
19
isSearchable = { ! ! isSearchable }
40
20
isClearable = { false }
41
- hideSelectedOptions = { false }
42
- closeMenuOnSelect = { ! rest . isMulti }
43
- noOptionsMessage = { ( ) => 'No option found' }
44
21
invalid = { invalid }
45
- isDisabled = { isDisabled }
46
22
textFieldProps = { {
47
23
label,
48
24
color : invalid ? 'red' : 'blue' ,
49
25
InputLabelProps : {
50
26
shrink : true
51
27
}
52
28
} }
53
- onChange = { ( option ) => input . onChange ( rest . isMulti ? selectValue ( option ) : option ? option . value : undefined ) }
54
29
input = { input }
55
30
label = { label }
56
- isRequired = { isRequired }
57
31
helperText = { invalid || helperText || description }
58
32
{ ...rest }
59
33
/>
@@ -64,10 +38,7 @@ const Select = (props) => {
64
38
Select . propTypes = {
65
39
input,
66
40
meta,
67
- isReadOnly : PropTypes . bool ,
68
- isDisabled : PropTypes . bool ,
69
41
placeholder : PropTypes . node ,
70
- isRequired : PropTypes . bool ,
71
42
label : PropTypes . node ,
72
43
helperText : PropTypes . node ,
73
44
validateOnMount : PropTypes . bool ,
@@ -76,4 +47,9 @@ Select.propTypes = {
76
47
description : PropTypes . node
77
48
} ;
78
49
50
+ Select . defaultProps = {
51
+ placeholder : 'Please choose' ,
52
+ noOptionsMessage : 'No option found'
53
+ } ;
54
+
79
55
export default Select ;
0 commit comments