-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathMultiSelection.js
737 lines (705 loc) · 25.7 KB
/
MultiSelection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
import React, { useRef, useEffect, useState, useMemo, useCallback } from 'react';
import PropTypes from 'prop-types';
import { deprecated } from 'prop-types-extra';
import classnames from 'classnames';
import {
isEqual,
noop,
debounce,
} from 'lodash';
import { useIntl } from 'react-intl';
import { useMultipleSelection, useCombobox } from 'downshift';
import { OVERLAY_MODIFIERS } from '../Popper';
import SelectedValuesList from './SelectedValuesList';
import MultiSelectFilterField from './MultiSelectFilterField';
import MultiSelectResponsiveRenderer from './MultiSelectResponsiveRenderer';
import SelectOption from './SelectOption';
import MultiSelectOptionsList from './MultiSelectOptionsList';
import ValueChip from './ValueChip';
import DefaultOptionFormatter from '../Selection/DefaultOptionFormatter';
import SRStatus from '../SRStatus';
import TextFieldIcon from '../TextField/TextFieldIcon';
import sharedInputStylesHelper from '../sharedStyles/sharedInputStylesHelper';
import formField from '../FormField';
import Label from '../Label';
import { Loading } from '../Loading';
import parseMeta from '../FormField/parseMeta';
import useProvidedIdOrCreate from '../../hooks/useProvidedIdOrCreate';
import css from './MultiSelect.css';
import formStyles from '../sharedStyles/form.css';
import useProvidedRefOrCreate from '../../hooks/useProvidedRefOrCreate';
const filterOptions = (filterText, list) => {
// escape special characters in filter text, so they won't be interpreted by RegExp
const escapedFilterText = filterText?.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&');
const filterRegExp = new RegExp(`^${escapedFilterText}`, 'i');
const renderedItems = filterText ? list.filter(item => item.label.search(filterRegExp) !== -1) : list;
const exactMatch = filterText ? (renderedItems.filter(item => item.label === filterText).length === 1) : false;
return { renderedItems, exactMatch };
};
const dbResize = debounce(
(cb) => cb(window.matchMedia('(max-width: 640px)').matches), { leading: false, trailing: true }
);
const getContainerWidth = (container) => { // eslint-disable-line consistent-return
return container.current?.offsetWidth || 100;
};
// handleSelection - addition/removal of selected options, also ensures selected
// options are deduped.
const handleSelection = (selectedItem, selectedItems, removeSelectedItem, addSelectedItem, onAdd) => {
const selectedIndex = selectedItems.findIndex((item) => isEqual(item, selectedItem));
if (selectedIndex !== -1) {
removeSelectedItem(selectedItem);
} else {
addSelectedItem(selectedItem);
onAdd(selectedItem);
}
};
const handleRemoval = (selectedItems, newSelectedItems, onRemove) => {
if (selectedItems.length !== 0) {
const removed = selectedItems.filter(old => newSelectedItems.findIndex(newItem => isEqual(old, newItem)) < 0)
if (removed.length > 0) {
onRemove(removed[0]);
}
}
};
const MultiSelection = ({
actions = [],
asyncFiltering = false,
autoFocus = false,
backspaceDeletes = true,
dataOptions = [],
dirty,
disabled,
emptyMessage: emptyMessageProp,
error,
filter = filterOptions,
formatter = DefaultOptionFormatter,
id,
inputRef,
isValid,
itemToString = option => (option ? option.label : ''),
label: labelProp,
maxHeight = 168,
marginBottom0,
modifiers = OVERLAY_MODIFIERS,
noBorder,
onAdd = noop,
onBlur = noop,
onChange = noop,
onFocus = noop,
onRemove = noop,
placeholder,
renderToOverlay = false,
required = false,
showLoading,
usePortal,
validationEnabled,
validStylesEnabled = false,
value,
valueFormatter,
warning,
...rest
}) => {
const { formatMessage } = useIntl();
const [atSmallMedia, setAtSmallMedia] = useState(window.matchMedia('(max-width: 640px)').matches);
const [filterFocused, setFilterFocused] = useState(false);
const [filterValue, setFilterValue] = useState('');
const awaitingChange = useRef(false);
const userSelection = useRef(null);
const container = useRef(null);
const control = useRef(null);
const input = useProvidedRefOrCreate(inputRef);
const selectedList = useRef(null);
const srStat = useRef(null);
const uiId = useProvidedIdOrCreate(id, 'multiselect-');
const ariaLabelledBy = useRef(rest['aria-labelledby'] || rest.ariaLabelledby || rest.ariaLabelledBy).current;
const valueLabelId = useRef(`multi-value-${uiId}`).current;
const valueListId = useRef(`multi-values-list-${uiId}`).current;
const valueDescriptionId = useRef(`multi-describe-action-${uiId}`).current;
const controlDescriptionId = useRef(`multi-describe-control-${uiId}`).current;
const controlValueStatusId = useRef(`multi-value-status-${uiId}`).current;
const ariaLabel = useRef(rest.ariaLabel || rest['aria-label']).current;
const labelId = useRef(`${uiId}-label`).current;
const label = useRef(labelProp || ariaLabel || rest['aria-label']).current;
const actionId = useRef(`multiselect-action-${uiId}`).current;
const menuId = useRef(`multiselect-option-list-${uiId}`).current;
const valueInputId = useRef(`multiselect-input-${uiId}`).current;
const filterId = useRef(`${uiId}-input`).current;
const dbFilter = useRef(debounce(filter, 300, { leading: false, trailing: true })).current;
const emptyMessage = useRef(
emptyMessageProp ||
formatMessage({ id: 'stripes-components.multiSelection.defaultEmptyMessage' })
).current;
const options = useMemo(
() => (asyncFiltering ? { renderedItems: dataOptions || [], exactMatch: false } : filter(filterValue, dataOptions)),
[asyncFiltering, filterValue, dataOptions, filter]
);
// This component makes use of useMultiSelection and useCombobox hooks from downshift.
// useMultiSelection manages the list of selected items. It provides methods to add/remove affect that state.
// useCombobox manages the other state of other interactions with the component -
// cursor position,
// open/closed state of the menu
// keyboard handlers/prop getters.
const {
getDropdownProps, // apply attributes to input or button trigger for dropdown
removeSelectedItem, // handler for removing the item from selected items
addSelectedItem, // handler for adding the item from selected items
selectedItems, // downshift manages this state.
setSelectedItems, // used only when the value changes from the outside of the component.
} = useMultipleSelection({
initialSelectedItems: value || [],
itemToKey: itemToString, /* used by downshift's internal equality checker. We override it because it would default
a strict equals on objects which probably won't succeed. itemToString will
boil each object down to a string, so that the strict-equals will
have a better time succeeding. */
onSelectedItemsChange(changes) {
// only trigger onChange if selectedItems is different from from the incoming value prop.
// this avoids instances when the value can appear *not to change for the user but it's really the cause of
// values just changing between re-renders and react just catching whichever onChange was triggered last.
if (typeof value === 'undefined') {
// since 'undefined' isn't [], it will never pass the equality check, so to account
// for a change to 'undefined', we need a special case.
if (changes.selectedItems.length !== 0) {
onChange(changes.selectedItems);
}
} else if (!isEqual(value, changes.selectedItems)) {
onChange(changes.selectedItems);
}
},
// since we want the component to discern between internal changes
// and external changes in the selected item,
// we catch the internal changes with this function and flag the 'awaitingChange' ref to let
// state-syncing logic know the change happened internally, so we don't expect the value prop to sync until
// our `onChange` has been called...
stateReducer(state, actionAndChanges) {
const { changes, type } = actionAndChanges;
switch (type) {
// backspace removal of slected items is handled here...
case useMultipleSelection.stateChangeTypes
.SelectedItemKeyDownBackspace:
case useMultipleSelection.stateChangeTypes
.DropdownKeyDownBackspace:
if (backspaceDeletes) {
handleRemoval(selectedItems, changes.selectedItems, onRemove);
awaitingChange.current = true;
userSelection.current = changes.selectedItems;
}
return changes;
case useMultipleSelection.stateChangeTypes
.SelectedItemKeyDownDelete:
case useMultipleSelection.stateChangeTypes
.FunctionRemoveSelectedItem:
// this calls the onRemove handle for the variety of different ways that a selected option can be removed.
handleRemoval(selectedItems, changes.selectedItems, onRemove);
awaitingChange.current = true;
userSelection.current = changes.selectedItems;
return changes;
case useMultipleSelection.stateChangeTypes.FunctionAddSelectedItem:
userSelection.current = changes.selectedItems;
awaitingChange.current = true;
return changes;
default:
return changes;
}
}
});
const {
getLabelProps, // props for the label
getInputProps, // props for the filter input
getMenuProps, // props for the overlay element
getItemProps, // props for option items
getToggleButtonProps, // for the elements that can toggle the dropdown (the filter input, the dropdown button.)
openMenu,
isOpen, // whether dropdown is open or closed. More state managed by Downshift.
highlightedIndex, // cursor value
reset,
} = useCombobox({
defaultHighlightedIndex: 0,
selectedItem: null,
itemToString,
inputValue: null,
items: [...options.renderedItems, ...actions],
onStateChange({
type,
selectedItem: newSelectedItem,
}) {
switch (type) {
case useCombobox.stateChangeTypes.InputKeyDownEnter:
case useCombobox.stateChangeTypes.ItemClick:
if (newSelectedItem) {
// custom handler used to de-dupe selected objects. Will call the add/remove functions
// for manipulating the downshift state from useMultipleSelection.
handleSelection(
newSelectedItem,
selectedItems,
removeSelectedItem,
addSelectedItem,
onAdd
);
setFilterValue('');
}
break;
default:
break;
}
},
stateReducer(state, actionAndChanges) {
const { changes, type } = actionAndChanges
switch (type) {
case useCombobox.stateChangeTypes.InputEvent:
case useCombobox.stateChangeTypes.InputKeyDownEnter:
case useCombobox.stateChangeTypes.ItemClick:
if (changes?.selectedItem?.onSelect) {
changes.selectedItem.onSelect({
...state,
...options,
filterText: filterValue,
inputValue: filterValue,
selectedItems,
reset
});
setFilterValue('');
return {
isOpen: false, // close the menu.
highlightedIndex, // don't move highlight cursor back to top of list on selection.
}
} else {
awaitingChange.current = true;
}
return {
...changes,
isOpen: true, // keep the menu open after selection.
highlightedIndex, // don't move highlight cursor back to top of list on selection.
}
default:
return changes
}
},
});
// set up resize handler onMount...
useEffect(() => {
const resizeHandler = () => { dbResize(setAtSmallMedia) };
window.addEventListener('resize', resizeHandler);
return () => window.removeEventListener('resize', resizeHandler);
}, []);
// retain focus on filter input if we happen to switch between
// small and large screen components.
useEffect(() => {
if (filterFocused) input.current?.focus();
}, [atSmallMedia, filterFocused, input]);
// for async filtering, call filter function as a debounced after-effect of filter value changing...
useEffect(() => {
if (asyncFiltering) {
dbFilter(filterValue, dataOptions);
}
}, [filterValue, asyncFiltering, dataOptions, dbFilter]);
const handleControlClick = useCallback(() => {
if (disabled) {
return;
}
if (!isOpen) {
input.current?.focus();
openMenu();
}
}, [disabled, isOpen, input, openMenu]);
const getRemoveButtonProps = useCallback(({
onClick = () => {},
item,
...props
} = {}) => {
return {
onClick: e => {
onClick(e);
e.stopPropagation();
removeSelectedItem(item);
},
onKeyDown: e => {
switch (e.key.toLowerCase()) {
case 'end':
selectedList.current.querySelector('li:last-child button').focus();
break;
case 'home':
selectedList.current.querySelector('li:first-child button').focus();
break;
case 'left':
case 'right':
default:
}
},
...props
};
}, [removeSelectedItem]);
const controlClass = useMemo(() => {
return classnames(
css.multiSelectControl,
{
[`${css.multiSelectFocused}`]: filterFocused,
[`${formStyles.isDisabled}`]: disabled,
},
sharedInputStylesHelper({
dirty,
error,
marginBottom0,
noBorder,
valid: isValid,
validationEnabled,
validStylesEnabled,
warning
}),
);
}, [
filterFocused,
disabled,
dirty,
error,
marginBottom0,
noBorder,
isValid,
validationEnabled,
validStylesEnabled,
warning
]);
/**
* Moves focus to the filter input on desktop and the control element on mobile
* when the hidden value input is focused.
* This will typically happen when the required prop is set to true
* and the HTML5 validation kicks in on form submit.
*/
const onValueInputFocus = useCallback(() => {
if (atSmallMedia) {
control.current?.focus();
} else {
input.current?.focus();
}
srStat.current.sendMessage(formatMessage({ id: 'stripes-components.requiredFieldMessage' }));
}, [atSmallMedia, formatMessage, input]);
const renderSelectedItems = useCallback(() => selectedItems.map((item, index) => {
const selectedFormatter = valueFormatter || formatter;
return (
<ValueChip
key={`${itemToString(item)}-${index}`}
id={`${itemToString(item)}-${index}`}
controlLabelId={valueLabelId}
descriptionId={valueDescriptionId}
disabled={disabled}
getRemoveButtonProps={getRemoveButtonProps}
item={item}
index={index}
>
{selectedFormatter({ option: item })}
</ValueChip>
);
}), [
disabled,
formatter,
getRemoveButtonProps,
itemToString,
selectedItems,
valueDescriptionId,
valueFormatter,
valueLabelId
]);
/* Filter input ends up rendered in one of two places.
On smaller screens The filter input is placed in the overlay at the top
of the list of possible value options. On large screens, the placeholder is
presented with the list of.
*/
const renderFilterInput = useCallback(() => (
<MultiSelectFilterField
ariaLabelledBy={ariaLabelledBy || labelId}
disabled={disabled}
filterValue={filterValue}
getInputProps={getInputProps}
getDropdownProps={getDropdownProps}
isOpen={isOpen}
placeholder={selectedItems.length === 0 ? placeholder : ''}
menuId={menuId}
setFilterValue={setFilterValue}
setFilterFocus={setFilterFocused}
inputRef={input}
onBlur={onBlur}
onFocus={onFocus}
id={filterId}
/>
), [
labelId,
ariaLabelledBy,
disabled,
filterId,
filterValue,
getDropdownProps,
getInputProps,
isOpen,
onBlur,
menuId,
onFocus,
placeholder,
selectedItems.length,
input
]);
const renderOptions = useCallback(() => options.renderedItems?.map((item, index) => (
<SelectOption
key={`${itemToString(item)}`}
{...getItemProps({
item,
index,
optionItem: item,
isActive: highlightedIndex === index,
isDisabled: disabled,
isSelected: selectedItems ?
selectedItems.findIndex((o) => isEqual(o, item)) !== -1 :
false
})}
>
{formatter({ option: item, searchTerm: filterValue })}
</SelectOption>
)), [
filterValue,
formatter,
disabled,
getItemProps,
highlightedIndex,
itemToString,
options.renderedItems,
selectedItems
]);
const getValueAsString = useCallback(() => {
return Array.isArray(selectedItems) ? selectedItems.map(itemToString).join(',') : '';
}, [selectedItems, itemToString]);
const renderActions = useCallback(() => actions?.map((item, index) => {
const { renderedItems, exactMatch } = options;
const actionIndex = renderedItems.length + index;
return (
<SelectOption
key={`${actionId}-action-${actionIndex}`}
{...getItemProps({
item: { ...item, downshiftActions: { reset } },
index: actionIndex,
optionItem: item,
isActive: highlightedIndex === actionIndex,
})}
>
{
item.render({
filterValue,
exactMatch,
renderedItems,
})
}
</SelectOption>
);
}), [actionId, actions, filterValue, getItemProps, highlightedIndex, options, reset]);
// check if value prop has changed from the outside and update state accordingly.
if (awaitingChange.current) {
if (
// re-renders can happen inbetween user interaction, the request to update state, and the
// expected state finally being committed.
// Check if the incoming value prop is in sync with our anticipated state update so that we know
// our change has landed and we can go back to paying attention to external value prop updates.
(value && isEqual(value, userSelection.current)) ||
(typeof value === 'undefined' && selectedItems.length === 0)
) {
awaitingChange.current = false;
userSelection.current = null;
}
} else if (!awaitingChange.current &&
((typeof value === 'undefined' && selectedItems.length !== 0) ||
(value && !isEqual(value, selectedItems)))) {
setSelectedItems(value || []);
}
return (
<div
className={css.multiSelectContainer}
role="application"
ref={container}
id={uiId}
aria-expanded={isOpen}
>
<SRStatus ref={srStat} />
{label &&
<Label
{...getLabelProps({
required,
id: labelId,
htmlFor: filterId,
})}
className={`${ariaLabel ? 'sr-only' : ''}`}
>
{label}
</Label>
}
<span className="sr-only" id={controlValueStatusId}>
{`${
selectedItems ? selectedItems.length : 0
} item${
!selectedItems || selectedItems.length !== 1 ? 's' : ''
} selected`
}
</span>
<span className="sr-only" id={controlDescriptionId}>
{ formatMessage({ id: 'stripes-components.multiSelection.controlDescription' })}
</span>
{/*
Multiselection handles accessible announcement by following the label - value announcement pattern
that's common to standard controls, inputs etc. The announcement includes the label as well as
the number of selected items (if any).
This is assembled via a collection of elements used with the aria-labelledby attribute. Other labeling
attributes suche as `aria-label` are rendered into these elements and applied through the
aria-labelledby attribute.
*/}
<div className={css.multiSelectControlWrapper}>
<div
className={controlClass}
tabIndex="0"
ref={control}
aria-labelledby={`${labelProp ?
labelId + ' ' :
''}${
(!labelProp && ariaLabelledBy) ?
ariaLabelledBy + ' ' :
''}${controlValueStatusId}`}
aria-describedby={controlDescriptionId}
onClick={handleControlClick}
role="searchbox"
onKeyDown={getDropdownProps().onKeyDown}
>
<div className={css.multiSelectControlGroup}>
{ selectedItems && selectedItems.length > 0 && (
<SelectedValuesList
id={valueListId}
listRef={selectedList}
renderSelectedItem={renderSelectedItems}
valueLabelId={valueLabelId}
valueDescriptionId={valueDescriptionId}
renderSelectedItems={renderSelectedItems}
/>
)}
{!atSmallMedia ?
renderFilterInput() :
<div>placeholder</div>
}
{/* MultiSelectValueInput is visually hidden via CSS and contains string versions of selected items.
This allows for this component to be validated using HTML5
validation for the 'required' attribute.
*/}
<input
className={css.multiSelectValueInput}
id={valueInputId}
required={required}
value={getValueAsString(value)}
onChange={noop}
autoFocus={autoFocus}
onFocus={onValueInputFocus}
aria-hidden
tabIndex="-1"
/>
</div>
{showLoading && (
<Loading />
)}
<button
className={css.multiSelectToggleButton}
type="button"
{...getToggleButtonProps({
...getDropdownProps({
'aria-label': formatMessage({ id: 'stripes-components.multiSelection.dropdownTriggerLabel' }),
'aria-controls': menuId,
// prevents the menu from immediately toggling
// closed (due to our custom click handler above).
onClick: (e) => e.stopPropagation(),
disabled
})
})}
>
<TextFieldIcon icon="triangle-down" />
</button>
</div>
<MultiSelectResponsiveRenderer atSmallMedia={atSmallMedia} isOpen={isOpen}>
<MultiSelectOptionsList
renderActions={renderActions}
renderFilterInput={renderFilterInput}
asyncFiltering={asyncFiltering}
renderOptions={renderOptions}
renderedItems={options?.renderedItems}
actions={actions}
containerWidth={getContainerWidth(container)}
controlRef={control}
id={menuId}
labelId={labelId}
isOpen={isOpen}
getMenuProps={getMenuProps}
maxHeight={maxHeight}
renderToOverlay={renderToOverlay}
emptyMessage={emptyMessage}
error={error}
warning={warning}
atSmallMedia={atSmallMedia}
modifiers={modifiers}
usePortal={usePortal}
/>
</MultiSelectResponsiveRenderer>
</div>
<div role="alert">
{error && <div className={css.multiSelectError}>{error}</div>}
{warning && <div className={css.multiSelectWarning}>{warning}</div>}
</div>
</div>
);
}
const propTypes = {
actions: PropTypes.arrayOf(PropTypes.object),
ariaLabel: PropTypes.string,
ariaLabelledBy: PropTypes.string,
asyncFiltering: PropTypes.bool,
autoFocus: PropTypes.bool,
backspaceDeletes: PropTypes.bool,
dataOptions: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.string,
PropTypes.object
])
),
dirty: PropTypes.bool,
disabled: PropTypes.bool,
emptyMessage: PropTypes.string,
error: PropTypes.node,
filter: PropTypes.func,
formatter: PropTypes.func,
id: PropTypes.string,
inputRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
intl: PropTypes.shape({
formatMessage: PropTypes.func
}),
isValid: PropTypes.bool,
itemToString: PropTypes.func,
label: PropTypes.node,
marginBottom0: PropTypes.bool,
maxHeight: PropTypes.number,
modifiers: PropTypes.object,
noBorder: PropTypes.bool,
onAdd: PropTypes.func,
onBlur: PropTypes.func,
onChange: PropTypes.func,
onFocus: PropTypes.func,
onRemove: PropTypes.func,
placeholder: PropTypes.string,
renderToOverlay: deprecated(PropTypes.bool, 'use usePortal prop instead'),
required: PropTypes.bool,
showLoading: PropTypes.bool,
usePortal: PropTypes.bool,
validationEnabled: PropTypes.bool,
validStylesEnabled: PropTypes.bool,
value: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.object),
PropTypes.arrayOf(PropTypes.string),
PropTypes.string]),
valueFormatter: PropTypes.func,
warning: PropTypes.node,
};
MultiSelection.propTypes = propTypes;
export default formField(
MultiSelection,
({ meta }) => ({
error: (meta.touched && meta.error ? meta.error : ''),
warning: (meta.touched ? parseMeta(meta, 'warning') : ''),
})
);