@evoke-platform/ui-components 1.6.0-dev.5 → 1.6.0-dev.7

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();
@@ -27,11 +28,14 @@ const Select = (props) => {
27
28
  otherInputRef.current.focus();
28
29
  }
29
30
  }, [isOther, value]);
31
+ useEffect(() => {
32
+ setValue(defaultValue);
33
+ }, [defaultValue]);
30
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
35
  const handleChange = (event, selected) => {
32
36
  if (Array.isArray(selected)) {
33
37
  const newValues = selected.map((option) => option.value ?? option);
34
- setValue(newValues);
38
+ setValue(uniq(newValues));
35
39
  onChange && onChange(property.id, newValues, property);
36
40
  }
37
41
  else {
@@ -144,6 +148,7 @@ const Select = (props) => {
144
148
  filtered.push({
145
149
  value: inputValue,
146
150
  label: `Add "${inputValue}"`,
151
+ isCustomValue: true,
147
152
  });
148
153
  }
149
154
  return filtered;
@@ -151,12 +156,19 @@ const Select = (props) => {
151
156
  ? (option, value) => isOptionEqualToValue(option, value)
152
157
  : undefined, getOptionLabel: getOptionLabel && !isCombobox
153
158
  ? (option) => getOptionLabel(option)
154
- : (option) => (typeof option === 'string' ? option : option.label), renderOption: renderOption
159
+ : (option) => {
160
+ if (typeof option === 'string')
161
+ return option;
162
+ // If the option is a custom value, return the value without the prepended "Add" text.
163
+ if (option.isCustomValue)
164
+ return option.value;
165
+ return option.label ?? '';
166
+ }, renderOption: renderOption
155
167
  ? (props, option, state) => renderOption(props, option, state)
156
- : undefined, ListboxComponent: ListboxComponent, disableCloseOnSelect: disableCloseOnSelect, sx: {
168
+ : (props, option) => React.createElement("li", { ...props }, option.label ?? option), ListboxComponent: ListboxComponent, disableCloseOnSelect: disableCloseOnSelect, sx: {
157
169
  '& button.MuiButtonBase-root': {
158
170
  visibility: 'visible',
159
171
  },
160
- }, ...(isCombobox ? { selectOnFocus: true, handleHomeEndKeys: true, freeSolo: true } : {}), ...(additionalProps ?? {}) }));
172
+ }, forcePopupIcon: true, ...(isCombobox ? { selectOnFocus: true, handleHomeEndKeys: true, freeSolo: true } : {}), ...(additionalProps ?? {}) }));
161
173
  };
162
174
  export default Select;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.6.0-dev.5",
3
+ "version": "1.6.0-dev.7",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",