@rhc-shared-components/form-multi-select-component 1.0.6 → 1.0.7
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/dist/index.js +119 -149
- package/dist/index.modern.js +90 -122
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,36 +27,30 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
27
27
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
28
28
|
|
|
29
29
|
function _extends() {
|
|
30
|
-
_extends = Object.assign
|
|
31
|
-
for (var
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
for (var key in source) {
|
|
35
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
36
|
-
target[key] = source[key];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
30
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
31
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
32
|
+
var t = arguments[e];
|
|
33
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
39
34
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return _extends.apply(this, arguments);
|
|
35
|
+
return n;
|
|
36
|
+
}, _extends.apply(null, arguments);
|
|
45
37
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
56
|
-
target[key] = source[key];
|
|
38
|
+
function _inheritsLoose(t, o) {
|
|
39
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
40
|
+
}
|
|
41
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
42
|
+
if (null == r) return {};
|
|
43
|
+
var t = {};
|
|
44
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
45
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
46
|
+
t[n] = r[n];
|
|
57
47
|
}
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
return t;
|
|
49
|
+
}
|
|
50
|
+
function _setPrototypeOf(t, e) {
|
|
51
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
52
|
+
return t.__proto__ = e, t;
|
|
53
|
+
}, _setPrototypeOf(t, e);
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
/******************************************************************************
|
|
@@ -73,133 +67,143 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
73
67
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
74
68
|
PERFORMANCE OF THIS SOFTWARE.
|
|
75
69
|
***************************************************************************** */
|
|
76
|
-
|
|
77
70
|
function __rest(s, e) {
|
|
78
71
|
var t = {};
|
|
79
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
84
|
-
t[p[i]] = s[p[i]];
|
|
85
|
-
}
|
|
72
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
73
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
74
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
75
|
+
}
|
|
86
76
|
return t;
|
|
87
77
|
}
|
|
88
|
-
|
|
89
78
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
90
79
|
var e = new Error(message);
|
|
91
80
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
92
81
|
};
|
|
93
82
|
|
|
94
|
-
|
|
83
|
+
var currentId = 0;
|
|
95
84
|
/**
|
|
96
85
|
* Factory to create Icon class components for consumers
|
|
97
86
|
*/
|
|
98
|
-
function createIcon(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
87
|
+
function createIcon(_ref) {
|
|
88
|
+
var name = _ref.name,
|
|
89
|
+
_ref$xOffset = _ref.xOffset,
|
|
90
|
+
xOffset = _ref$xOffset === void 0 ? 0 : _ref$xOffset,
|
|
91
|
+
_ref$yOffset = _ref.yOffset,
|
|
92
|
+
yOffset = _ref$yOffset === void 0 ? 0 : _ref$yOffset,
|
|
93
|
+
width = _ref.width,
|
|
94
|
+
height = _ref.height,
|
|
95
|
+
svgPath = _ref.svgPath;
|
|
96
|
+
var _a;
|
|
97
|
+
return _a = /*#__PURE__*/function (_React$Component) {
|
|
98
|
+
function SVGIcon() {
|
|
99
|
+
var _this;
|
|
100
|
+
_this = _React$Component.apply(this, arguments) || this;
|
|
101
|
+
_this.id = "icon-title-" + currentId++;
|
|
102
|
+
return _this;
|
|
103
|
+
}
|
|
104
|
+
_inheritsLoose(SVGIcon, _React$Component);
|
|
105
|
+
var _proto = SVGIcon.prototype;
|
|
106
|
+
_proto.render = function render() {
|
|
107
|
+
var _b = this.props,
|
|
108
|
+
title = _b.title,
|
|
109
|
+
className = _b.className,
|
|
110
|
+
props = __rest(_b, ["title", "className"]);
|
|
111
|
+
var classes = className ? "pf-v5-svg " + className : 'pf-v5-svg';
|
|
112
|
+
var hasTitle = Boolean(title);
|
|
113
|
+
var viewBox = [xOffset, yOffset, width, height].join(' ');
|
|
114
|
+
return React__namespace.createElement("svg", Object.assign({
|
|
115
|
+
className: classes,
|
|
116
|
+
viewBox: viewBox,
|
|
117
|
+
fill: "currentColor",
|
|
118
|
+
"aria-labelledby": hasTitle ? this.id : null,
|
|
119
|
+
"aria-hidden": hasTitle ? null : true,
|
|
120
|
+
role: "img",
|
|
121
|
+
width: "1em",
|
|
122
|
+
height: "1em"
|
|
123
|
+
}, props), hasTitle && React__namespace.createElement("title", {
|
|
124
|
+
id: this.id
|
|
125
|
+
}, title), React__namespace.createElement("path", {
|
|
126
|
+
d: svgPath
|
|
127
|
+
}));
|
|
128
|
+
};
|
|
129
|
+
return SVGIcon;
|
|
130
|
+
}(React__namespace.Component), _a.displayName = name, _a;
|
|
117
131
|
}
|
|
118
132
|
|
|
119
|
-
|
|
133
|
+
var TimesIconConfig = {
|
|
120
134
|
name: 'TimesIcon',
|
|
121
135
|
height: 512,
|
|
122
136
|
width: 352,
|
|
123
137
|
svgPath: 'M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z',
|
|
124
138
|
yOffset: 0,
|
|
125
|
-
xOffset: 0
|
|
139
|
+
xOffset: 0
|
|
126
140
|
};
|
|
127
|
-
|
|
128
|
-
const TimesIcon = createIcon(TimesIconConfig);
|
|
129
|
-
|
|
141
|
+
var TimesIcon = createIcon(TimesIconConfig);
|
|
130
142
|
var TimesIcon$1 = TimesIcon;
|
|
131
143
|
|
|
132
144
|
var _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "extraProps", "isScrollable"];
|
|
133
|
-
|
|
134
145
|
var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
135
146
|
var label = _ref.label,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
isRequired = _ref.isRequired,
|
|
148
|
+
selectMenuOptions = _ref.selectMenuOptions,
|
|
149
|
+
placeholder = _ref.placeholder,
|
|
150
|
+
helperText = _ref.helperText,
|
|
151
|
+
maxHeight = _ref.maxHeight,
|
|
152
|
+
_ref$isDisabled = _ref.isDisabled,
|
|
153
|
+
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
|
|
154
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
145
155
|
var _useField = formik.useField(rest),
|
|
146
|
-
|
|
147
|
-
|
|
156
|
+
meta = _useField[1];
|
|
148
157
|
var value = meta.value;
|
|
149
|
-
|
|
150
158
|
var _useFormikContext = formik.useFormikContext(),
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
isSubmitting = _useFormikContext.isSubmitting,
|
|
160
|
+
setFieldValue = _useFormikContext.setFieldValue,
|
|
161
|
+
setFieldTouched = _useFormikContext.setFieldTouched;
|
|
155
162
|
var _React$useState = React__default["default"].useState(false),
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
isOpen = _React$useState[0],
|
|
164
|
+
setIsOpen = _React$useState[1];
|
|
159
165
|
var _React$useState2 = React__default["default"].useState(''),
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
inputValue = _React$useState2[0],
|
|
167
|
+
setInputValue = _React$useState2[1];
|
|
163
168
|
var _React$useState3 = React__default["default"].useState([]),
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
selected = _React$useState3[0],
|
|
170
|
+
setSelected = _React$useState3[1];
|
|
167
171
|
var _React$useState4 = React__default["default"].useState(selectMenuOptions),
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
selectOptions = _React$useState4[0],
|
|
173
|
+
setSelectOptions = _React$useState4[1];
|
|
171
174
|
var _React$useState5 = React__default["default"].useState(null),
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
focusedItemIndex = _React$useState5[0],
|
|
176
|
+
setFocusedItemIndex = _React$useState5[1];
|
|
175
177
|
var _React$useState6 = React__default["default"].useState(null),
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
activeItemId = _React$useState6[0],
|
|
179
|
+
setActiveItemId = _React$useState6[1];
|
|
179
180
|
var textInputRef = React__default["default"].useRef();
|
|
180
181
|
var NO_RESULTS = 'no results';
|
|
181
182
|
React__default["default"].useEffect(function () {
|
|
182
|
-
|
|
183
|
-
|
|
183
|
+
if (textInputRef != null && textInputRef.current && isRequired !== undefined) {
|
|
184
|
+
textInputRef.current.setAttribute('aria-required', String(isRequired));
|
|
185
|
+
}
|
|
186
|
+
}, [isRequired, textInputRef.current]);
|
|
187
|
+
React__default["default"].useEffect(function () {
|
|
188
|
+
var newSelectOptions = selectMenuOptions;
|
|
189
|
+
// Filter menu items based on the text input value when one exists
|
|
184
190
|
if (inputValue) {
|
|
185
191
|
newSelectOptions = selectMenuOptions.filter(function (menuItem) {
|
|
186
192
|
return String(menuItem.children).toLowerCase().includes(inputValue.toLowerCase());
|
|
187
|
-
});
|
|
188
|
-
|
|
193
|
+
});
|
|
194
|
+
// When no options are found after filtering, display 'No results found'
|
|
189
195
|
if (!newSelectOptions.length) {
|
|
190
196
|
newSelectOptions = [{
|
|
191
197
|
isAriaDisabled: true,
|
|
192
198
|
children: "No results found for \"" + inputValue + "\"",
|
|
193
199
|
value: NO_RESULTS
|
|
194
200
|
}];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
201
|
+
}
|
|
202
|
+
// Open the menu when the input value changes and the new value is not empty
|
|
198
203
|
if (!isOpen) {
|
|
199
204
|
setIsOpen(true);
|
|
200
205
|
}
|
|
201
206
|
}
|
|
202
|
-
|
|
203
207
|
setSelectOptions(newSelectOptions);
|
|
204
208
|
}, [inputValue, isOpen, selectMenuOptions]);
|
|
205
209
|
React__default["default"].useEffect(function () {
|
|
@@ -208,27 +212,22 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
208
212
|
setSelected(value);
|
|
209
213
|
}
|
|
210
214
|
}, [rest.name, value, setFieldValue]);
|
|
211
|
-
|
|
212
215
|
var createItemId = function createItemId(value) {
|
|
213
216
|
return "select-multi-typeahead-" + value.replace(' ', '-');
|
|
214
217
|
};
|
|
215
|
-
|
|
216
218
|
var setActiveAndFocusedItem = function setActiveAndFocusedItem(itemIndex) {
|
|
217
219
|
setFocusedItemIndex(itemIndex);
|
|
218
220
|
var focusedItem = selectOptions[itemIndex];
|
|
219
221
|
setActiveItemId(createItemId(focusedItem.value));
|
|
220
222
|
};
|
|
221
|
-
|
|
222
223
|
var resetActiveAndFocusedItem = function resetActiveAndFocusedItem() {
|
|
223
224
|
setFocusedItemIndex(null);
|
|
224
225
|
setActiveItemId(null);
|
|
225
226
|
};
|
|
226
|
-
|
|
227
227
|
var closeMenu = function closeMenu() {
|
|
228
228
|
setIsOpen(false);
|
|
229
229
|
resetActiveAndFocusedItem();
|
|
230
230
|
};
|
|
231
|
-
|
|
232
231
|
var onInputClick = function onInputClick() {
|
|
233
232
|
if (!isOpen) {
|
|
234
233
|
setIsOpen(true);
|
|
@@ -236,10 +235,8 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
236
235
|
closeMenu();
|
|
237
236
|
}
|
|
238
237
|
};
|
|
239
|
-
|
|
240
238
|
var _onSelect = function onSelect(value) {
|
|
241
239
|
var _textInputRef$current;
|
|
242
|
-
|
|
243
240
|
if (value && value !== NO_RESULTS) {
|
|
244
241
|
var selectedValues = selected.includes(value) ? selected.filter(function (selection) {
|
|
245
242
|
return selection !== value;
|
|
@@ -247,86 +244,68 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
247
244
|
setSelected(selectedValues);
|
|
248
245
|
setFieldTouched(rest.name, true, false);
|
|
249
246
|
setFieldValue(rest.name, selectedValues, true);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
(_textInputRef$current = textInputRef.current) == null ? void 0 : _textInputRef$current.focus();
|
|
247
|
+
}
|
|
248
|
+
// eslint-disable-next-line no-unused-expressions
|
|
249
|
+
(_textInputRef$current = textInputRef.current) == null || _textInputRef$current.focus();
|
|
254
250
|
};
|
|
255
|
-
|
|
256
251
|
var onTextInputChange = function onTextInputChange(_event, value) {
|
|
257
252
|
setInputValue(value);
|
|
258
253
|
resetActiveAndFocusedItem();
|
|
259
254
|
};
|
|
260
|
-
|
|
261
255
|
var handleMenuArrowKeys = function handleMenuArrowKeys(key) {
|
|
262
256
|
var indexToFocus = 0;
|
|
263
|
-
|
|
264
257
|
if (!isOpen) {
|
|
265
258
|
setIsOpen(true);
|
|
266
259
|
}
|
|
267
|
-
|
|
268
260
|
if (selectOptions.every(function (option) {
|
|
269
261
|
return option.isDisabled;
|
|
270
262
|
})) {
|
|
271
263
|
return;
|
|
272
264
|
}
|
|
273
|
-
|
|
274
265
|
if (key === 'ArrowUp') {
|
|
275
266
|
// When no index is set or at the first index, focus to the last, otherwise decrement focus index
|
|
276
267
|
if (focusedItemIndex === null || focusedItemIndex === 0) {
|
|
277
268
|
indexToFocus = selectOptions.length - 1;
|
|
278
269
|
} else {
|
|
279
270
|
indexToFocus = focusedItemIndex - 1;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
271
|
+
}
|
|
272
|
+
// Skip disabled options
|
|
283
273
|
while (selectOptions[indexToFocus].isDisabled) {
|
|
284
274
|
indexToFocus--;
|
|
285
|
-
|
|
286
275
|
if (indexToFocus === -1) {
|
|
287
276
|
indexToFocus = selectOptions.length - 1;
|
|
288
277
|
}
|
|
289
278
|
}
|
|
290
279
|
}
|
|
291
|
-
|
|
292
280
|
if (key === 'ArrowDown') {
|
|
293
281
|
// When no index is set or at the last index, focus to the first, otherwise increment focus index
|
|
294
282
|
if (focusedItemIndex === null || focusedItemIndex === selectOptions.length - 1) {
|
|
295
283
|
indexToFocus = 0;
|
|
296
284
|
} else {
|
|
297
285
|
indexToFocus = focusedItemIndex + 1;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
286
|
+
}
|
|
287
|
+
// Skip disabled options
|
|
301
288
|
while (selectOptions[indexToFocus].isDisabled) {
|
|
302
289
|
indexToFocus++;
|
|
303
|
-
|
|
304
290
|
if (indexToFocus === selectOptions.length) {
|
|
305
291
|
indexToFocus = 0;
|
|
306
292
|
}
|
|
307
293
|
}
|
|
308
294
|
}
|
|
309
|
-
|
|
310
295
|
setActiveAndFocusedItem(indexToFocus);
|
|
311
296
|
};
|
|
312
|
-
|
|
313
297
|
var onInputKeyDown = function onInputKeyDown(event) {
|
|
314
298
|
var focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
|
|
315
|
-
|
|
316
299
|
switch (event.key) {
|
|
317
300
|
case 'Enter':
|
|
318
301
|
event.preventDefault();
|
|
319
|
-
|
|
320
302
|
if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
|
|
321
303
|
_onSelect(focusedItem.value);
|
|
322
304
|
}
|
|
323
|
-
|
|
324
305
|
if (!isOpen) {
|
|
325
306
|
setIsOpen(true);
|
|
326
307
|
}
|
|
327
|
-
|
|
328
308
|
break;
|
|
329
|
-
|
|
330
309
|
case 'ArrowUp':
|
|
331
310
|
case 'ArrowDown':
|
|
332
311
|
event.preventDefault();
|
|
@@ -334,33 +313,26 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
334
313
|
break;
|
|
335
314
|
}
|
|
336
315
|
};
|
|
337
|
-
|
|
338
316
|
var onToggleClick = function onToggleClick() {
|
|
339
317
|
var _textInputRef$current2;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
textInputRef == null ? void 0 : (_textInputRef$current2 = textInputRef.current) == null ? void 0 : _textInputRef$current2.focus();
|
|
318
|
+
setIsOpen(!isOpen);
|
|
319
|
+
// eslint-disable-next-line no-unused-expressions
|
|
320
|
+
textInputRef == null || (_textInputRef$current2 = textInputRef.current) == null || _textInputRef$current2.focus();
|
|
344
321
|
};
|
|
345
|
-
|
|
346
322
|
var onClearButtonClick = function onClearButtonClick() {
|
|
347
323
|
var _textInputRef$current3;
|
|
348
|
-
|
|
349
324
|
setSelected([]);
|
|
350
325
|
setInputValue('');
|
|
351
326
|
resetActiveAndFocusedItem();
|
|
352
|
-
textInputRef == null
|
|
327
|
+
textInputRef == null || (_textInputRef$current3 = textInputRef.current) == null || _textInputRef$current3.focus();
|
|
353
328
|
setFieldValue(rest.name, [], true);
|
|
354
329
|
};
|
|
355
|
-
|
|
356
330
|
var getChildren = function getChildren(value) {
|
|
357
331
|
var _selectMenuOptions$fi;
|
|
358
|
-
|
|
359
332
|
return (_selectMenuOptions$fi = selectMenuOptions.find(function (option) {
|
|
360
333
|
return option.value === value;
|
|
361
334
|
})) == null ? void 0 : _selectMenuOptions$fi.children;
|
|
362
335
|
};
|
|
363
|
-
|
|
364
336
|
var toggle = function toggle(toggleRef) {
|
|
365
337
|
return React__default["default"].createElement(reactCore.MenuToggle, {
|
|
366
338
|
variant: 'typeahead',
|
|
@@ -394,7 +366,6 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
394
366
|
key: index,
|
|
395
367
|
onClick: function onClick(ev) {
|
|
396
368
|
ev.stopPropagation();
|
|
397
|
-
|
|
398
369
|
_onSelect(selection);
|
|
399
370
|
}
|
|
400
371
|
}, getChildren(selection));
|
|
@@ -410,7 +381,6 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
|
|
|
410
381
|
"aria-hidden": true
|
|
411
382
|
})))));
|
|
412
383
|
};
|
|
413
|
-
|
|
414
384
|
return React__default["default"].createElement(formGroupContainer.FormGroupContainer, {
|
|
415
385
|
validated: meta.touched && meta.error ? reactCore.ValidatedOptions.error : reactCore.ValidatedOptions["default"],
|
|
416
386
|
helperTextInvalid: meta.error,
|
package/dist/index.modern.js
CHANGED
|
@@ -5,36 +5,22 @@ import { FormGroupContainer } from '@rhc-shared-components/form-group-container'
|
|
|
5
5
|
import { useField, useFormikContext } from 'formik';
|
|
6
6
|
|
|
7
7
|
function _extends() {
|
|
8
|
-
_extends = Object.assign
|
|
9
|
-
for (var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
for (var key in source) {
|
|
13
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
14
|
-
target[key] = source[key];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
8
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
9
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
10
|
+
var t = arguments[e];
|
|
11
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return _extends.apply(this, arguments);
|
|
13
|
+
return n;
|
|
14
|
+
}, _extends.apply(null, arguments);
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
32
|
-
key = sourceKeys[i];
|
|
33
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
34
|
-
target[key] = source[key];
|
|
16
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
17
|
+
if (null == r) return {};
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
20
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
21
|
+
t[n] = r[n];
|
|
35
22
|
}
|
|
36
|
-
|
|
37
|
-
return target;
|
|
23
|
+
return t;
|
|
38
24
|
}
|
|
39
25
|
|
|
40
26
|
/******************************************************************************
|
|
@@ -51,19 +37,14 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
51
37
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
52
38
|
PERFORMANCE OF THIS SOFTWARE.
|
|
53
39
|
***************************************************************************** */
|
|
54
|
-
|
|
55
40
|
function __rest(s, e) {
|
|
56
41
|
var t = {};
|
|
57
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
62
|
-
t[p[i]] = s[p[i]];
|
|
63
|
-
}
|
|
42
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
43
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
44
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
45
|
+
}
|
|
64
46
|
return t;
|
|
65
47
|
}
|
|
66
|
-
|
|
67
48
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
68
49
|
var e = new Error(message);
|
|
69
50
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -73,25 +54,46 @@ let currentId = 0;
|
|
|
73
54
|
/**
|
|
74
55
|
* Factory to create Icon class components for consumers
|
|
75
56
|
*/
|
|
76
|
-
function createIcon({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
57
|
+
function createIcon({
|
|
58
|
+
name,
|
|
59
|
+
xOffset = 0,
|
|
60
|
+
yOffset = 0,
|
|
61
|
+
width,
|
|
62
|
+
height,
|
|
63
|
+
svgPath
|
|
64
|
+
}) {
|
|
65
|
+
var _a;
|
|
66
|
+
return _a = class SVGIcon extends React.Component {
|
|
67
|
+
constructor() {
|
|
68
|
+
super(...arguments);
|
|
69
|
+
this.id = `icon-title-${currentId++}`;
|
|
70
|
+
}
|
|
71
|
+
render() {
|
|
72
|
+
const _b = this.props,
|
|
73
|
+
{
|
|
74
|
+
title,
|
|
75
|
+
className
|
|
76
|
+
} = _b,
|
|
77
|
+
props = __rest(_b, ["title", "className"]);
|
|
78
|
+
const classes = className ? `pf-v5-svg ${className}` : 'pf-v5-svg';
|
|
79
|
+
const hasTitle = Boolean(title);
|
|
80
|
+
const viewBox = [xOffset, yOffset, width, height].join(' ');
|
|
81
|
+
return React.createElement("svg", Object.assign({
|
|
82
|
+
className: classes,
|
|
83
|
+
viewBox: viewBox,
|
|
84
|
+
fill: "currentColor",
|
|
85
|
+
"aria-labelledby": hasTitle ? this.id : null,
|
|
86
|
+
"aria-hidden": hasTitle ? null : true,
|
|
87
|
+
role: "img",
|
|
88
|
+
width: "1em",
|
|
89
|
+
height: "1em"
|
|
90
|
+
}, props), hasTitle && React.createElement("title", {
|
|
91
|
+
id: this.id
|
|
92
|
+
}, title), React.createElement("path", {
|
|
93
|
+
d: svgPath
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
}, _a.displayName = name, _a;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
const TimesIconConfig = {
|
|
@@ -100,28 +102,24 @@ const TimesIconConfig = {
|
|
|
100
102
|
width: 352,
|
|
101
103
|
svgPath: 'M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z',
|
|
102
104
|
yOffset: 0,
|
|
103
|
-
xOffset: 0
|
|
105
|
+
xOffset: 0
|
|
104
106
|
};
|
|
105
|
-
|
|
106
107
|
const TimesIcon = createIcon(TimesIconConfig);
|
|
107
|
-
|
|
108
108
|
var TimesIcon$1 = TimesIcon;
|
|
109
109
|
|
|
110
110
|
const _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "extraProps", "isScrollable"];
|
|
111
|
-
|
|
112
111
|
const FormMultiSelectInput = _ref => {
|
|
113
112
|
let {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
label,
|
|
114
|
+
isRequired,
|
|
115
|
+
selectMenuOptions,
|
|
116
|
+
ariaLabel = 'Select a value',
|
|
117
|
+
placeholder,
|
|
118
|
+
helperText,
|
|
119
|
+
maxHeight,
|
|
120
|
+
isDisabled = false
|
|
121
|
+
} = _ref,
|
|
122
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
125
123
|
const [, meta] = useField(rest);
|
|
126
124
|
const {
|
|
127
125
|
value
|
|
@@ -140,25 +138,28 @@ const FormMultiSelectInput = _ref => {
|
|
|
140
138
|
const textInputRef = React__default.useRef();
|
|
141
139
|
const NO_RESULTS = 'no results';
|
|
142
140
|
React__default.useEffect(() => {
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
if (textInputRef != null && textInputRef.current && isRequired !== undefined) {
|
|
142
|
+
textInputRef.current.setAttribute('aria-required', String(isRequired));
|
|
143
|
+
}
|
|
144
|
+
}, [isRequired, textInputRef.current]);
|
|
145
|
+
React__default.useEffect(() => {
|
|
146
|
+
let newSelectOptions = selectMenuOptions;
|
|
147
|
+
// Filter menu items based on the text input value when one exists
|
|
145
148
|
if (inputValue) {
|
|
146
|
-
newSelectOptions = selectMenuOptions.filter(menuItem => String(menuItem.children).toLowerCase().includes(inputValue.toLowerCase()));
|
|
147
|
-
|
|
149
|
+
newSelectOptions = selectMenuOptions.filter(menuItem => String(menuItem.children).toLowerCase().includes(inputValue.toLowerCase()));
|
|
150
|
+
// When no options are found after filtering, display 'No results found'
|
|
148
151
|
if (!newSelectOptions.length) {
|
|
149
152
|
newSelectOptions = [{
|
|
150
153
|
isAriaDisabled: true,
|
|
151
154
|
children: `No results found for "${inputValue}"`,
|
|
152
155
|
value: NO_RESULTS
|
|
153
156
|
}];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
+
}
|
|
158
|
+
// Open the menu when the input value changes and the new value is not empty
|
|
157
159
|
if (!isOpen) {
|
|
158
160
|
setIsOpen(true);
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
|
-
|
|
162
163
|
setSelectOptions(newSelectOptions);
|
|
163
164
|
}, [inputValue, isOpen, selectMenuOptions]);
|
|
164
165
|
React__default.useEffect(() => {
|
|
@@ -167,25 +168,20 @@ const FormMultiSelectInput = _ref => {
|
|
|
167
168
|
setSelected(value);
|
|
168
169
|
}
|
|
169
170
|
}, [rest.name, value, setFieldValue]);
|
|
170
|
-
|
|
171
171
|
const createItemId = value => `select-multi-typeahead-${value.replace(' ', '-')}`;
|
|
172
|
-
|
|
173
172
|
const setActiveAndFocusedItem = itemIndex => {
|
|
174
173
|
setFocusedItemIndex(itemIndex);
|
|
175
174
|
const focusedItem = selectOptions[itemIndex];
|
|
176
175
|
setActiveItemId(createItemId(focusedItem.value));
|
|
177
176
|
};
|
|
178
|
-
|
|
179
177
|
const resetActiveAndFocusedItem = () => {
|
|
180
178
|
setFocusedItemIndex(null);
|
|
181
179
|
setActiveItemId(null);
|
|
182
180
|
};
|
|
183
|
-
|
|
184
181
|
const closeMenu = () => {
|
|
185
182
|
setIsOpen(false);
|
|
186
183
|
resetActiveAndFocusedItem();
|
|
187
184
|
};
|
|
188
|
-
|
|
189
185
|
const onInputClick = () => {
|
|
190
186
|
if (!isOpen) {
|
|
191
187
|
setIsOpen(true);
|
|
@@ -193,93 +189,73 @@ const FormMultiSelectInput = _ref => {
|
|
|
193
189
|
closeMenu();
|
|
194
190
|
}
|
|
195
191
|
};
|
|
196
|
-
|
|
197
192
|
const onSelect = value => {
|
|
198
193
|
var _textInputRef$current;
|
|
199
|
-
|
|
200
194
|
if (value && value !== NO_RESULTS) {
|
|
201
195
|
const selectedValues = selected.includes(value) ? selected.filter(selection => selection !== value) : [...selected, value];
|
|
202
196
|
setSelected(selectedValues);
|
|
203
197
|
setFieldTouched(rest.name, true, false);
|
|
204
198
|
setFieldValue(rest.name, selectedValues, true);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
(_textInputRef$current = textInputRef.current) == null ? void 0 : _textInputRef$current.focus();
|
|
199
|
+
}
|
|
200
|
+
// eslint-disable-next-line no-unused-expressions
|
|
201
|
+
(_textInputRef$current = textInputRef.current) == null || _textInputRef$current.focus();
|
|
209
202
|
};
|
|
210
|
-
|
|
211
203
|
const onTextInputChange = (_event, value) => {
|
|
212
204
|
setInputValue(value);
|
|
213
205
|
resetActiveAndFocusedItem();
|
|
214
206
|
};
|
|
215
|
-
|
|
216
207
|
const handleMenuArrowKeys = key => {
|
|
217
208
|
let indexToFocus = 0;
|
|
218
|
-
|
|
219
209
|
if (!isOpen) {
|
|
220
210
|
setIsOpen(true);
|
|
221
211
|
}
|
|
222
|
-
|
|
223
212
|
if (selectOptions.every(option => option.isDisabled)) {
|
|
224
213
|
return;
|
|
225
214
|
}
|
|
226
|
-
|
|
227
215
|
if (key === 'ArrowUp') {
|
|
228
216
|
// When no index is set or at the first index, focus to the last, otherwise decrement focus index
|
|
229
217
|
if (focusedItemIndex === null || focusedItemIndex === 0) {
|
|
230
218
|
indexToFocus = selectOptions.length - 1;
|
|
231
219
|
} else {
|
|
232
220
|
indexToFocus = focusedItemIndex - 1;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
221
|
+
}
|
|
222
|
+
// Skip disabled options
|
|
236
223
|
while (selectOptions[indexToFocus].isDisabled) {
|
|
237
224
|
indexToFocus--;
|
|
238
|
-
|
|
239
225
|
if (indexToFocus === -1) {
|
|
240
226
|
indexToFocus = selectOptions.length - 1;
|
|
241
227
|
}
|
|
242
228
|
}
|
|
243
229
|
}
|
|
244
|
-
|
|
245
230
|
if (key === 'ArrowDown') {
|
|
246
231
|
// When no index is set or at the last index, focus to the first, otherwise increment focus index
|
|
247
232
|
if (focusedItemIndex === null || focusedItemIndex === selectOptions.length - 1) {
|
|
248
233
|
indexToFocus = 0;
|
|
249
234
|
} else {
|
|
250
235
|
indexToFocus = focusedItemIndex + 1;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
236
|
+
}
|
|
237
|
+
// Skip disabled options
|
|
254
238
|
while (selectOptions[indexToFocus].isDisabled) {
|
|
255
239
|
indexToFocus++;
|
|
256
|
-
|
|
257
240
|
if (indexToFocus === selectOptions.length) {
|
|
258
241
|
indexToFocus = 0;
|
|
259
242
|
}
|
|
260
243
|
}
|
|
261
244
|
}
|
|
262
|
-
|
|
263
245
|
setActiveAndFocusedItem(indexToFocus);
|
|
264
246
|
};
|
|
265
|
-
|
|
266
247
|
const onInputKeyDown = event => {
|
|
267
248
|
const focusedItem = focusedItemIndex !== null ? selectOptions[focusedItemIndex] : null;
|
|
268
|
-
|
|
269
249
|
switch (event.key) {
|
|
270
250
|
case 'Enter':
|
|
271
251
|
event.preventDefault();
|
|
272
|
-
|
|
273
252
|
if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
|
|
274
253
|
onSelect(focusedItem.value);
|
|
275
254
|
}
|
|
276
|
-
|
|
277
255
|
if (!isOpen) {
|
|
278
256
|
setIsOpen(true);
|
|
279
257
|
}
|
|
280
|
-
|
|
281
258
|
break;
|
|
282
|
-
|
|
283
259
|
case 'ArrowUp':
|
|
284
260
|
case 'ArrowDown':
|
|
285
261
|
event.preventDefault();
|
|
@@ -287,31 +263,24 @@ const FormMultiSelectInput = _ref => {
|
|
|
287
263
|
break;
|
|
288
264
|
}
|
|
289
265
|
};
|
|
290
|
-
|
|
291
266
|
const onToggleClick = () => {
|
|
292
267
|
var _textInputRef$current2;
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
textInputRef == null ? void 0 : (_textInputRef$current2 = textInputRef.current) == null ? void 0 : _textInputRef$current2.focus();
|
|
268
|
+
setIsOpen(!isOpen);
|
|
269
|
+
// eslint-disable-next-line no-unused-expressions
|
|
270
|
+
textInputRef == null || (_textInputRef$current2 = textInputRef.current) == null || _textInputRef$current2.focus();
|
|
297
271
|
};
|
|
298
|
-
|
|
299
272
|
const onClearButtonClick = () => {
|
|
300
273
|
var _textInputRef$current3;
|
|
301
|
-
|
|
302
274
|
setSelected([]);
|
|
303
275
|
setInputValue('');
|
|
304
276
|
resetActiveAndFocusedItem();
|
|
305
|
-
textInputRef == null
|
|
277
|
+
textInputRef == null || (_textInputRef$current3 = textInputRef.current) == null || _textInputRef$current3.focus();
|
|
306
278
|
setFieldValue(rest.name, [], true);
|
|
307
279
|
};
|
|
308
|
-
|
|
309
280
|
const getChildren = value => {
|
|
310
281
|
var _selectMenuOptions$fi;
|
|
311
|
-
|
|
312
282
|
return (_selectMenuOptions$fi = selectMenuOptions.find(option => option.value === value)) == null ? void 0 : _selectMenuOptions$fi.children;
|
|
313
283
|
};
|
|
314
|
-
|
|
315
284
|
const toggle = toggleRef => React__default.createElement(MenuToggle, {
|
|
316
285
|
variant: 'typeahead',
|
|
317
286
|
"aria-label": 'menu toggle',
|
|
@@ -356,7 +325,6 @@ const FormMultiSelectInput = _ref => {
|
|
|
356
325
|
}, React__default.createElement(TimesIcon$1, {
|
|
357
326
|
"aria-hidden": true
|
|
358
327
|
})))));
|
|
359
|
-
|
|
360
328
|
return React__default.createElement(FormGroupContainer, {
|
|
361
329
|
validated: meta.touched && meta.error ? ValidatedOptions.error : ValidatedOptions.default,
|
|
362
330
|
helperTextInvalid: meta.error,
|