@rhc-shared-components/form-multi-select-component 1.0.1 → 1.0.3

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.
@@ -9,11 +9,12 @@ export interface FormMultiSelectInputProps {
9
9
  selectMenuOptions: IMultiSelectInputOptionProps[];
10
10
  ariaLabel?: string;
11
11
  helperText?: string;
12
- maxHeight?: string | number;
12
+ maxHeight?: string;
13
13
  isDisabled?: boolean;
14
14
  classNames?: string;
15
15
  menuAppendTo?: HTMLElement | (() => HTMLElement) | 'inline' | 'parent';
16
16
  extraProps?: any;
17
+ isScrollable?: boolean;
17
18
  }
18
19
  declare const FormMultiSelectInput: React.FunctionComponent<FormMultiSelectInputProps>;
19
20
  export { FormMultiSelectInput, IMultiSelectInputOptionProps };
package/dist/index.js CHANGED
@@ -111,7 +111,7 @@ const TimesIcon = createIcon(TimesIconConfig);
111
111
 
112
112
  var TimesIcon$1 = TimesIcon;
113
113
 
114
- var _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps"];
114
+ var _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps", "isScrollable"];
115
115
 
116
116
  var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
117
117
  var label = _ref.label,
@@ -119,6 +119,7 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
119
119
  selectMenuOptions = _ref.selectMenuOptions,
120
120
  placeholder = _ref.placeholder,
121
121
  helperText = _ref.helperText,
122
+ maxHeight = _ref.maxHeight,
122
123
  isDisabled = _ref.isDisabled,
123
124
  menuAppendTo = _ref.menuAppendTo,
124
125
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -181,9 +182,8 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
181
182
  }
182
183
 
183
184
  setSelectOptions(newSelectOptions);
184
- setFocusedItemIndex(null);
185
185
  setActiveItem(null);
186
- }, [inputValue]);
186
+ }, [inputValue, selectMenuOptions]);
187
187
  React__default["default"].useEffect(function () {
188
188
  if ((value == null ? void 0 : value.length) > 0) {
189
189
  setFieldValue(rest.name, value, true);
@@ -236,6 +236,8 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
236
236
  return !prevIsOpen;
237
237
  });
238
238
  } else if (isOpen && focusedItem.value !== 'no results') {
239
+ event.preventDefault();
240
+
239
241
  _onSelect(focusedItem.value);
240
242
  }
241
243
 
@@ -261,6 +263,7 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
261
263
 
262
264
  var onTextInputChange = function onTextInputChange(_event, value) {
263
265
  setInputValue(value);
266
+ setFocusedItemIndex(null);
264
267
  };
265
268
 
266
269
  var _onSelect = function onSelect(value) {
@@ -327,6 +330,7 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
327
330
  setSelected([]); // eslint-disable-next-line no-unused-expressions
328
331
 
329
332
  textInputRef == null ? void 0 : (_textInputRef$current2 = textInputRef.current) == null ? void 0 : _textInputRef$current2.focus();
333
+ setFieldValue(rest.name, [], true);
330
334
  },
331
335
  "aria-label": 'Clear input value'
332
336
  }, React__default["default"].createElement(TimesIcon$1, {
@@ -351,13 +355,15 @@ var FormMultiSelectInput = function FormMultiSelectInput(_ref) {
351
355
  onOpenChange: function onOpenChange() {
352
356
  return setIsOpen(false);
353
357
  },
354
- toggle: toggle
358
+ toggle: toggle,
359
+ isScrollable: true,
360
+ maxMenuHeight: maxHeight
355
361
  }, menuAppendTo && {
356
362
  menuAppendTo: menuAppendTo
357
363
  }), React__default["default"].createElement(reactCore.SelectList, {
358
364
  isAriaMultiselectable: true,
359
365
  id: 'select-multi-typeahead-listbox'
360
- }, selectOptions.map(function (option, index) {
366
+ }, selectOptions == null ? void 0 : selectOptions.map(function (option, index) {
361
367
  return React__default["default"].createElement(reactCore.SelectOption, Object.assign({
362
368
  key: option.value || option.children,
363
369
  isFocused: focusedItemIndex === index,
@@ -89,7 +89,7 @@ const TimesIcon = createIcon(TimesIconConfig);
89
89
 
90
90
  var TimesIcon$1 = TimesIcon;
91
91
 
92
- const _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps"];
92
+ const _excluded = ["label", "isRequired", "children", "selectMenuOptions", "ariaLabel", "placeholder", "helperText", "maxHeight", "isDisabled", "classNames", "menuAppendTo", "extraProps", "isScrollable"];
93
93
 
94
94
  const FormMultiSelectInput = _ref => {
95
95
  let {
@@ -99,6 +99,7 @@ const FormMultiSelectInput = _ref => {
99
99
  ariaLabel = 'Select Input',
100
100
  placeholder,
101
101
  helperText,
102
+ maxHeight,
102
103
  isDisabled,
103
104
  menuAppendTo
104
105
  } = _ref,
@@ -141,9 +142,8 @@ const FormMultiSelectInput = _ref => {
141
142
  }
142
143
 
143
144
  setSelectOptions(newSelectOptions);
144
- setFocusedItemIndex(null);
145
145
  setActiveItem(null);
146
- }, [inputValue]);
146
+ }, [inputValue, selectMenuOptions]);
147
147
  React__default.useEffect(() => {
148
148
  if ((value == null ? void 0 : value.length) > 0) {
149
149
  setFieldValue(rest.name, value, true);
@@ -190,6 +190,7 @@ const FormMultiSelectInput = _ref => {
190
190
  if (!isOpen) {
191
191
  setIsOpen(prevIsOpen => !prevIsOpen);
192
192
  } else if (isOpen && focusedItem.value !== 'no results') {
193
+ event.preventDefault();
193
194
  onSelect(focusedItem.value);
194
195
  }
195
196
 
@@ -215,6 +216,7 @@ const FormMultiSelectInput = _ref => {
215
216
 
216
217
  const onTextInputChange = (_event, value) => {
217
218
  setInputValue(value);
219
+ setFocusedItemIndex(null);
218
220
  };
219
221
 
220
222
  const onSelect = value => {
@@ -275,6 +277,7 @@ const FormMultiSelectInput = _ref => {
275
277
  setSelected([]); // eslint-disable-next-line no-unused-expressions
276
278
 
277
279
  textInputRef == null ? void 0 : (_textInputRef$current2 = textInputRef.current) == null ? void 0 : _textInputRef$current2.focus();
280
+ setFieldValue(rest.name, [], true);
278
281
  },
279
282
  "aria-label": 'Clear input value'
280
283
  }, React__default.createElement(TimesIcon$1, {
@@ -294,13 +297,15 @@ const FormMultiSelectInput = _ref => {
294
297
  selected: selected,
295
298
  onSelect: (_ev, selection) => onSelect(selection),
296
299
  onOpenChange: () => setIsOpen(false),
297
- toggle: toggle
300
+ toggle: toggle,
301
+ isScrollable: true,
302
+ maxMenuHeight: maxHeight
298
303
  }, menuAppendTo && {
299
304
  menuAppendTo
300
305
  }), React__default.createElement(SelectList, {
301
306
  isAriaMultiselectable: true,
302
307
  id: 'select-multi-typeahead-listbox'
303
- }, selectOptions.map((option, index) => React__default.createElement(SelectOption, Object.assign({
308
+ }, selectOptions == null ? void 0 : selectOptions.map((option, index) => React__default.createElement(SelectOption, Object.assign({
304
309
  key: option.value || option.children,
305
310
  isFocused: focusedItemIndex === index,
306
311
  id: `select-multi-typeahead-${option.value.replace(' ', '-')}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhc-shared-components/form-multi-select-component",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "project description",
5
5
  "author": "shkale",
6
6
  "license": "MIT",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@patternfly/react-core": "5.3.0",
66
- "@rhc-shared-components/form-group-container": "^0.4.0",
66
+ "@rhc-shared-components/form-group-container": "^1.0.1",
67
67
  "@types/lodash": "^4.14.177",
68
68
  "formik": "^2.1.4",
69
69
  "lodash": "^4.17.21",