@rhc-shared-components/form-multi-select-component 0.0.4 → 0.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [0.0.4](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/compare/@rhc-shared-components/form-multi-select-component@0.0.2...@rhc-shared-components/form-multi-select-component@0.0.4) (2022-10-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * added setTouched prop in multiselect component. ([3b0b6ff](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/commit/3b0b6ff0445995129bc2b2908861768a513339d8))
12
+ * added touched handler ([82e397e](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/commit/82e397e3c8ae90944d3110dd5d7b3d5ff98b0589))
13
+
14
+
15
+
16
+ ## 0.0.3 (2022-10-27)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * added meta.touched prop to the form multi select component. ([590886f](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/commit/590886fd8eb49a2153f6d5b512c6bd61cbae205c))
22
+
23
+
24
+
25
+
26
+
27
+ ## [0.0.2](https://gitlab.cee.redhat.com/customer-platform/rhc-shared-components/compare/@rhc-shared-components/form-multi-select-component@0.0.1...@rhc-shared-components/form-multi-select-component@0.0.2) (2022-01-05)
28
+
29
+ **Note:** Version bump only for package @rhc-shared-components/form-multi-select-component
30
+
31
+
32
+
33
+
34
+
35
+ ## 0.0.1 (2021-12-06)
36
+
37
+ **Note:** Version bump only for package @rhc-shared-components/form-multi-select-component
@@ -12,7 +12,6 @@ export interface FormMultiSelectInputProps {
12
12
  selectOptions: IMultiSelectItem[];
13
13
  ariaLabel?: string;
14
14
  helperText?: string;
15
- maxItems?: number;
16
15
  maxHeight?: string | number;
17
16
  }
18
17
  declare const FormMultiSelectInput: React.FC<FormMultiSelectInputProps>;
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
39
39
  return target;
40
40
  }
41
41
 
42
- var _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxItems", "maxHeight"];
42
+ var _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight"];
43
43
 
44
44
  var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
45
45
  var label = _ref.label,
@@ -49,7 +49,6 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
49
49
  ariaLabel = _ref$ariaLabel === void 0 ? 'Select Input' : _ref$ariaLabel,
50
50
  placeholder = _ref.placeholder,
51
51
  helperText = _ref.helperText,
52
- maxItems = _ref.maxItems,
53
52
  maxHeight = _ref.maxHeight,
54
53
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
55
54
 
@@ -61,42 +60,22 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
61
60
  var _useFormikContext = formik.useFormikContext(),
62
61
  isSubmitting = _useFormikContext.isSubmitting,
63
62
  setFieldValue = _useFormikContext.setFieldValue,
64
- validateField = _useFormikContext.validateField,
65
63
  setFieldTouched = _useFormikContext.setFieldTouched;
66
64
 
67
65
  var _React$useState = React__namespace.useState(false),
68
66
  isOpen = _React$useState[0],
69
67
  setIsOpen = _React$useState[1];
70
68
 
71
- var _React$useState2 = React__namespace.useState([]),
72
- selected = _React$useState2[0],
73
- setSelected = _React$useState2[1];
74
-
75
69
  var onSelect = function onSelect(_event, selection) {
76
- if (value.includes(selection)) {
77
- setFieldValue(rest.name, value.filter(function (item) {
78
- return item !== selection;
79
- }));
80
- validateField(rest.name);
81
- } else {
82
- if (maxItems && value.length === maxItems) {
83
- return;
84
- }
85
-
86
- setFieldValue(rest.name, [].concat(value, [selection]));
87
- validateField(rest.name);
88
- }
89
-
90
- setFieldTouched(rest.name, true);
70
+ var newValues = value.includes(selection) ? value.filter(function (item) {
71
+ return item !== selection;
72
+ }) : [].concat(value, [selection]);
73
+ setFieldTouched(rest.name, true, false);
74
+ setFieldValue(rest.name, newValues, true);
91
75
  };
92
76
 
93
- React__namespace.useEffect(function () {
94
- setSelected(value);
95
- }, [value]);
96
-
97
77
  var onClear = function onClear() {
98
- setFieldValue(rest.name, []);
99
- validateField(rest.name);
78
+ setFieldValue(rest.name, [], true);
100
79
  setIsOpen(false);
101
80
  };
102
81
 
@@ -119,7 +98,7 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
119
98
  onToggle: onToggle,
120
99
  onSelect: onSelect,
121
100
  onClear: onClear,
122
- selections: selected,
101
+ selections: value,
123
102
  isOpen: isOpen
124
103
  }, maxHeight && {
125
104
  maxHeight: maxHeight
@@ -19,7 +19,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
19
19
  return target;
20
20
  }
21
21
 
22
- const _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxItems", "maxHeight"];
22
+ const _excluded = ["label", "isRequired", "children", "selectOptions", "ariaLabel", "placeholder", "helperText", "maxHeight"];
23
23
 
24
24
  const FormMultiSelectInput = _ref => {
25
25
  let {
@@ -29,7 +29,6 @@ const FormMultiSelectInput = _ref => {
29
29
  ariaLabel = 'Select Input',
30
30
  placeholder,
31
31
  helperText,
32
- maxItems,
33
32
  maxHeight
34
33
  } = _ref,
35
34
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -41,35 +40,18 @@ const FormMultiSelectInput = _ref => {
41
40
  const {
42
41
  isSubmitting,
43
42
  setFieldValue,
44
- validateField,
45
43
  setFieldTouched
46
44
  } = useFormikContext();
47
45
  const [isOpen, setIsOpen] = React.useState(false);
48
- const [selected, setSelected] = React.useState([]);
49
46
 
50
47
  const onSelect = (_event, selection) => {
51
- if (value.includes(selection)) {
52
- setFieldValue(rest.name, value.filter(item => item !== selection));
53
- validateField(rest.name);
54
- } else {
55
- if (maxItems && value.length === maxItems) {
56
- return;
57
- }
58
-
59
- setFieldValue(rest.name, [...value, selection]);
60
- validateField(rest.name);
61
- }
62
-
63
- setFieldTouched(rest.name, true);
48
+ const newValues = value.includes(selection) ? value.filter(item => item !== selection) : [...value, selection];
49
+ setFieldTouched(rest.name, true, false);
50
+ setFieldValue(rest.name, newValues, true);
64
51
  };
65
52
 
66
- React.useEffect(() => {
67
- setSelected(value);
68
- }, [value]);
69
-
70
53
  const onClear = () => {
71
- setFieldValue(rest.name, []);
72
- validateField(rest.name);
54
+ setFieldValue(rest.name, [], true);
73
55
  setIsOpen(false);
74
56
  };
75
57
 
@@ -92,7 +74,7 @@ const FormMultiSelectInput = _ref => {
92
74
  onToggle: onToggle,
93
75
  onSelect: onSelect,
94
76
  onClear: onClear,
95
- selections: selected,
77
+ selections: value,
96
78
  isOpen: isOpen
97
79
  }, maxHeight && {
98
80
  maxHeight
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhc-shared-components/form-multi-select-component",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "project description",
5
5
  "author": "shkale",
6
6
  "license": "MIT",
@@ -76,6 +76,5 @@
76
76
  ],
77
77
  "publishConfig": {
78
78
  "access": "public"
79
- },
80
- "gitHead": "a8ed9cc748eefbfdd57bfae01aef27dd11ea0f0b"
79
+ }
81
80
  }