@rhc-shared-components/form-multi-select-component 1.0.4 → 1.0.6

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.
@@ -11,7 +11,6 @@ export interface FormMultiSelectInputProps {
11
11
  maxHeight?: string;
12
12
  isDisabled?: boolean;
13
13
  classNames?: string;
14
- menuAppendTo?: HTMLElement | (() => HTMLElement) | 'inline' | 'parent';
15
14
  extraProps?: any;
16
15
  isScrollable?: boolean;
17
16
  }
package/dist/index.js CHANGED
@@ -129,7 +129,7 @@ const TimesIcon = createIcon(TimesIconConfig);
129
129
 
130
130
  var TimesIcon$1 = TimesIcon;
131
131
 
132
- var _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps", "isScrollable"];
132
+ var _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "extraProps", "isScrollable"];
133
133
 
134
134
  var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
135
135
  var label = _ref.label,
@@ -140,7 +140,6 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
140
140
  maxHeight = _ref.maxHeight,
141
141
  _ref$isDisabled = _ref.isDisabled,
142
142
  isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
143
- menuAppendTo = _ref.menuAppendTo,
144
143
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
145
144
 
146
145
  var _useField = formik.useField(rest),
@@ -202,13 +201,13 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
202
201
  }
203
202
 
204
203
  setSelectOptions(newSelectOptions);
205
- }, [inputValue]);
204
+ }, [inputValue, isOpen, selectMenuOptions]);
206
205
  React__default["default"].useEffect(function () {
207
206
  if ((value == null ? void 0 : value.length) > 0) {
208
207
  setFieldValue(rest.name, value, true);
209
208
  setSelected(value);
210
209
  }
211
- }, []);
210
+ }, [rest.name, value, setFieldValue]);
212
211
 
213
212
  var createItemId = function createItemId(value) {
214
213
  return "select-multi-typeahead-" + value.replace(' ', '-');
@@ -316,6 +315,8 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
316
315
 
317
316
  switch (event.key) {
318
317
  case 'Enter':
318
+ event.preventDefault();
319
+
319
320
  if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
320
321
  _onSelect(focusedItem.value);
321
322
  }
@@ -410,14 +411,14 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
410
411
  })))));
411
412
  };
412
413
 
413
- return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(formGroupContainer.FormGroupContainer, {
414
+ return React__default["default"].createElement(formGroupContainer.FormGroupContainer, {
414
415
  validated: meta.touched && meta.error ? reactCore.ValidatedOptions.error : reactCore.ValidatedOptions["default"],
415
416
  helperTextInvalid: meta.error,
416
417
  isRequired: isRequired,
417
418
  fieldId: rest.name,
418
419
  label: label,
419
420
  helperText: helperText
420
- }, React__default["default"].createElement(reactCore.Select, _extends({
421
+ }, React__default["default"].createElement(reactCore.Select, {
421
422
  id: 'multi-typeahead-select',
422
423
  isOpen: isOpen,
423
424
  selected: selected,
@@ -426,20 +427,22 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
426
427
  },
427
428
  toggle: toggle,
428
429
  isScrollable: true,
429
- maxMenuHeight: maxHeight
430
- }, menuAppendTo && {
431
- menuAppendTo: menuAppendTo
432
- }), React__default["default"].createElement(reactCore.SelectList, {
430
+ maxMenuHeight: maxHeight,
431
+ onOpenChange: function onOpenChange(isOpen) {
432
+ !isOpen && closeMenu();
433
+ }
434
+ }, React__default["default"].createElement(reactCore.SelectList, {
433
435
  isAriaMultiselectable: true,
434
436
  id: 'select-multi-typeahead-listbox'
435
437
  }, selectOptions == null ? void 0 : selectOptions.map(function (option, index) {
436
438
  return React__default["default"].createElement(reactCore.SelectOption, _extends({
437
439
  key: option.value || option.children,
438
440
  isFocused: focusedItemIndex === index,
439
- id: "select-multi-typeahead-" + option.value.replace(' ', '-'),
441
+ className: option.className,
442
+ id: createItemId(option.value),
440
443
  isDisabled: option.isDisabled || isSubmitting
441
444
  }, option));
442
- })))));
445
+ }))));
443
446
  };
444
447
 
445
448
  exports.FormMultiSelectInput = FormMultiSelectInput;
@@ -107,7 +107,7 @@ const TimesIcon = createIcon(TimesIconConfig);
107
107
 
108
108
  var TimesIcon$1 = TimesIcon;
109
109
 
110
- const _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps", "isScrollable"];
110
+ const _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "extraProps", "isScrollable"];
111
111
 
112
112
  const FormMultiSelectInput = _ref => {
113
113
  let {
@@ -118,8 +118,7 @@ const FormMultiSelectInput = _ref => {
118
118
  placeholder,
119
119
  helperText,
120
120
  maxHeight,
121
- isDisabled = false,
122
- menuAppendTo
121
+ isDisabled = false
123
122
  } = _ref,
124
123
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
125
124
 
@@ -161,13 +160,13 @@ const FormMultiSelectInput = _ref => {
161
160
  }
162
161
 
163
162
  setSelectOptions(newSelectOptions);
164
- }, [inputValue]);
163
+ }, [inputValue, isOpen, selectMenuOptions]);
165
164
  React__default.useEffect(() => {
166
165
  if ((value == null ? void 0 : value.length) > 0) {
167
166
  setFieldValue(rest.name, value, true);
168
167
  setSelected(value);
169
168
  }
170
- }, []);
169
+ }, [rest.name, value, setFieldValue]);
171
170
 
172
171
  const createItemId = value => `select-multi-typeahead-${value.replace(' ', '-')}`;
173
172
 
@@ -269,6 +268,8 @@ const FormMultiSelectInput = _ref => {
269
268
 
270
269
  switch (event.key) {
271
270
  case 'Enter':
271
+ event.preventDefault();
272
+
272
273
  if (isOpen && focusedItem && focusedItem.value !== NO_RESULTS && !focusedItem.isAriaDisabled) {
273
274
  onSelect(focusedItem.value);
274
275
  }
@@ -356,32 +357,34 @@ const FormMultiSelectInput = _ref => {
356
357
  "aria-hidden": true
357
358
  })))));
358
359
 
359
- return React__default.createElement(React__default.Fragment, null, React__default.createElement(FormGroupContainer, {
360
+ return React__default.createElement(FormGroupContainer, {
360
361
  validated: meta.touched && meta.error ? ValidatedOptions.error : ValidatedOptions.default,
361
362
  helperTextInvalid: meta.error,
362
363
  isRequired: isRequired,
363
364
  fieldId: rest.name,
364
365
  label: label,
365
366
  helperText: helperText
366
- }, React__default.createElement(Select, _extends({
367
+ }, React__default.createElement(Select, {
367
368
  id: 'multi-typeahead-select',
368
369
  isOpen: isOpen,
369
370
  selected: selected,
370
371
  onSelect: (_ev, selection) => onSelect(selection),
371
372
  toggle: toggle,
372
373
  isScrollable: true,
373
- maxMenuHeight: maxHeight
374
- }, menuAppendTo && {
375
- menuAppendTo
376
- }), React__default.createElement(SelectList, {
374
+ maxMenuHeight: maxHeight,
375
+ onOpenChange: isOpen => {
376
+ !isOpen && closeMenu();
377
+ }
378
+ }, React__default.createElement(SelectList, {
377
379
  isAriaMultiselectable: true,
378
380
  id: 'select-multi-typeahead-listbox'
379
381
  }, selectOptions == null ? void 0 : selectOptions.map((option, index) => React__default.createElement(SelectOption, _extends({
380
382
  key: option.value || option.children,
381
383
  isFocused: focusedItemIndex === index,
382
- id: `select-multi-typeahead-${option.value.replace(' ', '-')}`,
384
+ className: option.className,
385
+ id: createItemId(option.value),
383
386
  isDisabled: option.isDisabled || isSubmitting
384
- }, option)))))));
387
+ }, option))))));
385
388
  };
386
389
 
387
390
  export { FormMultiSelectInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhc-shared-components/form-multi-select-component",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "project description",
5
5
  "author": "shkale",
6
6
  "license": "MIT",