@rhc-shared-components/form-multi-select-component 0.0.3 → 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 +21 -0
- package/dist/FormMultiSelectInput.d.ts +0 -1
- package/dist/index.js +9 -27
- package/dist/index.modern.js +7 -22
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,27 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
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
|
+
|
|
6
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)
|
|
7
28
|
|
|
8
29
|
**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", "
|
|
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,39 +60,22 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
61
60
|
var _useFormikContext = formik.useFormikContext(),
|
|
62
61
|
isSubmitting = _useFormikContext.isSubmitting,
|
|
63
62
|
setFieldValue = _useFormikContext.setFieldValue,
|
|
64
|
-
|
|
63
|
+
setFieldTouched = _useFormikContext.setFieldTouched;
|
|
65
64
|
|
|
66
65
|
var _React$useState = React__namespace.useState(false),
|
|
67
66
|
isOpen = _React$useState[0],
|
|
68
67
|
setIsOpen = _React$useState[1];
|
|
69
68
|
|
|
70
|
-
var _React$useState2 = React__namespace.useState([]),
|
|
71
|
-
selected = _React$useState2[0],
|
|
72
|
-
setSelected = _React$useState2[1];
|
|
73
|
-
|
|
74
69
|
var onSelect = function onSelect(_event, selection) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
} else {
|
|
81
|
-
if (maxItems && value.length === maxItems) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
setFieldValue(rest.name, [].concat(value, [selection]));
|
|
86
|
-
validateField(rest.name);
|
|
87
|
-
}
|
|
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);
|
|
88
75
|
};
|
|
89
76
|
|
|
90
|
-
React__namespace.useEffect(function () {
|
|
91
|
-
setSelected(value);
|
|
92
|
-
}, [value]);
|
|
93
|
-
|
|
94
77
|
var onClear = function onClear() {
|
|
95
|
-
setFieldValue(rest.name, []);
|
|
96
|
-
validateField(rest.name);
|
|
78
|
+
setFieldValue(rest.name, [], true);
|
|
97
79
|
setIsOpen(false);
|
|
98
80
|
};
|
|
99
81
|
|
|
@@ -116,7 +98,7 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
116
98
|
onToggle: onToggle,
|
|
117
99
|
onSelect: onSelect,
|
|
118
100
|
onClear: onClear,
|
|
119
|
-
selections:
|
|
101
|
+
selections: value,
|
|
120
102
|
isOpen: isOpen
|
|
121
103
|
}, maxHeight && {
|
|
122
104
|
maxHeight: maxHeight
|
package/dist/index.modern.js
CHANGED
|
@@ -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", "
|
|
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,32 +40,18 @@ const FormMultiSelectInput = _ref => {
|
|
|
41
40
|
const {
|
|
42
41
|
isSubmitting,
|
|
43
42
|
setFieldValue,
|
|
44
|
-
|
|
43
|
+
setFieldTouched
|
|
45
44
|
} = useFormikContext();
|
|
46
45
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
47
|
-
const [selected, setSelected] = React.useState([]);
|
|
48
46
|
|
|
49
47
|
const onSelect = (_event, selection) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} else {
|
|
54
|
-
if (maxItems && value.length === maxItems) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
setFieldValue(rest.name, [...value, selection]);
|
|
59
|
-
validateField(rest.name);
|
|
60
|
-
}
|
|
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);
|
|
61
51
|
};
|
|
62
52
|
|
|
63
|
-
React.useEffect(() => {
|
|
64
|
-
setSelected(value);
|
|
65
|
-
}, [value]);
|
|
66
|
-
|
|
67
53
|
const onClear = () => {
|
|
68
|
-
setFieldValue(rest.name, []);
|
|
69
|
-
validateField(rest.name);
|
|
54
|
+
setFieldValue(rest.name, [], true);
|
|
70
55
|
setIsOpen(false);
|
|
71
56
|
};
|
|
72
57
|
|
|
@@ -89,7 +74,7 @@ const FormMultiSelectInput = _ref => {
|
|
|
89
74
|
onToggle: onToggle,
|
|
90
75
|
onSelect: onSelect,
|
|
91
76
|
onClear: onClear,
|
|
92
|
-
selections:
|
|
77
|
+
selections: value,
|
|
93
78
|
isOpen: isOpen
|
|
94
79
|
}, maxHeight && {
|
|
95
80
|
maxHeight
|