@irontec/ivoz-ui 1.6.1 → 1.6.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@irontec/ivoz-ui",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "UI library used in ivozprovider",
5
5
  "license": "GPL-3.0",
6
6
  "main": "index.js",
@@ -5,9 +5,9 @@ import { useCallback, useEffect, useState, } from 'react';
5
5
  import { getI18n } from 'react-i18next';
6
6
  import { StyledAutocompleteTextField } from '../TextField';
7
7
  const Autocomplete = (props) => {
8
- var _a;
8
+ var _a, _b;
9
9
  const { name, label, required, multiple, disabled, onChange, onBlur, choices, error, errorMsg, helperText, hasChanged, } = props;
10
- const value = props.value || null;
10
+ const value = (_a = props.value) !== null && _a !== void 0 ? _a : null;
11
11
  const i18n = getI18n();
12
12
  let className = props.className;
13
13
  if (hasChanged) {
@@ -84,13 +84,35 @@ const Autocomplete = (props) => {
84
84
  ? false
85
85
  : true;
86
86
  }
87
+ const autoDefaultValue = (value) => {
88
+ if (value !== '__auto__') {
89
+ return value;
90
+ }
91
+ if (arrayChoices.length === 0) {
92
+ return value;
93
+ }
94
+ const realChoices = arrayChoices.filter((dac) => dac.id != '__null__');
95
+ if (realChoices.length != 1) {
96
+ return '__null__';
97
+ }
98
+ return realChoices[0].id;
99
+ };
87
100
  let autocompleteValue;
88
101
  if (multiple) {
89
102
  autocompleteValue = arrayChoices.length ? value : [];
90
103
  }
91
104
  else {
105
+ const autoValue = autoDefaultValue(value);
92
106
  autocompleteValue =
93
- (_a = arrayChoices === null || arrayChoices === void 0 ? void 0 : arrayChoices.find((item) => `${item.id}` === `${value}`)) !== null && _a !== void 0 ? _a : null;
107
+ (_b = arrayChoices === null || arrayChoices === void 0 ? void 0 : arrayChoices.find((item) => `${item.id}` === `${autoValue}`)) !== null && _b !== void 0 ? _b : null;
108
+ if (autoValue != value) {
109
+ onChange({
110
+ target: {
111
+ name: name,
112
+ value: autoValue,
113
+ },
114
+ });
115
+ }
94
116
  }
95
117
  return (_jsx(MuiAutocomplete, { className: 'autocomplete ' + className, value: autocompleteValue, multiple: multiple, disabled: disabled, disableClearable: disableClearable, onChange: onChangeWrapper, onBlur: onBlur, options: arrayChoices, getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, filterSelectedOptions: true, renderInput: renderInput, renderOption: (props, option) => (_jsx(Box, Object.assign({ component: 'li', className: 'autocomplete-option', "data-value": option.id }, props, { children: option.label }))) }));
96
118
  };