@evoke-platform/ui-components 1.6.0-testing.4 → 1.6.0-testing.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
|
|
1
1
|
import { createFilterOptions, List, ListSubheader } from '@mui/material';
|
2
|
+
import { uniq } from 'lodash';
|
2
3
|
import React, { forwardRef, useEffect, useRef, useState } from 'react';
|
3
4
|
import { Clear } from '../../../../icons';
|
4
5
|
import { Autocomplete, FormControl, FormControlLabel, IconButton, Radio, RadioGroup, TextField, Typography, } from '../../../core';
|
@@ -15,7 +16,7 @@ const Select = (props) => {
|
|
15
16
|
const [isOtherFocused, setIsOtherFocused] = useState(false);
|
16
17
|
const [value, setValue] = useState(defaultValue);
|
17
18
|
const [inputValue, setInputValue] = useState(!selectOptions?.some((option) => (typeof option === 'string' && option === defaultValue) ||
|
18
|
-
option.value === defaultValue)
|
19
|
+
option.value === defaultValue) && property.type !== 'array'
|
19
20
|
? defaultValue
|
20
21
|
: '');
|
21
22
|
const [errorState, setErrorState] = useState();
|
@@ -31,7 +32,7 @@ const Select = (props) => {
|
|
31
32
|
const handleChange = (event, selected) => {
|
32
33
|
if (Array.isArray(selected)) {
|
33
34
|
const newValues = selected.map((option) => option.value ?? option);
|
34
|
-
setValue(newValues);
|
35
|
+
setValue(uniq(newValues));
|
35
36
|
onChange && onChange(property.id, newValues, property);
|
36
37
|
}
|
37
38
|
else {
|
@@ -144,6 +145,7 @@ const Select = (props) => {
|
|
144
145
|
filtered.push({
|
145
146
|
value: inputValue,
|
146
147
|
label: `Add "${inputValue}"`,
|
148
|
+
isCustomValue: true,
|
147
149
|
});
|
148
150
|
}
|
149
151
|
return filtered;
|
@@ -151,9 +153,16 @@ const Select = (props) => {
|
|
151
153
|
? (option, value) => isOptionEqualToValue(option, value)
|
152
154
|
: undefined, getOptionLabel: getOptionLabel && !isCombobox
|
153
155
|
? (option) => getOptionLabel(option)
|
154
|
-
: (option) =>
|
156
|
+
: (option) => {
|
157
|
+
if (typeof option === 'string')
|
158
|
+
return option;
|
159
|
+
// If the option is a custom value, return the value without the prepended "Add" text.
|
160
|
+
if (option.isCustomValue)
|
161
|
+
return option.value;
|
162
|
+
return option.label ?? '';
|
163
|
+
}, renderOption: renderOption
|
155
164
|
? (props, option, state) => renderOption(props, option, state)
|
156
|
-
:
|
165
|
+
: (props, option) => React.createElement("li", { ...props }, option.label ?? option), ListboxComponent: ListboxComponent, disableCloseOnSelect: disableCloseOnSelect, sx: {
|
157
166
|
'& button.MuiButtonBase-root': {
|
158
167
|
visibility: 'visible',
|
159
168
|
},
|