@entur/dropdown 7.1.0 → 7.1.1-beta.0
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/Dropdown.d.ts +2 -2
- package/dist/MultiSelect.d.ts +52 -1
- package/dist/NativeDropdown.d.ts +1 -1
- package/dist/SearchableDropdown.d.ts +14 -1
- package/dist/components/DropdownList.d.ts +2 -2
- package/dist/components/FieldComponents.d.ts +15 -13
- package/dist/dropdown.cjs.development.js +443 -431
- package/dist/dropdown.cjs.development.js.map +1 -1
- package/dist/dropdown.cjs.production.min.js +1 -1
- package/dist/dropdown.cjs.production.min.js.map +1 -1
- package/dist/dropdown.esm.js +447 -435
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +21 -28
- package/dist/utils.d.ts +4 -0
- package/package.json +4 -4
|
@@ -361,7 +361,7 @@ function _regeneratorRuntime() {
|
|
|
361
361
|
}, e;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
-
var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "
|
|
364
|
+
var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "isOpen", "highlightedIndex", "listItems", "floatingStyles", "setListRef", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems"];
|
|
365
365
|
var DropdownList = function DropdownList(_ref) {
|
|
366
366
|
var _listItems$;
|
|
367
367
|
var _ref$ariaLabelChosenS = _ref.ariaLabelChosenSingular,
|
|
@@ -422,27 +422,20 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
422
422
|
"aria-hidden": "true",
|
|
423
423
|
checked: selectAllCheckboxState == null ? void 0 : selectAllCheckboxState(),
|
|
424
424
|
className: "eds-dropdown__list__item__checkbox",
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
},
|
|
428
|
-
tabIndex: -1
|
|
425
|
+
tabIndex: -1,
|
|
426
|
+
readOnly: true
|
|
429
427
|
}), React.createElement("span", {
|
|
430
428
|
className: "eds-dropdown__list__item__text",
|
|
431
429
|
"aria-label": ariaValuesSelectAll().label
|
|
432
430
|
}, selectAllItem == null ? void 0 : selectAllItem.label));
|
|
433
431
|
};
|
|
434
432
|
var listItemContent = function listItemContent(item) {
|
|
435
|
-
return React.createElement(React.Fragment, null, React.createElement(form.Checkbox, {
|
|
433
|
+
return React.createElement(React.Fragment, null, isMultiselect && React.createElement(form.Checkbox, {
|
|
436
434
|
"aria-hidden": "true",
|
|
437
435
|
checked: isItemSelected(item),
|
|
438
436
|
className: "eds-dropdown__list__item__checkbox",
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
},
|
|
442
|
-
style: !isMultiselect ? {
|
|
443
|
-
display: 'none'
|
|
444
|
-
} : {},
|
|
445
|
-
tabIndex: -1
|
|
437
|
+
tabIndex: -1,
|
|
438
|
+
readOnly: true
|
|
446
439
|
}), React.createElement("span", {
|
|
447
440
|
className: "eds-dropdown__list__item__text"
|
|
448
441
|
}, item.label, React.createElement(a11y.VisuallyHidden, null, isItemSelected(item) ? ariaLabelSelectedItem : '')), item.icons && React.createElement("span", null, item.icons.map(function (Icon) {
|
|
@@ -456,50 +449,58 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
456
449
|
};
|
|
457
450
|
return (
|
|
458
451
|
// use popover from @entur/tooltip when that package upgrades to floating-ui
|
|
459
|
-
React.createElement("
|
|
460
|
-
|
|
461
|
-
|
|
452
|
+
React.createElement("ul", _extends({}, getMenuProps({
|
|
453
|
+
'aria-multiselectable': isMultiselect,
|
|
454
|
+
ref: setListRef,
|
|
455
|
+
className: 'eds-dropdown__list',
|
|
456
|
+
style: _extends({}, floatingStyles, {
|
|
462
457
|
display: isOpen ? undefined : 'none'
|
|
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
|
-
|
|
458
|
+
}, rest.style)
|
|
459
|
+
})), function () {
|
|
460
|
+
if (!isOpen) {
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
if (loading) {
|
|
464
|
+
return React.createElement("li", {
|
|
465
|
+
key: "dropdown-list-loading",
|
|
466
|
+
className: "eds-dropdown__list__item"
|
|
467
|
+
}, loadingText);
|
|
468
|
+
}
|
|
469
|
+
if (isNoMatches) {
|
|
470
|
+
return React.createElement("li", {
|
|
471
|
+
key: "dropdown-list-no-match",
|
|
472
|
+
className: "eds-dropdown__list__item"
|
|
473
|
+
}, noMatchesText);
|
|
474
|
+
}
|
|
475
|
+
return listItems.map(function (item, index) {
|
|
476
|
+
var _item$icons$map, _item$icons;
|
|
477
|
+
var itemIsSelectAll = item.value === (selectAllItem == null ? void 0 : selectAllItem.value);
|
|
478
|
+
if (itemIsSelectAll && listItems.length <= 2) return null;
|
|
479
|
+
return React.createElement("li", _extends({
|
|
480
|
+
className: classNames('eds-dropdown__list__item', {
|
|
481
|
+
'eds-dropdown__list__item--select-all': itemIsSelectAll,
|
|
482
|
+
'eds-dropdown__list__item--highlighted': highlightedIndex === index,
|
|
483
|
+
'eds-dropdown__list__item--selected': !isMultiselect && isItemSelected(item)
|
|
484
|
+
}),
|
|
485
|
+
key: (item == null ? void 0 : item.label) + (item == null ? void 0 : item.value) + ((_item$icons$map = item == null || (_item$icons = item.icons) == null ? void 0 : _item$icons.map(function (icon) {
|
|
486
|
+
var _icon$displayName;
|
|
487
|
+
return (_icon$displayName = icon.displayName) != null ? _icon$displayName : icon.name;
|
|
488
|
+
})) != null ? _item$icons$map : '').toString()
|
|
489
|
+
}, getItemProps({
|
|
490
|
+
// @ts-expect-error Since getItemProps expects the same item type
|
|
491
|
+
// here as items, it throws error when selectAllItem is a string.
|
|
492
|
+
// This does, however, not cause any functional issues.
|
|
493
|
+
item: item,
|
|
494
|
+
index: index,
|
|
495
|
+
'aria-selected': itemIsSelectAll ? ariaValuesSelectAll().selected : isItemSelected(item)
|
|
496
|
+
})), itemIsSelectAll ? selectAllListItemContent() : listItemContent(item));
|
|
497
|
+
});
|
|
498
|
+
}())
|
|
499
499
|
);
|
|
500
500
|
};
|
|
501
501
|
|
|
502
|
-
var _excluded$4 = ["tabIndex"]
|
|
502
|
+
var _excluded$4 = ["tabIndex"],
|
|
503
|
+
_excluded2 = ["ariaLabelCloseList", "ariaLabelOpenList", "clearable", "labelClearSelected", "focusable", "disabled", "isOpen", "loading", "loadingText", "onClear", "itemIsSelected"];
|
|
503
504
|
var SelectedItemTag = function SelectedItemTag(_ref) {
|
|
504
505
|
var _getSelectedItemProps;
|
|
505
506
|
var ariaLabelRemoveSelected = _ref.ariaLabelRemoveSelected,
|
|
@@ -527,6 +528,9 @@ var SelectedItemTag = function SelectedItemTag(_ref) {
|
|
|
527
528
|
e.stopPropagation();
|
|
528
529
|
removeSelectedItem(selectedItem);
|
|
529
530
|
},
|
|
531
|
+
onClick: function onClick(e) {
|
|
532
|
+
return e.stopPropagation();
|
|
533
|
+
},
|
|
530
534
|
closeButtonAriaLabel: selectedItem.label + " " + ariaLabelChosen + ", " + ariaLabelRemoveSelected + " ",
|
|
531
535
|
key: selectedItem.value,
|
|
532
536
|
"aria-live": "polite"
|
|
@@ -535,57 +539,54 @@ var SelectedItemTag = function SelectedItemTag(_ref) {
|
|
|
535
539
|
className: "eds-dropdown__selected-item-tag__text"
|
|
536
540
|
}, selectedItem.label));
|
|
537
541
|
};
|
|
538
|
-
var
|
|
539
|
-
var
|
|
540
|
-
ariaHiddenToggleButton = _ref3$ariaHiddenToggl === void 0 ? false : _ref3$ariaHiddenToggl,
|
|
541
|
-
ariaLabelCloseList = _ref3.ariaLabelCloseList,
|
|
542
|
+
var DropdownFieldAppendix = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
|
|
543
|
+
var ariaLabelCloseList = _ref3.ariaLabelCloseList,
|
|
542
544
|
ariaLabelOpenList = _ref3.ariaLabelOpenList,
|
|
543
545
|
_ref3$clearable = _ref3.clearable,
|
|
544
546
|
clearable = _ref3$clearable === void 0 ? false : _ref3$clearable,
|
|
545
|
-
|
|
546
|
-
_ref3$disabled = _ref3.disabled,
|
|
547
|
-
disabled = _ref3$disabled === void 0 ? false : _ref3$disabled,
|
|
547
|
+
labelClearSelected = _ref3.labelClearSelected,
|
|
548
548
|
_ref3$focusable = _ref3.focusable,
|
|
549
549
|
focusable = _ref3$focusable === void 0 ? false : _ref3$focusable,
|
|
550
|
-
|
|
550
|
+
disabled = _ref3.disabled,
|
|
551
551
|
isOpen = _ref3.isOpen,
|
|
552
552
|
_ref3$loading = _ref3.loading,
|
|
553
553
|
loading = _ref3$loading === void 0 ? false : _ref3$loading,
|
|
554
|
-
|
|
555
|
-
loadingText = _ref3$loadingText === void 0 ? 'Laster resultater …' : _ref3$loadingText,
|
|
554
|
+
loadingText = _ref3.loadingText,
|
|
556
555
|
onClear = _ref3.onClear,
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
556
|
+
itemIsSelected = _ref3.itemIsSelected,
|
|
557
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2);
|
|
558
|
+
function getToggleAriaLabel() {
|
|
559
|
+
if (loading) return loadingText;
|
|
560
|
+
if (isOpen) return ariaLabelCloseList;
|
|
561
|
+
return ariaLabelOpenList;
|
|
560
562
|
}
|
|
561
|
-
return React.createElement("div", {
|
|
563
|
+
return React.createElement(React.Fragment, null, !disabled && React.createElement("div", {
|
|
562
564
|
className: "eds-dropdown__appendix"
|
|
563
|
-
}, clearable &&
|
|
565
|
+
}, clearable && itemIsSelected && React.createElement(ClearableButton, {
|
|
564
566
|
onClear: onClear,
|
|
565
567
|
focusable: true,
|
|
566
|
-
labelClearSelectedItems:
|
|
567
|
-
}), React.createElement(
|
|
568
|
-
className:
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
};
|
|
568
|
+
labelClearSelectedItems: labelClearSelected
|
|
569
|
+
}), React.createElement(button.IconButton, _extends({
|
|
570
|
+
className: classNames('eds-dropdown__appendix__toggle-button', {
|
|
571
|
+
'eds-dropdown__appendix__toggle-button--open': isOpen
|
|
572
|
+
}),
|
|
573
|
+
ref: ref,
|
|
574
|
+
"aria-label": getToggleAriaLabel()
|
|
575
|
+
}, rest, {
|
|
576
|
+
tabIndex: focusable ? 0 : -1
|
|
577
|
+
}), !loading ? React.createElement(icons.DownArrowIcon, {
|
|
578
|
+
"aria-hidden": "true"
|
|
579
|
+
}) : React.createElement(loader.LoadingDots, {
|
|
580
|
+
"aria-hidden": "true"
|
|
581
|
+
}))));
|
|
582
|
+
});
|
|
582
583
|
var ClearableButton = function ClearableButton(_ref4) {
|
|
583
584
|
var onClear = _ref4.onClear,
|
|
584
585
|
_ref4$labelClearSelec = _ref4.labelClearSelectedItems,
|
|
585
586
|
labelClearSelectedItems = _ref4$labelClearSelec === void 0 ? 'Fjern valgte' : _ref4$labelClearSelec,
|
|
586
587
|
_ref4$focusable = _ref4.focusable,
|
|
587
588
|
focusable = _ref4$focusable === void 0 ? false : _ref4$focusable;
|
|
588
|
-
return React.createElement(tooltip.Tooltip, {
|
|
589
|
+
return React.createElement(React.Fragment, null, React.createElement(tooltip.Tooltip, {
|
|
589
590
|
"aria-hidden": "true",
|
|
590
591
|
placement: "top",
|
|
591
592
|
content: labelClearSelectedItems,
|
|
@@ -593,36 +594,16 @@ var ClearableButton = function ClearableButton(_ref4) {
|
|
|
593
594
|
}, React.createElement(button.IconButton, {
|
|
594
595
|
className: "eds-dropdown__appendix__clear-button",
|
|
595
596
|
type: "button",
|
|
596
|
-
tabIndex: focusable ? 0 : 1,
|
|
597
|
-
onClick:
|
|
597
|
+
tabIndex: focusable ? 0 : -1,
|
|
598
|
+
onClick: function onClick(e) {
|
|
599
|
+
e.stopPropagation();
|
|
600
|
+
onClear();
|
|
601
|
+
},
|
|
598
602
|
"aria-label": labelClearSelectedItems
|
|
599
603
|
}, React.createElement(icons.CloseSmallIcon, {
|
|
600
604
|
"aria-hidden": "true"
|
|
601
|
-
})))
|
|
602
|
-
|
|
603
|
-
var ToggleButton = function ToggleButton(_ref5) {
|
|
604
|
-
var getToggleButtonProps = _ref5.getToggleButtonProps,
|
|
605
|
-
isOpen = _ref5.isOpen,
|
|
606
|
-
_ref5$ariaHidden = _ref5['aria-hidden'],
|
|
607
|
-
ariaHidden = _ref5$ariaHidden === void 0 ? false : _ref5$ariaHidden,
|
|
608
|
-
_ref5$ariaLabelCloseL = _ref5.ariaLabelCloseList,
|
|
609
|
-
ariaLabelCloseList = _ref5$ariaLabelCloseL === void 0 ? 'Lukk liste med valg' : _ref5$ariaLabelCloseL,
|
|
610
|
-
_ref5$ariaLabelOpenLi = _ref5.ariaLabelOpenList,
|
|
611
|
-
ariaLabelOpenList = _ref5$ariaLabelOpenLi === void 0 ? 'Åpne liste med valg' : _ref5$ariaLabelOpenLi,
|
|
612
|
-
_ref5$focusable = _ref5.focusable,
|
|
613
|
-
focusable = _ref5$focusable === void 0 ? false : _ref5$focusable;
|
|
614
|
-
return React.createElement(button.IconButton, _extends({}, getToggleButtonProps({
|
|
615
|
-
className: classNames('eds-dropdown__appendix__toggle-button', {
|
|
616
|
-
'eds-dropdown__appendix__toggle-button--open': isOpen
|
|
617
|
-
}),
|
|
618
|
-
'aria-labelledby': undefined
|
|
619
|
-
}), {
|
|
620
|
-
"aria-hidden": ariaHidden,
|
|
621
|
-
"aria-label": ariaHidden ? undefined : isOpen ? ariaLabelCloseList : ariaLabelOpenList,
|
|
622
|
-
tabIndex: focusable ? 0 : -1,
|
|
623
|
-
type: "button"
|
|
624
|
-
}), React.createElement(icons.DownArrowIcon, {
|
|
625
|
-
"aria-hidden": "true"
|
|
605
|
+
}))), React.createElement("div", {
|
|
606
|
+
className: "eds-dropdown__appendix__divider"
|
|
626
607
|
}));
|
|
627
608
|
};
|
|
628
609
|
|
|
@@ -767,6 +748,15 @@ var itemToKey = function itemToKey(item) {
|
|
|
767
748
|
var isFunctionWithQueryArgument = function isFunctionWithQueryArgument(object) {
|
|
768
749
|
return typeof object === 'function' && object.length > 0;
|
|
769
750
|
};
|
|
751
|
+
var clamp = function clamp(val, min, max) {
|
|
752
|
+
if (min === void 0) {
|
|
753
|
+
min = 1;
|
|
754
|
+
}
|
|
755
|
+
if (max === void 0) {
|
|
756
|
+
max = 10;
|
|
757
|
+
}
|
|
758
|
+
return Math.min(Math.max(val, min), max);
|
|
759
|
+
};
|
|
770
760
|
var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
771
761
|
var listItems = _ref.listItems,
|
|
772
762
|
selectedItems = _ref.selectedItems,
|
|
@@ -872,11 +862,13 @@ function getA11yStatusMessage(options) {
|
|
|
872
862
|
/* end a11y utils */
|
|
873
863
|
|
|
874
864
|
var _excluded$3 = ["ariaLabelChosenSingular", "ariaLabelCloseList", "ariaLabelOpenList", "ariaLabelSelectedItem", "className", "clearable", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "items", "itemFilter", "label", "labelClearSelectedItem", "labelTooltip", "listStyle", "loading", "loadingText", "noMatchesText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
|
|
875
|
-
var SearchableDropdown = function
|
|
876
|
-
var _document, _selectedItem$label;
|
|
865
|
+
var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
866
|
+
var _document, _getInputProps2, _selectedItem$label;
|
|
877
867
|
var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
878
|
-
|
|
879
|
-
|
|
868
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
869
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
870
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
871
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
880
872
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
881
873
|
className = _ref.className,
|
|
882
874
|
_ref$clearable = _ref.clearable,
|
|
@@ -896,8 +888,10 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
896
888
|
labelTooltip = _ref.labelTooltip,
|
|
897
889
|
listStyle = _ref.listStyle,
|
|
898
890
|
loading = _ref.loading,
|
|
899
|
-
loadingText = _ref.loadingText,
|
|
900
|
-
|
|
891
|
+
_ref$loadingText = _ref.loadingText,
|
|
892
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
893
|
+
_ref$noMatchesText = _ref.noMatchesText,
|
|
894
|
+
noMatchesText = _ref$noMatchesText === void 0 ? 'Ingen tilgjengelige valg …' : _ref$noMatchesText,
|
|
901
895
|
_ref$onChange = _ref.onChange,
|
|
902
896
|
onChange = _ref$onChange === void 0 ? function () {
|
|
903
897
|
return undefined;
|
|
@@ -943,6 +937,15 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
943
937
|
inputValue: inputValue != null ? inputValue : EMPTY_INPUT
|
|
944
938
|
});
|
|
945
939
|
};
|
|
940
|
+
var resetInputState = function resetInputState(_ref4) {
|
|
941
|
+
var changes = _ref4.changes;
|
|
942
|
+
updateListItems({
|
|
943
|
+
inputValue: EMPTY_INPUT
|
|
944
|
+
});
|
|
945
|
+
return _extends({}, changes, {
|
|
946
|
+
inputValue: EMPTY_INPUT
|
|
947
|
+
});
|
|
948
|
+
};
|
|
946
949
|
var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
|
|
947
950
|
React.useEffect(function () {
|
|
948
951
|
filterListItems({
|
|
@@ -959,9 +962,9 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
959
962
|
setInputValue(EMPTY_INPUT);
|
|
960
963
|
}
|
|
961
964
|
}, []);
|
|
962
|
-
var stateReducer = React.useCallback(function (
|
|
963
|
-
var type =
|
|
964
|
-
changes =
|
|
965
|
+
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
966
|
+
var type = _ref5.type,
|
|
967
|
+
changes = _ref5.changes;
|
|
965
968
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
966
969
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
967
970
|
}
|
|
@@ -970,67 +973,61 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
970
973
|
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
971
974
|
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
972
975
|
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
973
|
-
{
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
});
|
|
977
|
-
return _extends({}, changes, {
|
|
978
|
-
inputValue: EMPTY_INPUT
|
|
979
|
-
});
|
|
980
|
-
}
|
|
976
|
+
return resetInputState({
|
|
977
|
+
changes: changes
|
|
978
|
+
});
|
|
981
979
|
case downshift.useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
982
980
|
if (changes.selectedItem !== null && !inputHasFocus) setShowSelectedItem(true);
|
|
983
|
-
|
|
984
|
-
|
|
981
|
+
return resetInputState({
|
|
982
|
+
changes: changes
|
|
985
983
|
});
|
|
986
|
-
|
|
987
|
-
inputValue: EMPTY_INPUT
|
|
988
|
-
});
|
|
989
|
-
// remove leading whitespace, select element with spacebar on empty input, and filter list based on input
|
|
984
|
+
// remove leading whitespace, select element with spacebar on empty input
|
|
990
985
|
case downshift.useCombobox.stateChangeTypes.InputChange:
|
|
991
986
|
{
|
|
992
987
|
var _changes$inputValue;
|
|
988
|
+
setLastHighlightedIndex(0);
|
|
993
989
|
var leadingWhitespaceTest = /^\s+/g;
|
|
994
990
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
995
991
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
996
|
-
|
|
992
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
997
993
|
if (isSpacePressedOnEmptyInput) {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
994
|
+
if (!state.isOpen) return _extends({}, changes, {
|
|
995
|
+
inputValue: sanitizedInputValue,
|
|
996
|
+
isOpen: true,
|
|
997
|
+
highlightedIndex: 0
|
|
998
|
+
});
|
|
999
|
+
if (changes.highlightedIndex !== undefined) {
|
|
1000
|
+
return _extends({}, changes, {
|
|
1001
|
+
inputValue: sanitizedInputValue,
|
|
1002
|
+
selectedItem: listItems[changes.highlightedIndex],
|
|
1003
|
+
highlightedIndex: 0
|
|
1004
|
+
});
|
|
1001
1005
|
}
|
|
1002
1006
|
}
|
|
1003
|
-
} else {
|
|
1004
|
-
updateListItems({
|
|
1005
|
-
inputValue: changes.inputValue
|
|
1006
|
-
});
|
|
1007
|
-
setHighlightedIndex(0);
|
|
1008
|
-
setLastHighlightedIndex(0);
|
|
1009
1007
|
}
|
|
1010
|
-
return changes
|
|
1008
|
+
return _extends({}, changes, {
|
|
1009
|
+
highlightedIndex: 0
|
|
1010
|
+
});
|
|
1011
1011
|
}
|
|
1012
1012
|
default:
|
|
1013
1013
|
return changes;
|
|
1014
1014
|
}
|
|
1015
|
-
}, [fetchItems, filterListItems]);
|
|
1016
|
-
var _useCombobox = downshift.useCombobox(
|
|
1015
|
+
}, [fetchItems, filterListItems, inputHasFocus, resetInputState]);
|
|
1016
|
+
var _useCombobox = downshift.useCombobox({
|
|
1017
1017
|
defaultHighlightedIndex: lastHighlightedIndex,
|
|
1018
1018
|
items: listItems,
|
|
1019
1019
|
itemToString: itemToString,
|
|
1020
1020
|
selectedItem: value,
|
|
1021
1021
|
stateReducer: stateReducer,
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
if (newSelectedItem === undefined) return;
|
|
1032
|
-
onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1033
|
-
}
|
|
1022
|
+
onInputValueChange: function onInputValueChange(changes) {
|
|
1023
|
+
updateListItems({
|
|
1024
|
+
inputValue: changes.inputValue
|
|
1025
|
+
});
|
|
1026
|
+
},
|
|
1027
|
+
onStateChange: function onStateChange(_ref6) {
|
|
1028
|
+
var newSelectedItem = _ref6.selectedItem;
|
|
1029
|
+
if (newSelectedItem === undefined) return;
|
|
1030
|
+
onChange(newSelectedItem);
|
|
1034
1031
|
},
|
|
1035
1032
|
// Accessibility
|
|
1036
1033
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1038,37 +1035,51 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1038
1035
|
resultCount: listItems.length
|
|
1039
1036
|
}));
|
|
1040
1037
|
}
|
|
1041
|
-
}
|
|
1038
|
+
}),
|
|
1042
1039
|
isOpen = _useCombobox.isOpen,
|
|
1043
|
-
openMenu = _useCombobox.openMenu,
|
|
1044
1040
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1045
1041
|
getLabelProps = _useCombobox.getLabelProps,
|
|
1046
1042
|
getMenuProps = _useCombobox.getMenuProps,
|
|
1047
1043
|
getInputProps = _useCombobox.getInputProps,
|
|
1048
1044
|
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1049
|
-
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1050
1045
|
getItemProps = _useCombobox.getItemProps,
|
|
1051
1046
|
selectedItem = _useCombobox.selectedItem,
|
|
1052
1047
|
inputValue = _useCombobox.inputValue,
|
|
1053
1048
|
setInputValue = _useCombobox.setInputValue;
|
|
1049
|
+
// calculations for floating-UI popover position
|
|
1054
1050
|
var _useFloating = reactDom.useFloating({
|
|
1055
|
-
placement: 'bottom-start',
|
|
1056
1051
|
open: isOpen,
|
|
1057
|
-
|
|
1052
|
+
placement: 'bottom-start',
|
|
1053
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.shift({
|
|
1054
|
+
padding: tokens.space.extraSmall
|
|
1055
|
+
}), reactDom.size({
|
|
1056
|
+
apply: function apply(_ref7) {
|
|
1057
|
+
var rects = _ref7.rects,
|
|
1058
|
+
elements = _ref7.elements,
|
|
1059
|
+
availableHeight = _ref7.availableHeight;
|
|
1060
|
+
Object.assign(elements.floating.style, {
|
|
1061
|
+
width: rects.reference.width + "px",
|
|
1062
|
+
// Floating will flip when smaller than 10*16 px
|
|
1063
|
+
// and never exceed 20*16 px.
|
|
1064
|
+
maxHeight: clamp(10 * 16, availableHeight, 20 * 16) + "px"
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
}), reactDom.flip({
|
|
1068
|
+
fallbackStrategy: 'initialPlacement'
|
|
1069
|
+
})]
|
|
1058
1070
|
}),
|
|
1059
1071
|
refs = _useFloating.refs,
|
|
1060
1072
|
floatingStyles = _useFloating.floatingStyles,
|
|
1061
|
-
elements = _useFloating.elements,
|
|
1062
1073
|
update = _useFloating.update;
|
|
1063
|
-
//
|
|
1064
|
-
//
|
|
1065
|
-
//
|
|
1074
|
+
// Update floating-ui position on scroll etc. Floating-ui's autoupdate is usually used inside
|
|
1075
|
+
// the useFloating hook but this requires the floating element to be conditionally rendered.
|
|
1076
|
+
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1077
|
+
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1066
1078
|
React.useEffect(function () {
|
|
1067
|
-
if (isOpen &&
|
|
1068
|
-
|
|
1069
|
-
return cleanup;
|
|
1079
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1080
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1070
1081
|
}
|
|
1071
|
-
}, [isOpen,
|
|
1082
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1072
1083
|
var handleOnClear = function handleOnClear() {
|
|
1073
1084
|
var _inputRef$current;
|
|
1074
1085
|
onChange(null);
|
|
@@ -1080,20 +1091,6 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1080
1091
|
setShowSelectedItem(false);
|
|
1081
1092
|
};
|
|
1082
1093
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1083
|
-
append: React.createElement(FieldAppend$1, {
|
|
1084
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1085
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1086
|
-
clearable: clearable,
|
|
1087
|
-
labelClearSelectedItems: labelClearSelectedItem,
|
|
1088
|
-
disabled: readOnly || disabled,
|
|
1089
|
-
focusable: false,
|
|
1090
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
1091
|
-
isOpen: isOpen,
|
|
1092
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1093
|
-
loadingText: loadingText,
|
|
1094
|
-
onClear: handleOnClear,
|
|
1095
|
-
selectedItems: [selectedItem]
|
|
1096
|
-
}),
|
|
1097
1094
|
className: classNames('eds-dropdown', 'eds-dropdown--searchable', className, {
|
|
1098
1095
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1099
1096
|
}),
|
|
@@ -1105,31 +1102,50 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1105
1102
|
labelId: getLabelProps().id,
|
|
1106
1103
|
labelProps: getLabelProps(),
|
|
1107
1104
|
labelTooltip: labelTooltip,
|
|
1105
|
+
onBlur: function onBlur() {
|
|
1106
|
+
return setInputValue('');
|
|
1107
|
+
},
|
|
1108
1108
|
onClick: function onClick(e) {
|
|
1109
|
-
|
|
1110
|
-
|
|
1109
|
+
if (e.target === e.currentTarget) {
|
|
1110
|
+
var _getInputProps;
|
|
1111
|
+
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1112
|
+
}
|
|
1111
1113
|
},
|
|
1112
1114
|
prepend: prepend,
|
|
1113
1115
|
readOnly: readOnly,
|
|
1114
1116
|
ref: refs.setReference,
|
|
1115
1117
|
style: style,
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
+
tabIndex: disabled || readOnly ? -1 : undefined,
|
|
1119
|
+
variant: variant,
|
|
1120
|
+
after: React.createElement(DropdownList, {
|
|
1121
|
+
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1122
|
+
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1123
|
+
floatingStyles: floatingStyles,
|
|
1124
|
+
getItemProps: getItemProps,
|
|
1125
|
+
getMenuProps: getMenuProps,
|
|
1126
|
+
highlightedIndex: highlightedIndex,
|
|
1127
|
+
isOpen: isOpen,
|
|
1128
|
+
listItems: listItems,
|
|
1129
|
+
style: listStyle,
|
|
1130
|
+
setListRef: refs.setFloating,
|
|
1131
|
+
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1132
|
+
loadingText: loadingText,
|
|
1133
|
+
noMatchesText: noMatchesText,
|
|
1134
|
+
selectedItems: selectedItem !== null ? [selectedItem] : []
|
|
1135
|
+
})
|
|
1136
|
+
}, rest, {
|
|
1137
|
+
// Append is not supported as of now
|
|
1138
|
+
append: undefined
|
|
1139
|
+
}), React.createElement("span", {
|
|
1118
1140
|
className: classNames('eds-dropdown--searchable__selected-item', {
|
|
1119
1141
|
'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
|
|
1120
1142
|
}),
|
|
1121
1143
|
"aria-hidden": "true",
|
|
1122
|
-
onClick:
|
|
1123
|
-
var _inputRef$current3;
|
|
1124
|
-
(_inputRef$current3 = inputRef.current) == null || _inputRef$current3.focus();
|
|
1125
|
-
openMenu();
|
|
1126
|
-
}
|
|
1144
|
+
onClick: (_getInputProps2 = getInputProps()) == null ? void 0 : _getInputProps2.onClick
|
|
1127
1145
|
}, showSelectedItem ? selectedItem == null ? void 0 : selectedItem.label : ''), React.createElement("input", _extends({
|
|
1128
1146
|
className: classNames('eds-dropdown__input eds-form-control', {
|
|
1129
1147
|
'eds-dropdown__input--hidden': showSelectedItem
|
|
1130
|
-
})
|
|
1131
|
-
disabled: readOnly || disabled,
|
|
1132
|
-
placeholder: (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : placeholder
|
|
1148
|
+
})
|
|
1133
1149
|
}, getInputProps({
|
|
1134
1150
|
onBlur: function onBlur() {
|
|
1135
1151
|
if (selectedItem !== null) setShowSelectedItem(true);
|
|
@@ -1138,29 +1154,33 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1138
1154
|
setShowSelectedItem(false);
|
|
1139
1155
|
},
|
|
1140
1156
|
onKeyDown: function onKeyDown(e) {
|
|
1141
|
-
if (
|
|
1157
|
+
if (isOpen && (selectOnTab || selectOnBlur) && e.key === 'Tab' && highlightedIndex !== undefined) onChange(listItems[highlightedIndex]);
|
|
1142
1158
|
},
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1159
|
+
disabled: disabled,
|
|
1160
|
+
readOnly: readOnly,
|
|
1161
|
+
placeholder: (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : placeholder,
|
|
1162
|
+
tabIndex: disabled || readOnly ? -1 : undefined,
|
|
1163
|
+
ref: utils.mergeRefs(inputRef, ref)
|
|
1164
|
+
}))), React.createElement(DropdownFieldAppendix, _extends({}, getToggleButtonProps({
|
|
1165
|
+
'aria-busy': !(loading != null ? loading : resolvedItemsLoading) ? undefined : 'true'
|
|
1166
|
+
}), {
|
|
1167
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1168
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1169
|
+
clearable: clearable,
|
|
1170
|
+
disabled: disabled || readOnly,
|
|
1171
|
+
onClear: handleOnClear,
|
|
1172
|
+
focusable: false,
|
|
1173
|
+
labelClearSelected: labelClearSelectedItem,
|
|
1151
1174
|
isOpen: isOpen,
|
|
1152
|
-
|
|
1153
|
-
style: listStyle,
|
|
1154
|
-
setListRef: refs.setFloating,
|
|
1155
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1175
|
+
itemIsSelected: selectedItem !== null,
|
|
1156
1176
|
loadingText: loadingText,
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
};
|
|
1177
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1178
|
+
})));
|
|
1179
|
+
});
|
|
1161
1180
|
|
|
1162
1181
|
var _excluded$2 = ["className", "clearable", "clearInputOnSelect", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "hideSelectAll", "items", "itemFilter", "label", "labelAllItemsSelected", "labelClearAllItems", "labelSelectAll", "labelTooltip", "listStyle", "loading", "loadingText", "maxChips", "noMatchesText", "onChange", "placeholder", "readOnly", "selectedItems", "selectOnBlur", "selectOnTab", "style", "variant", "ariaLabelChosenSingular", "ariaLabelChosenPlural", "ariaLabelCloseList", "ariaLabelJumpToInput", "ariaLabelOpenList", "ariaLabelRemoveSelected", "ariaLabelSelectedItem"];
|
|
1163
|
-
var MultiSelect = function
|
|
1182
|
+
var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1183
|
+
var _inputRef$current4;
|
|
1164
1184
|
var className = _ref.className,
|
|
1165
1185
|
_ref$clearable = _ref.clearable,
|
|
1166
1186
|
clearable = _ref$clearable === void 0 ? true : _ref$clearable,
|
|
@@ -1186,7 +1206,8 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1186
1206
|
labelTooltip = _ref.labelTooltip,
|
|
1187
1207
|
listStyle = _ref.listStyle,
|
|
1188
1208
|
loading = _ref.loading,
|
|
1189
|
-
loadingText = _ref.loadingText,
|
|
1209
|
+
_ref$loadingText = _ref.loadingText,
|
|
1210
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1190
1211
|
_ref$maxChips = _ref.maxChips,
|
|
1191
1212
|
maxChips = _ref$maxChips === void 0 ? 10 : _ref$maxChips,
|
|
1192
1213
|
noMatchesText = _ref.noMatchesText,
|
|
@@ -1199,8 +1220,6 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1199
1220
|
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
1200
1221
|
_ref$selectedItems = _ref.selectedItems,
|
|
1201
1222
|
selectedItems = _ref$selectedItems === void 0 ? [] : _ref$selectedItems,
|
|
1202
|
-
_ref$selectOnBlur = _ref.selectOnBlur,
|
|
1203
|
-
selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
|
|
1204
1223
|
_ref$selectOnTab = _ref.selectOnTab,
|
|
1205
1224
|
selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
|
|
1206
1225
|
style = _ref.style,
|
|
@@ -1209,10 +1228,12 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1209
1228
|
ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1210
1229
|
_ref$ariaLabelChosenP = _ref.ariaLabelChosenPlural,
|
|
1211
1230
|
ariaLabelChosenPlural = _ref$ariaLabelChosenP === void 0 ? 'valgte' : _ref$ariaLabelChosenP,
|
|
1212
|
-
|
|
1231
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
1232
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
1213
1233
|
_ref$ariaLabelJumpToI = _ref.ariaLabelJumpToInput,
|
|
1214
1234
|
ariaLabelJumpToInput = _ref$ariaLabelJumpToI === void 0 ? selectedItems.length + " valgte elementer, trykk for \xE5 hoppe til tekstfeltet" : _ref$ariaLabelJumpToI,
|
|
1215
|
-
|
|
1235
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
1236
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
1216
1237
|
_ref$ariaLabelRemoveS = _ref.ariaLabelRemoveSelected,
|
|
1217
1238
|
ariaLabelRemoveSelected = _ref$ariaLabelRemoveS === void 0 ? 'trykk for å fjerne valg' : _ref$ariaLabelRemoveS,
|
|
1218
1239
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
@@ -1280,39 +1301,29 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1280
1301
|
itemToString: itemToString,
|
|
1281
1302
|
itemToKey: itemToKey,
|
|
1282
1303
|
onStateChange: function onStateChange(_ref4) {
|
|
1283
|
-
var newSelectedItems = _ref4.selectedItems
|
|
1284
|
-
|
|
1285
|
-
switch (type) {
|
|
1286
|
-
case downshift.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownBackspace:
|
|
1287
|
-
case downshift.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownDelete:
|
|
1288
|
-
case downshift.useMultipleSelection.stateChangeTypes.DropdownKeyDownBackspace:
|
|
1289
|
-
case downshift.useMultipleSelection.stateChangeTypes.FunctionRemoveSelectedItem:
|
|
1290
|
-
{
|
|
1291
|
-
if (newSelectedItems !== undefined) onChange(newSelectedItems);
|
|
1292
|
-
break;
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1304
|
+
var newSelectedItems = _ref4.selectedItems;
|
|
1305
|
+
if (newSelectedItems !== undefined) onChange(newSelectedItems);
|
|
1295
1306
|
}
|
|
1296
1307
|
}),
|
|
1297
1308
|
getSelectedItemProps = _useMultipleSelection.getSelectedItemProps,
|
|
1298
1309
|
getDropdownProps = _useMultipleSelection.getDropdownProps;
|
|
1299
|
-
var stateReducer = React.useCallback(function (
|
|
1310
|
+
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
1300
1311
|
var changes = _ref5.changes,
|
|
1301
1312
|
type = _ref5.type;
|
|
1302
1313
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
1303
1314
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
1304
1315
|
}
|
|
1305
1316
|
switch (type) {
|
|
1317
|
+
// reset input value when leaving input field
|
|
1318
|
+
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
1319
|
+
return _extends({}, changes, {
|
|
1320
|
+
inputValue: EMPTY_INPUT
|
|
1321
|
+
});
|
|
1306
1322
|
// keep menu open and edit input value on item selection
|
|
1307
1323
|
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1308
1324
|
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
1309
1325
|
{
|
|
1310
1326
|
var _inputRef$current$val, _inputRef$current;
|
|
1311
|
-
if (clearInputOnSelect) {
|
|
1312
|
-
updateListItems({
|
|
1313
|
-
inputValue: EMPTY_INPUT
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
1327
|
return _extends({}, changes, {
|
|
1317
1328
|
isOpen: true,
|
|
1318
1329
|
inputValue: clearInputOnSelect ? EMPTY_INPUT : (_inputRef$current$val = inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value) != null ? _inputRef$current$val : EMPTY_INPUT
|
|
@@ -1333,38 +1344,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1333
1344
|
var leadingWhitespaceTest = /^\s+/g;
|
|
1334
1345
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
1335
1346
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
1336
|
-
|
|
1347
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
1337
1348
|
if (isSpacePressedOnEmptyInput) {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1349
|
+
if (!state.isOpen) return _extends({}, changes, {
|
|
1350
|
+
inputValue: sanitizedInputValue,
|
|
1351
|
+
isOpen: true
|
|
1352
|
+
});
|
|
1353
|
+
if (changes.highlightedIndex !== undefined) {
|
|
1354
|
+
return _extends({}, changes, {
|
|
1355
|
+
inputValue: sanitizedInputValue,
|
|
1356
|
+
selectedItem: listItems[changes.highlightedIndex]
|
|
1343
1357
|
});
|
|
1344
1358
|
}
|
|
1345
1359
|
}
|
|
1346
|
-
} else {
|
|
1347
|
-
updateListItems({
|
|
1348
|
-
inputValue: changes.inputValue
|
|
1349
|
-
});
|
|
1350
|
-
// set highlighted item to first item after search
|
|
1351
|
-
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1352
|
-
return _extends({}, changes, {
|
|
1353
|
-
highlightedIndex: hideSelectAll ? 0 : 1
|
|
1354
|
-
});
|
|
1355
1360
|
}
|
|
1356
1361
|
return changes;
|
|
1357
1362
|
}
|
|
1358
|
-
// reset input value when leaving input field
|
|
1359
|
-
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
1360
|
-
{
|
|
1361
|
-
updateListItems({
|
|
1362
|
-
inputValue: EMPTY_INPUT
|
|
1363
|
-
});
|
|
1364
|
-
return _extends({}, changes, {
|
|
1365
|
-
inputValue: EMPTY_INPUT
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
1363
|
default:
|
|
1369
1364
|
return changes;
|
|
1370
1365
|
}
|
|
@@ -1376,24 +1371,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1376
1371
|
itemToString: itemToString,
|
|
1377
1372
|
selectedItem: null,
|
|
1378
1373
|
stateReducer: stateReducer,
|
|
1374
|
+
onInputValueChange: function onInputValueChange(changes) {
|
|
1375
|
+
updateListItems({
|
|
1376
|
+
inputValue: changes.inputValue
|
|
1377
|
+
});
|
|
1378
|
+
// set highlighted item to first item after search
|
|
1379
|
+
setHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1380
|
+
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1381
|
+
},
|
|
1379
1382
|
onStateChange: function onStateChange(_ref6) {
|
|
1380
|
-
var
|
|
1381
|
-
clickedItem = _ref6.selectedItem;
|
|
1383
|
+
var clickedItem = _ref6.selectedItem;
|
|
1382
1384
|
// clickedItem means item chosen either via mouse or keyboard
|
|
1383
1385
|
if (!clickedItem) return;
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter: // eslint-disable-line no-fallthrough
|
|
1389
|
-
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
1390
|
-
{
|
|
1391
|
-
handleListItemClicked({
|
|
1392
|
-
clickedItem: clickedItem,
|
|
1393
|
-
onChange: onChange
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1386
|
+
handleListItemClicked({
|
|
1387
|
+
clickedItem: clickedItem,
|
|
1388
|
+
onChange: onChange
|
|
1389
|
+
});
|
|
1397
1390
|
},
|
|
1398
1391
|
// Accessibility
|
|
1399
1392
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1409,28 +1402,44 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1409
1402
|
getMenuProps = _useCombobox.getMenuProps,
|
|
1410
1403
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1411
1404
|
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1405
|
+
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1412
1406
|
inputValue = _useCombobox.inputValue,
|
|
1413
1407
|
isOpen = _useCombobox.isOpen,
|
|
1414
|
-
openMenu = _useCombobox.openMenu,
|
|
1415
1408
|
setInputValue = _useCombobox.setInputValue;
|
|
1409
|
+
// calculations for floating-UI popover position
|
|
1416
1410
|
var _useFloating = reactDom.useFloating({
|
|
1417
|
-
placement: 'bottom-start',
|
|
1418
1411
|
open: isOpen,
|
|
1419
|
-
|
|
1412
|
+
placement: 'bottom-start',
|
|
1413
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.shift({
|
|
1414
|
+
padding: tokens.space.extraSmall
|
|
1415
|
+
}), reactDom.size({
|
|
1416
|
+
apply: function apply(_ref7) {
|
|
1417
|
+
var rects = _ref7.rects,
|
|
1418
|
+
elements = _ref7.elements,
|
|
1419
|
+
availableHeight = _ref7.availableHeight;
|
|
1420
|
+
Object.assign(elements.floating.style, {
|
|
1421
|
+
width: rects.reference.width + "px",
|
|
1422
|
+
// Floating will flip when smaller than 10*16 px
|
|
1423
|
+
// and never exceed 20*16 px.
|
|
1424
|
+
maxHeight: clamp(10 * 16, availableHeight, 20 * 16) + "px"
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
}), reactDom.flip({
|
|
1428
|
+
fallbackStrategy: 'initialPlacement'
|
|
1429
|
+
})]
|
|
1420
1430
|
}),
|
|
1421
1431
|
refs = _useFloating.refs,
|
|
1422
1432
|
floatingStyles = _useFloating.floatingStyles,
|
|
1423
|
-
elements = _useFloating.elements,
|
|
1424
1433
|
update = _useFloating.update;
|
|
1425
|
-
//
|
|
1426
|
-
//
|
|
1427
|
-
//
|
|
1434
|
+
// Update floating-ui position on scroll etc. Floating-ui's autoupdate is usually used inside
|
|
1435
|
+
// the useFloating hook but this requires the floating element to be conditionally rendered.
|
|
1436
|
+
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1437
|
+
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1428
1438
|
React.useEffect(function () {
|
|
1429
|
-
if (isOpen &&
|
|
1430
|
-
|
|
1431
|
-
return cleanup;
|
|
1439
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1440
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1432
1441
|
}
|
|
1433
|
-
}, [isOpen,
|
|
1442
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1434
1443
|
var handleOnClear = function handleOnClear() {
|
|
1435
1444
|
var _inputRef$current3;
|
|
1436
1445
|
onChange([]);
|
|
@@ -1441,20 +1450,6 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1441
1450
|
});
|
|
1442
1451
|
};
|
|
1443
1452
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1444
|
-
append: React.createElement(FieldAppend$1, {
|
|
1445
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1446
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1447
|
-
selectedItems: selectedItems,
|
|
1448
|
-
isOpen: isOpen,
|
|
1449
|
-
clearable: clearable,
|
|
1450
|
-
labelClearSelectedItems: labelClearAllItems,
|
|
1451
|
-
focusable: false,
|
|
1452
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1453
|
-
loadingText: loadingText,
|
|
1454
|
-
disabled: readOnly || disabled,
|
|
1455
|
-
onClear: handleOnClear,
|
|
1456
|
-
getToggleButtonProps: getToggleButtonProps
|
|
1457
|
-
}),
|
|
1458
1453
|
className: classNames('eds-dropdown', 'eds-dropdown--multiselect', className, {
|
|
1459
1454
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1460
1455
|
}),
|
|
@@ -1466,27 +1461,44 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1466
1461
|
labelId: getLabelProps().id,
|
|
1467
1462
|
labelProps: getLabelProps(),
|
|
1468
1463
|
labelTooltip: labelTooltip,
|
|
1464
|
+
onBlur: function onBlur() {
|
|
1465
|
+
return setInputValue('');
|
|
1466
|
+
},
|
|
1469
1467
|
onClick: function onClick(e) {
|
|
1470
|
-
|
|
1471
|
-
|
|
1468
|
+
if (e.target === e.currentTarget) {
|
|
1469
|
+
var _getInputProps;
|
|
1470
|
+
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1471
|
+
}
|
|
1472
1472
|
},
|
|
1473
1473
|
readOnly: readOnly,
|
|
1474
1474
|
ref: refs.setReference,
|
|
1475
1475
|
style: style,
|
|
1476
|
-
variant: variant
|
|
1476
|
+
variant: variant,
|
|
1477
|
+
after: React.createElement(DropdownList, {
|
|
1478
|
+
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1479
|
+
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1480
|
+
floatingStyles: floatingStyles,
|
|
1481
|
+
getItemProps: getItemProps,
|
|
1482
|
+
getMenuProps: getMenuProps,
|
|
1483
|
+
highlightedIndex: highlightedIndex,
|
|
1484
|
+
isOpen: isOpen,
|
|
1485
|
+
listItems: listItems,
|
|
1486
|
+
style: listStyle,
|
|
1487
|
+
setListRef: refs.setFloating,
|
|
1488
|
+
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1489
|
+
loadingText: loadingText,
|
|
1490
|
+
noMatchesText: noMatchesText,
|
|
1491
|
+
selectAllCheckboxState: selectAllCheckboxState,
|
|
1492
|
+
selectAllItem: selectAll,
|
|
1493
|
+
selectedItems: selectedItems
|
|
1494
|
+
})
|
|
1477
1495
|
}, rest), React.createElement("div", {
|
|
1478
1496
|
className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
|
|
1479
1497
|
'eds-dropdown--multiselect__selected-items-and-input--filled': hasSelectedItems
|
|
1480
|
-
})
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
}, selectedItems.length <= maxChips ? React.createElement(React.Fragment, null, selectedItems.length > 1 ? React.createElement(a11y.VisuallyHidden, {
|
|
1485
|
-
onClick: function onClick() {
|
|
1486
|
-
var _inputRef$current5;
|
|
1487
|
-
return (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.focus();
|
|
1488
|
-
}
|
|
1489
|
-
}, ariaLabelJumpToInput) : React.createElement(React.Fragment, null), selectedItems.map(function (selectedItem, index) {
|
|
1498
|
+
})
|
|
1499
|
+
}, selectedItems.length > 1 ? React.createElement(a11y.VisuallyHidden, {
|
|
1500
|
+
onClick: (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus
|
|
1501
|
+
}, ariaLabelJumpToInput) : null, selectedItems.length <= maxChips ? selectedItems.map(function (selectedItem, index) {
|
|
1490
1502
|
return React.createElement(SelectedItemTag, {
|
|
1491
1503
|
ariaLabelChosen: ariaLabelChosenSingular,
|
|
1492
1504
|
ariaLabelRemoveSelected: ariaLabelRemoveSelected,
|
|
@@ -1496,27 +1508,23 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1496
1508
|
key: (selectedItem == null ? void 0 : selectedItem.label) + (typeof (selectedItem == null ? void 0 : selectedItem.value) === 'string' ? selectedItem.value : ''),
|
|
1497
1509
|
readOnly: readOnly,
|
|
1498
1510
|
removeSelectedItem: function removeSelectedItem() {
|
|
1499
|
-
var _inputRef$
|
|
1511
|
+
var _inputRef$current5;
|
|
1500
1512
|
handleListItemClicked({
|
|
1501
1513
|
clickedItem: selectedItem,
|
|
1502
1514
|
onChange: onChange
|
|
1503
1515
|
});
|
|
1504
|
-
inputRef == null || (_inputRef$
|
|
1516
|
+
inputRef == null || (_inputRef$current5 = inputRef.current) == null || _inputRef$current5.focus();
|
|
1505
1517
|
},
|
|
1506
1518
|
selectedItem: selectedItem
|
|
1507
1519
|
});
|
|
1508
|
-
})
|
|
1520
|
+
}) : React.createElement(SelectedItemTag, {
|
|
1509
1521
|
ariaLabelRemoveSelected: labelClearAllItems,
|
|
1510
1522
|
ariaLabelChosen: "",
|
|
1511
1523
|
disabled: disabled,
|
|
1512
1524
|
readOnly: readOnly,
|
|
1513
1525
|
removeSelectedItem: handleOnClear,
|
|
1514
1526
|
selectedItem: summarySelectedItems
|
|
1515
|
-
}), React.createElement("input", _extends({
|
|
1516
|
-
placeholder: placeholder,
|
|
1517
|
-
className: "eds-dropdown__input eds-form-control",
|
|
1518
|
-
disabled: readOnly || disabled
|
|
1519
|
-
}, getInputProps(_extends({
|
|
1527
|
+
}), React.createElement("input", _extends({}, getInputProps(_extends({
|
|
1520
1528
|
onKeyDown: function onKeyDown(e) {
|
|
1521
1529
|
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1522
1530
|
var highlitedItem = listItems[highlightedIndex];
|
|
@@ -1532,34 +1540,37 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1532
1540
|
}, getDropdownProps({
|
|
1533
1541
|
preventKeyAction: isOpen,
|
|
1534
1542
|
value: inputValue != null ? inputValue : EMPTY_INPUT,
|
|
1535
|
-
ref: inputRef
|
|
1536
|
-
})
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1543
|
+
ref: utils.mergeRefs(inputRef, ref)
|
|
1544
|
+
}), {
|
|
1545
|
+
className: 'eds-dropdown__input eds-form-control',
|
|
1546
|
+
disabled: readOnly || disabled,
|
|
1547
|
+
placeholder: placeholder,
|
|
1548
|
+
tabIndex: disabled || readOnly ? -1 : undefined
|
|
1549
|
+
}))))), React.createElement(DropdownFieldAppendix, _extends({}, getToggleButtonProps({
|
|
1550
|
+
'aria-busy': !(loading != null ? loading : resolvedItemsLoading) ? undefined : 'true'
|
|
1551
|
+
}), {
|
|
1552
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1553
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1554
|
+
clearable: clearable,
|
|
1555
|
+
disabled: disabled || readOnly,
|
|
1556
|
+
onClear: handleOnClear,
|
|
1557
|
+
focusable: false,
|
|
1558
|
+
labelClearSelected: labelClearAllItems,
|
|
1544
1559
|
isOpen: isOpen,
|
|
1545
|
-
|
|
1546
|
-
style: listStyle,
|
|
1547
|
-
setListRef: refs.setFloating,
|
|
1548
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1560
|
+
itemIsSelected: selectedItems.length > 0,
|
|
1549
1561
|
loadingText: loadingText,
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
selectedItems: selectedItems
|
|
1554
|
-
}));
|
|
1555
|
-
};
|
|
1562
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1563
|
+
})));
|
|
1564
|
+
});
|
|
1556
1565
|
|
|
1557
1566
|
var _excluded$1 = ["ariaLabelChosenSingular", "ariaLabelCloseList", "ariaLabelOpenList", "ariaLabelSelectedItem", "className", "clearable", "disabled", "disableLabelAnimation", "feedback", "items", "label", "labelClearSelectedItem", "labelTooltip", "listStyle", "loading", "loadingText", "noMatchesText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
|
|
1558
|
-
var Dropdown = function
|
|
1559
|
-
var
|
|
1567
|
+
var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1568
|
+
var _getLabelProps, _selectedItem$label;
|
|
1560
1569
|
var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1561
|
-
|
|
1562
|
-
|
|
1570
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
1571
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
1572
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
1573
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
1563
1574
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
1564
1575
|
className = _ref.className,
|
|
1565
1576
|
_ref$clearable = _ref.clearable,
|
|
@@ -1575,7 +1586,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1575
1586
|
labelTooltip = _ref.labelTooltip,
|
|
1576
1587
|
listStyle = _ref.listStyle,
|
|
1577
1588
|
loading = _ref.loading,
|
|
1578
|
-
loadingText = _ref.loadingText,
|
|
1589
|
+
_ref$loadingText = _ref.loadingText,
|
|
1590
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1579
1591
|
_ref$noMatchesText = _ref.noMatchesText,
|
|
1580
1592
|
noMatchesText = _ref$noMatchesText === void 0 ? 'Ingen tilgjengelige valg …' : _ref$noMatchesText,
|
|
1581
1593
|
onChange = _ref.onChange,
|
|
@@ -1595,7 +1607,6 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1595
1607
|
var _useResolvedItems = useResolvedItems(initialItems),
|
|
1596
1608
|
normalizedItems = _useResolvedItems.items,
|
|
1597
1609
|
resolvedItemsLoading = _useResolvedItems.loading;
|
|
1598
|
-
var toggleButtonRef = React.useRef(null);
|
|
1599
1610
|
var isFilled = selectedItem !== null || placeholder !== undefined;
|
|
1600
1611
|
var _useSelect = downshift.useSelect({
|
|
1601
1612
|
items: normalizedItems,
|
|
@@ -1605,128 +1616,128 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1605
1616
|
var type = _ref2.type,
|
|
1606
1617
|
newSelectedItem = _ref2.selectedItem;
|
|
1607
1618
|
switch (type) {
|
|
1608
|
-
// @ts-expect-error This falltrough is wanted
|
|
1609
1619
|
case downshift.useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
1610
|
-
if (!selectOnBlur)
|
|
1611
|
-
case downshift.useSelect.stateChangeTypes.ToggleButtonKeyDownEnter: // eslint-disable-line no-fallthrough
|
|
1612
|
-
case downshift.useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
1613
|
-
case downshift.useSelect.stateChangeTypes.ItemClick:
|
|
1614
|
-
{
|
|
1615
|
-
if (newSelectedItem === undefined) return;
|
|
1616
|
-
onChange == null || onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1617
|
-
}
|
|
1620
|
+
if (!selectOnBlur) return;
|
|
1618
1621
|
}
|
|
1622
|
+
if (newSelectedItem === undefined) return;
|
|
1623
|
+
onChange == null || onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1619
1624
|
},
|
|
1620
1625
|
itemToString: itemToString
|
|
1621
1626
|
}),
|
|
1622
1627
|
isOpen = _useSelect.isOpen,
|
|
1623
|
-
openMenu = _useSelect.openMenu,
|
|
1624
1628
|
getItemProps = _useSelect.getItemProps,
|
|
1625
1629
|
getLabelProps = _useSelect.getLabelProps,
|
|
1626
1630
|
getMenuProps = _useSelect.getMenuProps,
|
|
1627
1631
|
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
1628
1632
|
highlightedIndex = _useSelect.highlightedIndex;
|
|
1633
|
+
// calculations for floating-UI popover position
|
|
1629
1634
|
var _useFloating = reactDom.useFloating({
|
|
1630
|
-
placement: 'bottom-start',
|
|
1631
1635
|
open: isOpen,
|
|
1632
|
-
|
|
1636
|
+
placement: 'bottom-start',
|
|
1637
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.shift({
|
|
1638
|
+
padding: tokens.space.extraSmall
|
|
1639
|
+
}), reactDom.size({
|
|
1640
|
+
apply: function apply(_ref3) {
|
|
1641
|
+
var rects = _ref3.rects,
|
|
1642
|
+
elements = _ref3.elements,
|
|
1643
|
+
availableHeight = _ref3.availableHeight;
|
|
1644
|
+
Object.assign(elements.floating.style, {
|
|
1645
|
+
width: rects.reference.width + "px",
|
|
1646
|
+
// Floating will flip when smaller than 10*16 px
|
|
1647
|
+
// and never exceed 20*16 px.
|
|
1648
|
+
maxHeight: clamp(10 * 16, availableHeight, 20 * 16) + "px"
|
|
1649
|
+
});
|
|
1650
|
+
}
|
|
1651
|
+
}), reactDom.flip({
|
|
1652
|
+
fallbackStrategy: 'initialPlacement'
|
|
1653
|
+
})]
|
|
1633
1654
|
}),
|
|
1634
1655
|
refs = _useFloating.refs,
|
|
1635
1656
|
floatingStyles = _useFloating.floatingStyles,
|
|
1636
|
-
elements = _useFloating.elements,
|
|
1637
1657
|
update = _useFloating.update;
|
|
1638
|
-
//
|
|
1639
|
-
//
|
|
1640
|
-
//
|
|
1658
|
+
// Update floating-ui position on scroll etc. Floating-ui's autoupdate is usually used inside
|
|
1659
|
+
// the useFloating hook but this requires the floating element to be conditionally rendered.
|
|
1660
|
+
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1661
|
+
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1641
1662
|
React.useEffect(function () {
|
|
1642
|
-
if (isOpen &&
|
|
1643
|
-
|
|
1644
|
-
return cleanup;
|
|
1663
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1664
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1645
1665
|
}
|
|
1646
|
-
}, [isOpen,
|
|
1666
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1647
1667
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1648
|
-
append: React.createElement(FieldAppend$1, {
|
|
1649
|
-
ariaHiddenToggleButton: true,
|
|
1650
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1651
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1652
|
-
clearable: clearable,
|
|
1653
|
-
labelClearSelectedItems: labelClearSelectedItem,
|
|
1654
|
-
focusable: false,
|
|
1655
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
1656
|
-
isOpen: isOpen,
|
|
1657
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1658
|
-
loadingText: loadingText,
|
|
1659
|
-
onClear: function onClear() {
|
|
1660
|
-
var _toggleButtonRef$curr;
|
|
1661
|
-
onChange == null || onChange(null);
|
|
1662
|
-
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
1663
|
-
},
|
|
1664
|
-
disabled: readOnly || disabled,
|
|
1665
|
-
selectedItems: [selectedItem]
|
|
1666
|
-
}),
|
|
1667
1668
|
className: classNames('eds-dropdown', className, {
|
|
1668
1669
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1669
1670
|
}),
|
|
1670
|
-
disabled: disabled,
|
|
1671
1671
|
disableLabelAnimation: disableLabelAnimation,
|
|
1672
1672
|
feedback: feedback,
|
|
1673
1673
|
isFilled: isFilled,
|
|
1674
|
-
label: label,
|
|
1675
|
-
labelId: getLabelProps().id,
|
|
1676
1674
|
labelProps: getLabelProps(),
|
|
1677
1675
|
labelTooltip: labelTooltip,
|
|
1678
|
-
onClick: function onClick(e) {
|
|
1679
|
-
if (e.target === e.currentTarget) openMenu();
|
|
1680
|
-
},
|
|
1681
1676
|
prepend: prepend,
|
|
1682
|
-
readOnly: readOnly,
|
|
1683
|
-
ref: refs.setReference,
|
|
1684
1677
|
style: style,
|
|
1685
1678
|
variant: variant
|
|
1686
|
-
}, rest), React.createElement("div", _extends({
|
|
1687
|
-
className: "eds-dropdown__selected-item"
|
|
1688
1679
|
}, getToggleButtonProps({
|
|
1689
|
-
|
|
1690
|
-
onKeyDown: function onKeyDown(e) {
|
|
1691
|
-
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1692
|
-
// we don't want to clear selection with tab
|
|
1693
|
-
var highlitedItem = normalizedItems[highlightedIndex];
|
|
1694
|
-
if (highlitedItem) {
|
|
1695
|
-
onChange == null || onChange(highlitedItem);
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
},
|
|
1699
|
-
ref: toggleButtonRef,
|
|
1680
|
+
ref: utils.mergeRefs(ref, refs.setReference),
|
|
1700
1681
|
'aria-disabled': disabled,
|
|
1701
1682
|
'aria-label': disabled ? 'Disabled dropdown' : '',
|
|
1702
1683
|
disabled: disabled,
|
|
1703
|
-
|
|
1704
|
-
|
|
1684
|
+
readOnly: readOnly,
|
|
1685
|
+
label: label,
|
|
1686
|
+
labelId: (_getLabelProps = getLabelProps()) == null ? void 0 : _getLabelProps.id,
|
|
1687
|
+
children: undefined,
|
|
1688
|
+
tabIndex: disabled || readOnly ? -1 : 0,
|
|
1689
|
+
onKeyDown: function onKeyDown(e) {
|
|
1690
|
+
if (isOpen && (selectOnTab || selectOnBlur) && e.key === 'Tab' && highlightedIndex !== undefined) onChange == null || onChange(normalizedItems[highlightedIndex]);
|
|
1691
|
+
}
|
|
1692
|
+
}), {
|
|
1693
|
+
after: React.createElement(DropdownList, {
|
|
1694
|
+
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1695
|
+
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1696
|
+
floatingStyles: floatingStyles,
|
|
1697
|
+
getItemProps: getItemProps,
|
|
1698
|
+
getMenuProps: getMenuProps,
|
|
1699
|
+
highlightedIndex: highlightedIndex,
|
|
1700
|
+
isOpen: isOpen,
|
|
1701
|
+
listItems: normalizedItems,
|
|
1702
|
+
noMatchesText: noMatchesText,
|
|
1703
|
+
style: listStyle,
|
|
1704
|
+
setListRef: refs.setFloating,
|
|
1705
|
+
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1706
|
+
loadingText: loadingText,
|
|
1707
|
+
selectedItems: selectedItem !== null ? [selectedItem] : []
|
|
1708
|
+
})
|
|
1709
|
+
}, rest, {
|
|
1710
|
+
// Append is not supported as of now
|
|
1711
|
+
append: undefined
|
|
1712
|
+
}), React.createElement("div", {
|
|
1713
|
+
className: "eds-dropdown__selected-item"
|
|
1714
|
+
}, (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : React.createElement("div", {
|
|
1705
1715
|
className: classNames('eds-dropdown__selected-item__placeholder', {
|
|
1706
1716
|
'eds-dropdown__selected-item__placeholder--readonly': readOnly
|
|
1707
1717
|
})
|
|
1708
|
-
}, placeholder))
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1718
|
+
}, placeholder)), React.createElement(DropdownFieldAppendix, {
|
|
1719
|
+
"aria-busy": !(loading != null ? loading : resolvedItemsLoading) ? undefined : 'true',
|
|
1720
|
+
"aria-expanded": isOpen,
|
|
1721
|
+
clearable: clearable,
|
|
1722
|
+
onClear: function onClear() {
|
|
1723
|
+
return onChange == null ? void 0 : onChange(null);
|
|
1724
|
+
},
|
|
1725
|
+
disabled: disabled || readOnly,
|
|
1726
|
+
focusable: false,
|
|
1727
|
+
labelClearSelected: labelClearSelectedItem,
|
|
1715
1728
|
isOpen: isOpen,
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
loadingText: loadingText,
|
|
1722
|
-
selectedItems: selectedItem !== null ? [selectedItem] : []
|
|
1729
|
+
itemIsSelected: selectedItem !== null,
|
|
1730
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1731
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1732
|
+
loading: false,
|
|
1733
|
+
loadingText: undefined
|
|
1723
1734
|
}));
|
|
1724
|
-
};
|
|
1735
|
+
});
|
|
1725
1736
|
|
|
1726
1737
|
var _excluded = ["className", "disabled", "disableLabelAnimation", "feedback", "items", "label", "loadingText", "onChange", "prepend", "readOnly", "selectedItem", "style", "value", "variant"];
|
|
1727
1738
|
/** @deprecated use variant="negative" instead */
|
|
1728
1739
|
var error = 'error';
|
|
1729
|
-
var NativeDropdown = function
|
|
1740
|
+
var NativeDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1730
1741
|
var _ref2;
|
|
1731
1742
|
var className = _ref.className,
|
|
1732
1743
|
_ref$disabled = _ref.disabled,
|
|
@@ -1782,14 +1793,15 @@ var NativeDropdown = function NativeDropdown(_ref) {
|
|
|
1782
1793
|
target: event.target
|
|
1783
1794
|
});
|
|
1784
1795
|
},
|
|
1785
|
-
value: (_ref2 = value != null ? value : selectedItem == null ? void 0 : selectedItem.value) != null ? _ref2 : undefined
|
|
1796
|
+
value: (_ref2 = value != null ? value : selectedItem == null ? void 0 : selectedItem.value) != null ? _ref2 : undefined,
|
|
1797
|
+
ref: ref
|
|
1786
1798
|
}, rest), normalizedItems.map(function (item) {
|
|
1787
1799
|
return React.createElement("option", {
|
|
1788
1800
|
key: item.value,
|
|
1789
1801
|
value: item.value
|
|
1790
1802
|
}, item.label);
|
|
1791
1803
|
})));
|
|
1792
|
-
};
|
|
1804
|
+
});
|
|
1793
1805
|
var FieldAppend = function FieldAppend(_ref3) {
|
|
1794
1806
|
var loading = _ref3.loading,
|
|
1795
1807
|
loadingText = _ref3.loadingText,
|