dynamic-mui 1.1.1 → 1.1.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.
@@ -30,10 +30,11 @@ const getValue = function () {
30
30
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
31
31
  let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
32
32
  let isMultiple = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
33
+ let separator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ',';
33
34
  if (isMultiple) {
34
- let separator = ',';
35
- if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(',')) separator = ',';else if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(';')) separator = ';';
36
- const dValueSet = new Set(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.split(separator));
35
+ let tempSeparator = separator;
36
+ if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(',')) tempSeparator = ',';else if (defaultValue !== null && defaultValue !== void 0 && defaultValue.includes(';')) tempSeparator = ';';
37
+ const dValueSet = new Set(defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.split(tempSeparator));
37
38
  return options === null || options === void 0 ? void 0 : options.filter(_ref => {
38
39
  let {
39
40
  value
@@ -60,7 +61,7 @@ function Select(_ref3) {
60
61
  id = '',
61
62
  InputProps = {}
62
63
  } = attributes;
63
- const [value, setValue] = _react.default.useState((attributes === null || attributes === void 0 ? void 0 : attributes.value) && getValue(options, attributes === null || attributes === void 0 ? void 0 : attributes.value, MuiAttributes.multiple));
64
+ const [value, setValue] = _react.default.useState((attributes === null || attributes === void 0 ? void 0 : attributes.value) && getValue(options, attributes === null || attributes === void 0 ? void 0 : attributes.value, MuiAttributes.multiple, attributes === null || attributes === void 0 ? void 0 : attributes.separator));
64
65
  const getMuiAttributes = () => {
65
66
  if (MuiAttributes.multiple) {
66
67
  MuiAttributes.renderOption = function (props) {
@@ -83,20 +84,30 @@ function Select(_ref3) {
83
84
  };
84
85
  const extractValue = option => (option === null || option === void 0 ? void 0 : option.value) || (option === null || option === void 0 ? void 0 : option.title) || (option === null || option === void 0 ? void 0 : option.label);
85
86
  const onChangeEvent = (0, _react.useCallback)((event, newValue) => {
87
+ var _attributes$separator;
86
88
  setValue(newValue);
89
+
90
+ // Use attributes?.separator, default to ';'
91
+ const separator = (_attributes$separator = attributes === null || attributes === void 0 ? void 0 : attributes.separator) !== null && _attributes$separator !== void 0 ? _attributes$separator : ';';
87
92
  if (newValue) {
88
93
  const data = MuiAttributes.multiple ? newValue.map(extractValue) : extractValue(newValue);
94
+ const customValue = MuiAttributes.multiple ? data.join(separator) // <-- use custom separator here
95
+ : data;
89
96
  onChange({
90
97
  id,
91
- value: MuiAttributes.multiple ? data.toString() : data,
98
+ value: customValue,
92
99
  option: newValue
93
100
  });
94
- } else onChange({
95
- id,
96
- value: '',
97
- option: newValue
98
- });
99
- }, []);
101
+ } else {
102
+ onChange({
103
+ id,
104
+ value: '',
105
+ option: newValue
106
+ });
107
+ }
108
+ }, [id, onChange, attributes === null || attributes === void 0 ? void 0 : attributes.separator,
109
+ // so changes to separator update the callback
110
+ MuiAttributes.multiple, extractValue]);
100
111
  return /*#__PURE__*/_react.default.createElement(_Autocomplete.default, _extends({
101
112
  disablePortal: false
102
113
  }, getMuiAttributes(), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynamic-mui",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "author": "Dinakaran S",
5
5
  "user": "dinakarans",
6
6
  "repository": {