Skip to content

Commit c9be80f

Browse files
committed
MUI use common select
1 parent 208c184 commit c9be80f

File tree

3 files changed

+8
-32
lines changed

3 files changed

+8
-32
lines changed

packages/common/src/select/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const Select = ({
161161
Select.propTypes = {
162162
options: PropTypes.array,
163163
onChange: PropTypes.func,
164-
classNamePrefix: PropTypes.string.isRequired,
164+
classNamePrefix: PropTypes.string,
165165
invalid: PropTypes.bool,
166166
simpleValue: PropTypes.bool,
167167
isMulti: PropTypes.bool,

packages/mui-component-mapper/src/files/select.js

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,27 @@ import { meta, input } from '@data-driven-forms/common/src/prop-types-templates'
77
import MUISelect from './select/integration-select';
88
import { 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-
1210
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);
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) => {
6438
Select.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+
7955
export default Select;

packages/mui-component-mapper/src/files/select/integration-select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import clsx from 'clsx';
4-
import Select from 'react-select';
4+
import Select from '@data-driven-forms/common/src/select';
55
import { emphasize, makeStyles, useTheme } from '@material-ui/core/styles';
66
import { Typography, NoSsr, TextField, Paper, Chip, MenuItem, FormControl, FormHelperText, FormLabel } from '@material-ui/core';
77
import CancelIcon from '@material-ui/icons/Cancel';

0 commit comments

Comments
 (0)