@widergy/energy-ui 2.8.1 → 2.9.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [2.9.0](https://github.com/widergy/energy-ui/compare/v2.8.1...v2.9.0) (2023-10-26)
2
+
3
+
4
+ ### Features
5
+
6
+ * autocomplete - multiple ([#387](https://github.com/widergy/energy-ui/issues/387)) ([4f567e2](https://github.com/widergy/energy-ui/commit/4f567e2e23529cca996d41becde5b473f2c029ad))
7
+
1
8
  ## [2.8.1](https://github.com/widergy/energy-ui/compare/v2.8.0...v2.8.1) (2023-10-12)
2
9
 
3
10
 
@@ -45,10 +45,6 @@ var UTAutocomplete = function UTAutocomplete(_ref) {
45
45
  placeholder = _ref.placeholder,
46
46
  textFieldProps = _ref.textFieldProps,
47
47
  variant = _ref.variant;
48
- var _useState = (0, _react.useState)(''),
49
- _useState2 = _slicedToArray(_useState, 2),
50
- componentValue = _useState2[0],
51
- setComponentValue = _useState2[1];
52
48
  var _ref2 = field.configuration || {},
53
49
  _ref2$field_options_v = _ref2.field_options_value_key,
54
50
  valueKey = _ref2$field_options_v === void 0 ? _constants.DEFAULT_VALUE_KEY : _ref2$field_options_v,
@@ -57,23 +53,58 @@ var UTAutocomplete = function UTAutocomplete(_ref) {
57
53
  _ref2$field_options_n = _ref2.field_options_no_results_message,
58
54
  noOptionsMessage = _ref2$field_options_n === void 0 ? _constants.INVALID_OPTION : _ref2$field_options_n,
59
55
  _ref2$field_options_e = _ref2.field_options_empty_message,
60
- emptyOptionsLabel = _ref2$field_options_e === void 0 ? _constants.ERROR_EMPTY_OPTIONS : _ref2$field_options_e;
56
+ emptyOptionsLabel = _ref2$field_options_e === void 0 ? _constants.ERROR_EMPTY_OPTIONS : _ref2$field_options_e,
57
+ _ref2$multiple = _ref2.multiple,
58
+ multiple = _ref2$multiple === void 0 ? false : _ref2$multiple;
59
+ var initialValue = (0, _react.useMemo)(function () {
60
+ return multiple ? [] : '';
61
+ }, [multiple]);
62
+ var _useState = (0, _react.useState)(initialValue),
63
+ _useState2 = _slicedToArray(_useState, 2),
64
+ componentValue = _useState2[0],
65
+ setComponentValue = _useState2[1];
61
66
  var textInputLabel = (0, _array.isEmpty)(options) ? emptyOptionsLabel : label;
62
67
  var fieldDisabled = disabled || loading || (0, _array.isEmpty)(options);
63
68
  var onChange = function onChange(_, values) {
64
- input.onChange(values === null || values === void 0 ? void 0 : values[valueKey]);
65
- if (!values) setComponentValue(null);
69
+ input.onChange(multiple ? values === null || values === void 0 ? void 0 : values.map(function (val) {
70
+ return val[valueKey];
71
+ }) : values === null || values === void 0 ? void 0 : values[valueKey]);
72
+ if (!values) setComponentValue(initialValue);
66
73
  if (field.onChange) field.onChange(values);
67
74
  };
68
75
  (0, _react.useEffect)(function () {
69
- setComponentValue(input.value && options ? options.find(function (option) {
76
+ setComponentValue(input.value && !(0, _array.isEmpty)(options) ? multiple ? options.filter(function (option) {
77
+ return input.value.some(function (inputValue) {
78
+ return inputValue === option[valueKey];
79
+ });
80
+ }) : options.find(function (option) {
70
81
  return option[valueKey] === input.value;
71
- }) : null);
82
+ }) : multiple ? [] : '');
72
83
  }, [input.value]);
73
84
  (0, _react.useEffect)(function () {
74
- if (options && input.value && !componentValue) setComponentValue(options.find(function (option) {
75
- return option[valueKey] === input.value;
76
- }));
85
+ if ((0, _array.isEmpty)(options) || (multiple ? (0, _array.isEmpty)(input.value) : !input.value)) {
86
+ if (multiple && !(0, _array.isEmpty)(componentValue) || componentValue) {
87
+ input.onChange(initialValue);
88
+ setComponentValue(initialValue);
89
+ }
90
+ } else {
91
+ var newInputValue = multiple ? input.value.filter(function (inputValue) {
92
+ return options.some(function (option) {
93
+ return inputValue === option[valueKey];
94
+ });
95
+ }) : options.some(function (option) {
96
+ return option[valueKey] === input.value;
97
+ }) ? input.value : '';
98
+ input.onChange(newInputValue);
99
+ var updatedValue = multiple ? options.filter(function (option) {
100
+ return newInputValue.some(function (inputValue) {
101
+ return inputValue === option[valueKey];
102
+ });
103
+ }) : options.find(function (option) {
104
+ return option[valueKey] === newInputValue;
105
+ });
106
+ setComponentValue(updatedValue);
107
+ }
77
108
  }, [options]);
78
109
  var textInputEndAdornment = loading ? /*#__PURE__*/_react.default.createElement(_CircularProgress.default, {
79
110
  className: classes.loadingIcon
@@ -82,23 +113,24 @@ var UTAutocomplete = function UTAutocomplete(_ref) {
82
113
  });
83
114
  var errorMessage = (0, _form.shouldShowErrors)(meta) && meta.error || '';
84
115
  return /*#__PURE__*/_react.default.createElement(_Autocomplete.default, _extends({
85
- id: field.key,
86
116
  clearText: _constants.CLEAR_TEXT,
87
117
  closeText: _constants.CLOSE_TEXT,
88
- openText: _constants.OPEN_TEXT,
118
+ disabled: fieldDisabled,
119
+ getOptionLabel: function getOptionLabel(option) {
120
+ return option[labelKey] || '';
121
+ },
122
+ id: field.key,
89
123
  ListboxComponent: _ListBox.default,
90
124
  ListboxProps: {
91
125
  fixedSizeListProps: fixedSizeListProps
92
126
  },
93
- getOptionLabel: function getOptionLabel(option) {
94
- return option[labelKey] || '';
95
- },
96
- onChange: onChange,
97
- disabled: fieldDisabled,
98
- value: componentValue,
127
+ multiple: multiple,
99
128
  noOptionsText: noOptionsMessage,
129
+ onChange: onChange,
130
+ openText: _constants.OPEN_TEXT,
100
131
  options: options,
101
132
  popupIcon: textInputEndAdornment,
133
+ value: componentValue,
102
134
  renderInput: function renderInput(params) {
103
135
  return /*#__PURE__*/_react.default.createElement(_TextField.default, _extends({}, params, {
104
136
  label: textInputLabel,
@@ -3,6 +3,8 @@
3
3
  .drawer {
4
4
  align-items: center;
5
5
  display: flex;
6
+ margin: 0;
7
+ max-height: auto;
6
8
  overflow-x: hidden;
7
9
 
8
10
  @media #{$desktop-tablet} {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",