@entur/dropdown 7.1.0 → 7.1.1
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 +466 -435
- 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 +470 -439
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +96 -103
- package/dist/utils.d.ts +4 -0
- package/package.json +8 -8
|
@@ -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,55 @@ 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
|
-
focusable:
|
|
576
|
-
})
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
"aria-
|
|
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
|
+
type: "button",
|
|
577
|
+
tabIndex: focusable ? 0 : -1
|
|
578
|
+
}), !loading ? React.createElement(icons.DownArrowIcon, {
|
|
579
|
+
"aria-hidden": "true"
|
|
580
|
+
}) : React.createElement(loader.LoadingDots, {
|
|
581
|
+
"aria-hidden": "true"
|
|
582
|
+
}))));
|
|
583
|
+
});
|
|
582
584
|
var ClearableButton = function ClearableButton(_ref4) {
|
|
583
585
|
var onClear = _ref4.onClear,
|
|
584
586
|
_ref4$labelClearSelec = _ref4.labelClearSelectedItems,
|
|
585
587
|
labelClearSelectedItems = _ref4$labelClearSelec === void 0 ? 'Fjern valgte' : _ref4$labelClearSelec,
|
|
586
588
|
_ref4$focusable = _ref4.focusable,
|
|
587
589
|
focusable = _ref4$focusable === void 0 ? false : _ref4$focusable;
|
|
588
|
-
return React.createElement(tooltip.Tooltip, {
|
|
590
|
+
return React.createElement(React.Fragment, null, React.createElement(tooltip.Tooltip, {
|
|
589
591
|
"aria-hidden": "true",
|
|
590
592
|
placement: "top",
|
|
591
593
|
content: labelClearSelectedItems,
|
|
@@ -593,36 +595,16 @@ var ClearableButton = function ClearableButton(_ref4) {
|
|
|
593
595
|
}, React.createElement(button.IconButton, {
|
|
594
596
|
className: "eds-dropdown__appendix__clear-button",
|
|
595
597
|
type: "button",
|
|
596
|
-
tabIndex: focusable ? 0 : 1,
|
|
597
|
-
onClick:
|
|
598
|
+
tabIndex: focusable ? 0 : -1,
|
|
599
|
+
onClick: function onClick(e) {
|
|
600
|
+
e.stopPropagation();
|
|
601
|
+
onClear();
|
|
602
|
+
},
|
|
598
603
|
"aria-label": labelClearSelectedItems
|
|
599
604
|
}, React.createElement(icons.CloseSmallIcon, {
|
|
600
605
|
"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"
|
|
606
|
+
}))), React.createElement("div", {
|
|
607
|
+
className: "eds-dropdown__appendix__divider"
|
|
626
608
|
}));
|
|
627
609
|
};
|
|
628
610
|
|
|
@@ -767,6 +749,15 @@ var itemToKey = function itemToKey(item) {
|
|
|
767
749
|
var isFunctionWithQueryArgument = function isFunctionWithQueryArgument(object) {
|
|
768
750
|
return typeof object === 'function' && object.length > 0;
|
|
769
751
|
};
|
|
752
|
+
var clamp = function clamp(val, min, max) {
|
|
753
|
+
if (min === void 0) {
|
|
754
|
+
min = 1;
|
|
755
|
+
}
|
|
756
|
+
if (max === void 0) {
|
|
757
|
+
max = 10;
|
|
758
|
+
}
|
|
759
|
+
return Math.min(Math.max(val, min), max);
|
|
760
|
+
};
|
|
770
761
|
var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
771
762
|
var listItems = _ref.listItems,
|
|
772
763
|
selectedItems = _ref.selectedItems,
|
|
@@ -872,11 +863,13 @@ function getA11yStatusMessage(options) {
|
|
|
872
863
|
/* end a11y utils */
|
|
873
864
|
|
|
874
865
|
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;
|
|
866
|
+
var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
867
|
+
var _document, _getInputProps2, _selectedItem$label;
|
|
877
868
|
var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
878
|
-
|
|
879
|
-
|
|
869
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
870
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
871
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
872
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
880
873
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
881
874
|
className = _ref.className,
|
|
882
875
|
_ref$clearable = _ref.clearable,
|
|
@@ -896,8 +889,10 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
896
889
|
labelTooltip = _ref.labelTooltip,
|
|
897
890
|
listStyle = _ref.listStyle,
|
|
898
891
|
loading = _ref.loading,
|
|
899
|
-
loadingText = _ref.loadingText,
|
|
900
|
-
|
|
892
|
+
_ref$loadingText = _ref.loadingText,
|
|
893
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
894
|
+
_ref$noMatchesText = _ref.noMatchesText,
|
|
895
|
+
noMatchesText = _ref$noMatchesText === void 0 ? 'Ingen tilgjengelige valg …' : _ref$noMatchesText,
|
|
901
896
|
_ref$onChange = _ref.onChange,
|
|
902
897
|
onChange = _ref$onChange === void 0 ? function () {
|
|
903
898
|
return undefined;
|
|
@@ -943,6 +938,15 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
943
938
|
inputValue: inputValue != null ? inputValue : EMPTY_INPUT
|
|
944
939
|
});
|
|
945
940
|
};
|
|
941
|
+
var resetInputState = function resetInputState(_ref4) {
|
|
942
|
+
var changes = _ref4.changes;
|
|
943
|
+
updateListItems({
|
|
944
|
+
inputValue: EMPTY_INPUT
|
|
945
|
+
});
|
|
946
|
+
return _extends({}, changes, {
|
|
947
|
+
inputValue: EMPTY_INPUT
|
|
948
|
+
});
|
|
949
|
+
};
|
|
946
950
|
var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
|
|
947
951
|
React.useEffect(function () {
|
|
948
952
|
filterListItems({
|
|
@@ -959,9 +963,9 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
959
963
|
setInputValue(EMPTY_INPUT);
|
|
960
964
|
}
|
|
961
965
|
}, []);
|
|
962
|
-
var stateReducer = React.useCallback(function (
|
|
963
|
-
var type =
|
|
964
|
-
changes =
|
|
966
|
+
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
967
|
+
var type = _ref5.type,
|
|
968
|
+
changes = _ref5.changes;
|
|
965
969
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
966
970
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
967
971
|
}
|
|
@@ -970,67 +974,59 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
970
974
|
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
971
975
|
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
972
976
|
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
973
|
-
{
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
});
|
|
977
|
-
return _extends({}, changes, {
|
|
978
|
-
inputValue: EMPTY_INPUT
|
|
979
|
-
});
|
|
980
|
-
}
|
|
977
|
+
return resetInputState({
|
|
978
|
+
changes: changes
|
|
979
|
+
});
|
|
981
980
|
case downshift.useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
982
981
|
if (changes.selectedItem !== null && !inputHasFocus) setShowSelectedItem(true);
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
});
|
|
986
|
-
return _extends({}, changes, {
|
|
987
|
-
inputValue: EMPTY_INPUT
|
|
982
|
+
return resetInputState({
|
|
983
|
+
changes: changes
|
|
988
984
|
});
|
|
989
|
-
// remove leading whitespace, select element with spacebar on empty input
|
|
985
|
+
// remove leading whitespace, select element with spacebar on empty input
|
|
990
986
|
case downshift.useCombobox.stateChangeTypes.InputChange:
|
|
991
987
|
{
|
|
992
988
|
var _changes$inputValue;
|
|
993
989
|
var leadingWhitespaceTest = /^\s+/g;
|
|
994
990
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
991
|
+
if (!isSpacePressedOnEmptyInput) setLastHighlightedIndex(0);
|
|
995
992
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
996
|
-
|
|
993
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
997
994
|
if (isSpacePressedOnEmptyInput) {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
995
|
+
if (!state.isOpen) return _extends({}, changes, {
|
|
996
|
+
inputValue: sanitizedInputValue,
|
|
997
|
+
isOpen: true
|
|
998
|
+
});
|
|
999
|
+
if (changes.highlightedIndex !== undefined) {
|
|
1000
|
+
return _extends({}, changes, {
|
|
1001
|
+
inputValue: sanitizedInputValue,
|
|
1002
|
+
selectedItem: listItems[changes.highlightedIndex]
|
|
1003
|
+
});
|
|
1001
1004
|
}
|
|
1002
1005
|
}
|
|
1003
|
-
} else {
|
|
1004
|
-
updateListItems({
|
|
1005
|
-
inputValue: changes.inputValue
|
|
1006
|
-
});
|
|
1007
|
-
setHighlightedIndex(0);
|
|
1008
|
-
setLastHighlightedIndex(0);
|
|
1009
1006
|
}
|
|
1010
|
-
return changes
|
|
1007
|
+
return _extends({}, changes, {
|
|
1008
|
+
highlightedIndex: 0
|
|
1009
|
+
});
|
|
1011
1010
|
}
|
|
1012
1011
|
default:
|
|
1013
1012
|
return changes;
|
|
1014
1013
|
}
|
|
1015
|
-
}, [fetchItems, filterListItems]);
|
|
1016
|
-
var _useCombobox = downshift.useCombobox(
|
|
1014
|
+
}, [fetchItems, filterListItems, inputHasFocus, resetInputState]);
|
|
1015
|
+
var _useCombobox = downshift.useCombobox({
|
|
1017
1016
|
defaultHighlightedIndex: lastHighlightedIndex,
|
|
1018
1017
|
items: listItems,
|
|
1019
1018
|
itemToString: itemToString,
|
|
1020
1019
|
selectedItem: value,
|
|
1021
1020
|
stateReducer: stateReducer,
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
if (newSelectedItem === undefined) return;
|
|
1032
|
-
onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1033
|
-
}
|
|
1021
|
+
onInputValueChange: function onInputValueChange(changes) {
|
|
1022
|
+
updateListItems({
|
|
1023
|
+
inputValue: changes.inputValue
|
|
1024
|
+
});
|
|
1025
|
+
},
|
|
1026
|
+
onStateChange: function onStateChange(_ref6) {
|
|
1027
|
+
var newSelectedItem = _ref6.selectedItem;
|
|
1028
|
+
if (newSelectedItem === undefined) return;
|
|
1029
|
+
onChange(newSelectedItem);
|
|
1034
1030
|
},
|
|
1035
1031
|
// Accessibility
|
|
1036
1032
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1038,37 +1034,52 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1038
1034
|
resultCount: listItems.length
|
|
1039
1035
|
}));
|
|
1040
1036
|
}
|
|
1041
|
-
}
|
|
1037
|
+
}),
|
|
1038
|
+
closeMenu = _useCombobox.closeMenu,
|
|
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,62 +1102,93 @@ 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({
|
|
1150
|
+
onKeyDown: function onKeyDown(e) {
|
|
1151
|
+
if (isOpen && e.key === 'Tab') {
|
|
1152
|
+
var highlitedItem = listItems[highlightedIndex];
|
|
1153
|
+
// we don't want to clear selection with tab
|
|
1154
|
+
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
1155
|
+
onChange == null || onChange(highlitedItem);
|
|
1156
|
+
}
|
|
1157
|
+
closeMenu();
|
|
1158
|
+
e.preventDefault();
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1134
1161
|
onBlur: function onBlur() {
|
|
1135
1162
|
if (selectedItem !== null) setShowSelectedItem(true);
|
|
1136
1163
|
},
|
|
1137
1164
|
onFocus: function onFocus() {
|
|
1138
1165
|
setShowSelectedItem(false);
|
|
1139
1166
|
},
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1167
|
+
disabled: disabled,
|
|
1168
|
+
readOnly: readOnly,
|
|
1169
|
+
placeholder: (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : placeholder,
|
|
1170
|
+
tabIndex: disabled || readOnly ? -1 : undefined,
|
|
1171
|
+
ref: utils.mergeRefs(inputRef, ref)
|
|
1172
|
+
}))), React.createElement(DropdownFieldAppendix, _extends({}, getToggleButtonProps({
|
|
1173
|
+
'aria-busy': !(loading != null ? loading : resolvedItemsLoading) ? undefined : 'true'
|
|
1174
|
+
}), {
|
|
1175
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1176
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1177
|
+
clearable: clearable,
|
|
1178
|
+
disabled: disabled || readOnly,
|
|
1179
|
+
onClear: handleOnClear,
|
|
1180
|
+
focusable: false,
|
|
1181
|
+
labelClearSelected: labelClearSelectedItem,
|
|
1151
1182
|
isOpen: isOpen,
|
|
1152
|
-
|
|
1153
|
-
style: listStyle,
|
|
1154
|
-
setListRef: refs.setFloating,
|
|
1155
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1183
|
+
itemIsSelected: selectedItem !== null,
|
|
1156
1184
|
loadingText: loadingText,
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
};
|
|
1185
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1186
|
+
})));
|
|
1187
|
+
});
|
|
1161
1188
|
|
|
1162
1189
|
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
|
|
1190
|
+
var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1191
|
+
var _inputRef$current5;
|
|
1164
1192
|
var className = _ref.className,
|
|
1165
1193
|
_ref$clearable = _ref.clearable,
|
|
1166
1194
|
clearable = _ref$clearable === void 0 ? true : _ref$clearable,
|
|
@@ -1186,7 +1214,8 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1186
1214
|
labelTooltip = _ref.labelTooltip,
|
|
1187
1215
|
listStyle = _ref.listStyle,
|
|
1188
1216
|
loading = _ref.loading,
|
|
1189
|
-
loadingText = _ref.loadingText,
|
|
1217
|
+
_ref$loadingText = _ref.loadingText,
|
|
1218
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1190
1219
|
_ref$maxChips = _ref.maxChips,
|
|
1191
1220
|
maxChips = _ref$maxChips === void 0 ? 10 : _ref$maxChips,
|
|
1192
1221
|
noMatchesText = _ref.noMatchesText,
|
|
@@ -1199,8 +1228,6 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1199
1228
|
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
1200
1229
|
_ref$selectedItems = _ref.selectedItems,
|
|
1201
1230
|
selectedItems = _ref$selectedItems === void 0 ? [] : _ref$selectedItems,
|
|
1202
|
-
_ref$selectOnBlur = _ref.selectOnBlur,
|
|
1203
|
-
selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
|
|
1204
1231
|
_ref$selectOnTab = _ref.selectOnTab,
|
|
1205
1232
|
selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
|
|
1206
1233
|
style = _ref.style,
|
|
@@ -1209,10 +1236,12 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1209
1236
|
ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1210
1237
|
_ref$ariaLabelChosenP = _ref.ariaLabelChosenPlural,
|
|
1211
1238
|
ariaLabelChosenPlural = _ref$ariaLabelChosenP === void 0 ? 'valgte' : _ref$ariaLabelChosenP,
|
|
1212
|
-
|
|
1239
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
1240
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
1213
1241
|
_ref$ariaLabelJumpToI = _ref.ariaLabelJumpToInput,
|
|
1214
1242
|
ariaLabelJumpToInput = _ref$ariaLabelJumpToI === void 0 ? selectedItems.length + " valgte elementer, trykk for \xE5 hoppe til tekstfeltet" : _ref$ariaLabelJumpToI,
|
|
1215
|
-
|
|
1243
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
1244
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
1216
1245
|
_ref$ariaLabelRemoveS = _ref.ariaLabelRemoveSelected,
|
|
1217
1246
|
ariaLabelRemoveSelected = _ref$ariaLabelRemoveS === void 0 ? 'trykk for å fjerne valg' : _ref$ariaLabelRemoveS,
|
|
1218
1247
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
@@ -1280,50 +1309,42 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1280
1309
|
itemToString: itemToString,
|
|
1281
1310
|
itemToKey: itemToKey,
|
|
1282
1311
|
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
|
-
}
|
|
1312
|
+
var newSelectedItems = _ref4.selectedItems;
|
|
1313
|
+
if (newSelectedItems !== undefined) onChange(newSelectedItems);
|
|
1295
1314
|
}
|
|
1296
1315
|
}),
|
|
1297
1316
|
getSelectedItemProps = _useMultipleSelection.getSelectedItemProps,
|
|
1298
1317
|
getDropdownProps = _useMultipleSelection.getDropdownProps;
|
|
1299
|
-
var stateReducer = React.useCallback(function (
|
|
1318
|
+
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
1319
|
+
var _inputRef$current;
|
|
1300
1320
|
var changes = _ref5.changes,
|
|
1301
1321
|
type = _ref5.type;
|
|
1302
1322
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
1303
1323
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
1304
1324
|
}
|
|
1305
1325
|
switch (type) {
|
|
1326
|
+
// reset input value when leaving input field
|
|
1327
|
+
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
1328
|
+
if (state.isOpen) (_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
|
|
1329
|
+
return _extends({}, changes, {
|
|
1330
|
+
inputValue: EMPTY_INPUT
|
|
1331
|
+
});
|
|
1306
1332
|
// keep menu open and edit input value on item selection
|
|
1307
1333
|
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1308
1334
|
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
1309
1335
|
{
|
|
1310
|
-
var _inputRef$current$val, _inputRef$
|
|
1311
|
-
if (clearInputOnSelect) {
|
|
1312
|
-
updateListItems({
|
|
1313
|
-
inputValue: EMPTY_INPUT
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1336
|
+
var _inputRef$current$val, _inputRef$current2;
|
|
1316
1337
|
return _extends({}, changes, {
|
|
1317
1338
|
isOpen: true,
|
|
1318
|
-
inputValue: clearInputOnSelect ? EMPTY_INPUT : (_inputRef$current$val = inputRef == null || (_inputRef$
|
|
1339
|
+
inputValue: clearInputOnSelect ? EMPTY_INPUT : (_inputRef$current$val = inputRef == null || (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value) != null ? _inputRef$current$val : EMPTY_INPUT
|
|
1319
1340
|
});
|
|
1320
1341
|
}
|
|
1321
1342
|
// edit input value when selected items is updated outside component
|
|
1322
1343
|
case downshift.useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
1323
1344
|
{
|
|
1324
|
-
var _inputRef$current$val2, _inputRef$
|
|
1345
|
+
var _inputRef$current$val2, _inputRef$current3;
|
|
1325
1346
|
return _extends({}, changes, {
|
|
1326
|
-
inputValue: (_inputRef$current$val2 = inputRef == null || (_inputRef$
|
|
1347
|
+
inputValue: (_inputRef$current$val2 = inputRef == null || (_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.value) != null ? _inputRef$current$val2 : EMPTY_INPUT
|
|
1327
1348
|
});
|
|
1328
1349
|
}
|
|
1329
1350
|
// remove leading whitespace, select item with spacebar if input is empty and filter list items
|
|
@@ -1333,38 +1354,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1333
1354
|
var leadingWhitespaceTest = /^\s+/g;
|
|
1334
1355
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
1335
1356
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
1336
|
-
|
|
1357
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
1337
1358
|
if (isSpacePressedOnEmptyInput) {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1359
|
+
if (!state.isOpen) return _extends({}, changes, {
|
|
1360
|
+
inputValue: sanitizedInputValue,
|
|
1361
|
+
isOpen: true
|
|
1362
|
+
});
|
|
1363
|
+
if (changes.highlightedIndex !== undefined) {
|
|
1364
|
+
return _extends({}, changes, {
|
|
1365
|
+
inputValue: sanitizedInputValue,
|
|
1366
|
+
selectedItem: listItems[changes.highlightedIndex]
|
|
1343
1367
|
});
|
|
1344
1368
|
}
|
|
1345
1369
|
}
|
|
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
1370
|
}
|
|
1356
1371
|
return changes;
|
|
1357
1372
|
}
|
|
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
1373
|
default:
|
|
1369
1374
|
return changes;
|
|
1370
1375
|
}
|
|
@@ -1376,24 +1381,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1376
1381
|
itemToString: itemToString,
|
|
1377
1382
|
selectedItem: null,
|
|
1378
1383
|
stateReducer: stateReducer,
|
|
1384
|
+
onInputValueChange: function onInputValueChange(changes) {
|
|
1385
|
+
updateListItems({
|
|
1386
|
+
inputValue: changes.inputValue
|
|
1387
|
+
});
|
|
1388
|
+
// set highlighted item to first item after search
|
|
1389
|
+
setHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1390
|
+
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1391
|
+
},
|
|
1379
1392
|
onStateChange: function onStateChange(_ref6) {
|
|
1380
|
-
var
|
|
1381
|
-
clickedItem = _ref6.selectedItem;
|
|
1393
|
+
var clickedItem = _ref6.selectedItem;
|
|
1382
1394
|
// clickedItem means item chosen either via mouse or keyboard
|
|
1383
1395
|
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
|
-
}
|
|
1396
|
+
handleListItemClicked({
|
|
1397
|
+
clickedItem: clickedItem,
|
|
1398
|
+
onChange: onChange
|
|
1399
|
+
});
|
|
1397
1400
|
},
|
|
1398
1401
|
// Accessibility
|
|
1399
1402
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1409,52 +1412,54 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1409
1412
|
getMenuProps = _useCombobox.getMenuProps,
|
|
1410
1413
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1411
1414
|
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1415
|
+
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1412
1416
|
inputValue = _useCombobox.inputValue,
|
|
1413
1417
|
isOpen = _useCombobox.isOpen,
|
|
1414
|
-
openMenu = _useCombobox.openMenu,
|
|
1415
1418
|
setInputValue = _useCombobox.setInputValue;
|
|
1419
|
+
// calculations for floating-UI popover position
|
|
1416
1420
|
var _useFloating = reactDom.useFloating({
|
|
1417
|
-
placement: 'bottom-start',
|
|
1418
1421
|
open: isOpen,
|
|
1419
|
-
|
|
1422
|
+
placement: 'bottom-start',
|
|
1423
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.shift({
|
|
1424
|
+
padding: tokens.space.extraSmall
|
|
1425
|
+
}), reactDom.size({
|
|
1426
|
+
apply: function apply(_ref7) {
|
|
1427
|
+
var rects = _ref7.rects,
|
|
1428
|
+
elements = _ref7.elements,
|
|
1429
|
+
availableHeight = _ref7.availableHeight;
|
|
1430
|
+
Object.assign(elements.floating.style, {
|
|
1431
|
+
width: rects.reference.width + "px",
|
|
1432
|
+
// Floating will flip when smaller than 10*16 px
|
|
1433
|
+
// and never exceed 20*16 px.
|
|
1434
|
+
maxHeight: clamp(10 * 16, availableHeight, 20 * 16) + "px"
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
}), reactDom.flip({
|
|
1438
|
+
fallbackStrategy: 'initialPlacement'
|
|
1439
|
+
})]
|
|
1420
1440
|
}),
|
|
1421
1441
|
refs = _useFloating.refs,
|
|
1422
1442
|
floatingStyles = _useFloating.floatingStyles,
|
|
1423
|
-
elements = _useFloating.elements,
|
|
1424
1443
|
update = _useFloating.update;
|
|
1425
|
-
//
|
|
1426
|
-
//
|
|
1427
|
-
//
|
|
1444
|
+
// Update floating-ui position on scroll etc. Floating-ui's autoupdate is usually used inside
|
|
1445
|
+
// the useFloating hook but this requires the floating element to be conditionally rendered.
|
|
1446
|
+
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1447
|
+
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1428
1448
|
React.useEffect(function () {
|
|
1429
|
-
if (isOpen &&
|
|
1430
|
-
|
|
1431
|
-
return cleanup;
|
|
1449
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1450
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1432
1451
|
}
|
|
1433
|
-
}, [isOpen,
|
|
1452
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1434
1453
|
var handleOnClear = function handleOnClear() {
|
|
1435
|
-
var _inputRef$
|
|
1454
|
+
var _inputRef$current4;
|
|
1436
1455
|
onChange([]);
|
|
1437
1456
|
setInputValue(EMPTY_INPUT);
|
|
1438
|
-
(_inputRef$
|
|
1457
|
+
(_inputRef$current4 = inputRef.current) == null || _inputRef$current4.focus();
|
|
1439
1458
|
updateListItems({
|
|
1440
1459
|
inputValue: inputValue
|
|
1441
1460
|
});
|
|
1442
1461
|
};
|
|
1443
1462
|
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
1463
|
className: classNames('eds-dropdown', 'eds-dropdown--multiselect', className, {
|
|
1459
1464
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1460
1465
|
}),
|
|
@@ -1466,27 +1471,44 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1466
1471
|
labelId: getLabelProps().id,
|
|
1467
1472
|
labelProps: getLabelProps(),
|
|
1468
1473
|
labelTooltip: labelTooltip,
|
|
1474
|
+
onBlur: function onBlur() {
|
|
1475
|
+
return setInputValue('');
|
|
1476
|
+
},
|
|
1469
1477
|
onClick: function onClick(e) {
|
|
1470
|
-
|
|
1471
|
-
|
|
1478
|
+
if (e.target === e.currentTarget) {
|
|
1479
|
+
var _getInputProps;
|
|
1480
|
+
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1481
|
+
}
|
|
1472
1482
|
},
|
|
1473
1483
|
readOnly: readOnly,
|
|
1474
1484
|
ref: refs.setReference,
|
|
1475
1485
|
style: style,
|
|
1476
|
-
variant: variant
|
|
1486
|
+
variant: variant,
|
|
1487
|
+
after: React.createElement(DropdownList, {
|
|
1488
|
+
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1489
|
+
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1490
|
+
floatingStyles: floatingStyles,
|
|
1491
|
+
getItemProps: getItemProps,
|
|
1492
|
+
getMenuProps: getMenuProps,
|
|
1493
|
+
highlightedIndex: highlightedIndex,
|
|
1494
|
+
isOpen: isOpen,
|
|
1495
|
+
listItems: listItems,
|
|
1496
|
+
style: listStyle,
|
|
1497
|
+
setListRef: refs.setFloating,
|
|
1498
|
+
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1499
|
+
loadingText: loadingText,
|
|
1500
|
+
noMatchesText: noMatchesText,
|
|
1501
|
+
selectAllCheckboxState: selectAllCheckboxState,
|
|
1502
|
+
selectAllItem: selectAll,
|
|
1503
|
+
selectedItems: selectedItems
|
|
1504
|
+
})
|
|
1477
1505
|
}, rest), React.createElement("div", {
|
|
1478
1506
|
className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
|
|
1479
1507
|
'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) {
|
|
1508
|
+
})
|
|
1509
|
+
}, selectedItems.length > 1 ? React.createElement(a11y.VisuallyHidden, {
|
|
1510
|
+
onClick: (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.focus
|
|
1511
|
+
}, ariaLabelJumpToInput) : null, selectedItems.length <= maxChips ? selectedItems.map(function (selectedItem, index) {
|
|
1490
1512
|
return React.createElement(SelectedItemTag, {
|
|
1491
1513
|
ariaLabelChosen: ariaLabelChosenSingular,
|
|
1492
1514
|
ariaLabelRemoveSelected: ariaLabelRemoveSelected,
|
|
@@ -1505,18 +1527,14 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1505
1527
|
},
|
|
1506
1528
|
selectedItem: selectedItem
|
|
1507
1529
|
});
|
|
1508
|
-
})
|
|
1530
|
+
}) : React.createElement(SelectedItemTag, {
|
|
1509
1531
|
ariaLabelRemoveSelected: labelClearAllItems,
|
|
1510
1532
|
ariaLabelChosen: "",
|
|
1511
1533
|
disabled: disabled,
|
|
1512
1534
|
readOnly: readOnly,
|
|
1513
1535
|
removeSelectedItem: handleOnClear,
|
|
1514
1536
|
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({
|
|
1537
|
+
}), React.createElement("input", _extends({}, getInputProps(_extends({
|
|
1520
1538
|
onKeyDown: function onKeyDown(e) {
|
|
1521
1539
|
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1522
1540
|
var highlitedItem = listItems[highlightedIndex];
|
|
@@ -1532,34 +1550,37 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1532
1550
|
}, getDropdownProps({
|
|
1533
1551
|
preventKeyAction: isOpen,
|
|
1534
1552
|
value: inputValue != null ? inputValue : EMPTY_INPUT,
|
|
1535
|
-
ref: inputRef
|
|
1536
|
-
})
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1553
|
+
ref: utils.mergeRefs(inputRef, ref)
|
|
1554
|
+
}), {
|
|
1555
|
+
className: 'eds-dropdown__input eds-form-control',
|
|
1556
|
+
disabled: readOnly || disabled,
|
|
1557
|
+
placeholder: placeholder,
|
|
1558
|
+
tabIndex: disabled || readOnly ? -1 : undefined
|
|
1559
|
+
}))))), React.createElement(DropdownFieldAppendix, _extends({}, getToggleButtonProps({
|
|
1560
|
+
'aria-busy': !(loading != null ? loading : resolvedItemsLoading) ? undefined : 'true'
|
|
1561
|
+
}), {
|
|
1562
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1563
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1564
|
+
clearable: clearable,
|
|
1565
|
+
disabled: disabled || readOnly,
|
|
1566
|
+
onClear: handleOnClear,
|
|
1567
|
+
focusable: false,
|
|
1568
|
+
labelClearSelected: labelClearAllItems,
|
|
1544
1569
|
isOpen: isOpen,
|
|
1545
|
-
|
|
1546
|
-
style: listStyle,
|
|
1547
|
-
setListRef: refs.setFloating,
|
|
1548
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1570
|
+
itemIsSelected: selectedItems.length > 0,
|
|
1549
1571
|
loadingText: loadingText,
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
selectedItems: selectedItems
|
|
1554
|
-
}));
|
|
1555
|
-
};
|
|
1572
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1573
|
+
})));
|
|
1574
|
+
});
|
|
1556
1575
|
|
|
1557
1576
|
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
|
|
1577
|
+
var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1578
|
+
var _getLabelProps, _selectedItem$label;
|
|
1560
1579
|
var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1561
|
-
|
|
1562
|
-
|
|
1580
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
1581
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
1582
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
1583
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
1563
1584
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
1564
1585
|
className = _ref.className,
|
|
1565
1586
|
_ref$clearable = _ref.clearable,
|
|
@@ -1575,7 +1596,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1575
1596
|
labelTooltip = _ref.labelTooltip,
|
|
1576
1597
|
listStyle = _ref.listStyle,
|
|
1577
1598
|
loading = _ref.loading,
|
|
1578
|
-
loadingText = _ref.loadingText,
|
|
1599
|
+
_ref$loadingText = _ref.loadingText,
|
|
1600
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1579
1601
|
_ref$noMatchesText = _ref.noMatchesText,
|
|
1580
1602
|
noMatchesText = _ref$noMatchesText === void 0 ? 'Ingen tilgjengelige valg …' : _ref$noMatchesText,
|
|
1581
1603
|
onChange = _ref.onChange,
|
|
@@ -1595,7 +1617,6 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1595
1617
|
var _useResolvedItems = useResolvedItems(initialItems),
|
|
1596
1618
|
normalizedItems = _useResolvedItems.items,
|
|
1597
1619
|
resolvedItemsLoading = _useResolvedItems.loading;
|
|
1598
|
-
var toggleButtonRef = React.useRef(null);
|
|
1599
1620
|
var isFilled = selectedItem !== null || placeholder !== undefined;
|
|
1600
1621
|
var _useSelect = downshift.useSelect({
|
|
1601
1622
|
items: normalizedItems,
|
|
@@ -1605,128 +1626,137 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1605
1626
|
var type = _ref2.type,
|
|
1606
1627
|
newSelectedItem = _ref2.selectedItem;
|
|
1607
1628
|
switch (type) {
|
|
1608
|
-
// @ts-expect-error This falltrough is wanted
|
|
1609
1629
|
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
|
-
}
|
|
1630
|
+
if (!selectOnBlur) return;
|
|
1618
1631
|
}
|
|
1632
|
+
if (newSelectedItem === undefined) return;
|
|
1633
|
+
onChange == null || onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1619
1634
|
},
|
|
1620
1635
|
itemToString: itemToString
|
|
1621
1636
|
}),
|
|
1637
|
+
closeMenu = _useSelect.closeMenu,
|
|
1622
1638
|
isOpen = _useSelect.isOpen,
|
|
1623
|
-
openMenu = _useSelect.openMenu,
|
|
1624
1639
|
getItemProps = _useSelect.getItemProps,
|
|
1625
1640
|
getLabelProps = _useSelect.getLabelProps,
|
|
1626
1641
|
getMenuProps = _useSelect.getMenuProps,
|
|
1627
1642
|
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
1628
1643
|
highlightedIndex = _useSelect.highlightedIndex;
|
|
1644
|
+
// calculations for floating-UI popover position
|
|
1629
1645
|
var _useFloating = reactDom.useFloating({
|
|
1630
|
-
placement: 'bottom-start',
|
|
1631
1646
|
open: isOpen,
|
|
1632
|
-
|
|
1647
|
+
placement: 'bottom-start',
|
|
1648
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.shift({
|
|
1649
|
+
padding: tokens.space.extraSmall
|
|
1650
|
+
}), reactDom.size({
|
|
1651
|
+
apply: function apply(_ref3) {
|
|
1652
|
+
var rects = _ref3.rects,
|
|
1653
|
+
elements = _ref3.elements,
|
|
1654
|
+
availableHeight = _ref3.availableHeight;
|
|
1655
|
+
Object.assign(elements.floating.style, {
|
|
1656
|
+
width: rects.reference.width + "px",
|
|
1657
|
+
// Floating will flip when smaller than 10*16 px
|
|
1658
|
+
// and never exceed 20*16 px.
|
|
1659
|
+
maxHeight: clamp(10 * 16, availableHeight, 20 * 16) + "px"
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
}), reactDom.flip({
|
|
1663
|
+
fallbackStrategy: 'initialPlacement'
|
|
1664
|
+
})]
|
|
1633
1665
|
}),
|
|
1634
1666
|
refs = _useFloating.refs,
|
|
1635
1667
|
floatingStyles = _useFloating.floatingStyles,
|
|
1636
|
-
elements = _useFloating.elements,
|
|
1637
1668
|
update = _useFloating.update;
|
|
1638
|
-
//
|
|
1639
|
-
//
|
|
1640
|
-
//
|
|
1669
|
+
// Update floating-ui position on scroll etc. Floating-ui's autoupdate is usually used inside
|
|
1670
|
+
// the useFloating hook but this requires the floating element to be conditionally rendered.
|
|
1671
|
+
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1672
|
+
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1641
1673
|
React.useEffect(function () {
|
|
1642
|
-
if (isOpen &&
|
|
1643
|
-
|
|
1644
|
-
return cleanup;
|
|
1674
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1675
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1645
1676
|
}
|
|
1646
|
-
}, [isOpen,
|
|
1677
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1647
1678
|
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
1679
|
className: classNames('eds-dropdown', className, {
|
|
1668
1680
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1669
1681
|
}),
|
|
1670
|
-
disabled: disabled,
|
|
1671
1682
|
disableLabelAnimation: disableLabelAnimation,
|
|
1672
1683
|
feedback: feedback,
|
|
1673
1684
|
isFilled: isFilled,
|
|
1674
|
-
label: label,
|
|
1675
|
-
labelId: getLabelProps().id,
|
|
1676
1685
|
labelProps: getLabelProps(),
|
|
1677
1686
|
labelTooltip: labelTooltip,
|
|
1678
|
-
onClick: function onClick(e) {
|
|
1679
|
-
if (e.target === e.currentTarget) openMenu();
|
|
1680
|
-
},
|
|
1681
1687
|
prepend: prepend,
|
|
1682
|
-
readOnly: readOnly,
|
|
1683
|
-
ref: refs.setReference,
|
|
1684
1688
|
style: style,
|
|
1685
1689
|
variant: variant
|
|
1686
|
-
}, rest), React.createElement("div", _extends({
|
|
1687
|
-
className: "eds-dropdown__selected-item"
|
|
1688
1690
|
}, getToggleButtonProps({
|
|
1689
|
-
|
|
1691
|
+
ref: utils.mergeRefs(ref, refs.setReference),
|
|
1692
|
+
'aria-disabled': disabled,
|
|
1693
|
+
'aria-label': disabled ? 'Disabled dropdown' : '',
|
|
1694
|
+
disabled: disabled,
|
|
1695
|
+
readOnly: readOnly,
|
|
1696
|
+
label: label,
|
|
1697
|
+
labelId: (_getLabelProps = getLabelProps()) == null ? void 0 : _getLabelProps.id,
|
|
1698
|
+
children: undefined,
|
|
1699
|
+
tabIndex: disabled || readOnly ? -1 : 0,
|
|
1690
1700
|
onKeyDown: function onKeyDown(e) {
|
|
1691
|
-
if (
|
|
1692
|
-
// we don't want to clear selection with tab
|
|
1701
|
+
if (isOpen && e.key === 'Tab') {
|
|
1693
1702
|
var highlitedItem = normalizedItems[highlightedIndex];
|
|
1694
|
-
|
|
1703
|
+
// we don't want to clear selection with tab
|
|
1704
|
+
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
1695
1705
|
onChange == null || onChange(highlitedItem);
|
|
1696
1706
|
}
|
|
1707
|
+
closeMenu();
|
|
1708
|
+
e.preventDefault();
|
|
1697
1709
|
}
|
|
1698
|
-
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1710
|
+
}
|
|
1711
|
+
}), {
|
|
1712
|
+
after: React.createElement(DropdownList, {
|
|
1713
|
+
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1714
|
+
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1715
|
+
floatingStyles: floatingStyles,
|
|
1716
|
+
getItemProps: getItemProps,
|
|
1717
|
+
getMenuProps: getMenuProps,
|
|
1718
|
+
highlightedIndex: highlightedIndex,
|
|
1719
|
+
isOpen: isOpen,
|
|
1720
|
+
listItems: normalizedItems,
|
|
1721
|
+
noMatchesText: noMatchesText,
|
|
1722
|
+
style: listStyle,
|
|
1723
|
+
setListRef: refs.setFloating,
|
|
1724
|
+
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1725
|
+
loadingText: loadingText,
|
|
1726
|
+
selectedItems: selectedItem !== null ? [selectedItem] : []
|
|
1727
|
+
})
|
|
1728
|
+
}, rest, {
|
|
1729
|
+
// Append is not supported as of now
|
|
1730
|
+
append: undefined
|
|
1731
|
+
}), React.createElement("div", {
|
|
1732
|
+
className: "eds-dropdown__selected-item"
|
|
1733
|
+
}, (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : React.createElement("div", {
|
|
1705
1734
|
className: classNames('eds-dropdown__selected-item__placeholder', {
|
|
1706
1735
|
'eds-dropdown__selected-item__placeholder--readonly': readOnly
|
|
1707
1736
|
})
|
|
1708
|
-
}, placeholder))
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1737
|
+
}, placeholder)), React.createElement(DropdownFieldAppendix, {
|
|
1738
|
+
"aria-busy": !(loading != null ? loading : resolvedItemsLoading) ? undefined : 'true',
|
|
1739
|
+
"aria-expanded": isOpen,
|
|
1740
|
+
clearable: clearable,
|
|
1741
|
+
onClear: function onClear() {
|
|
1742
|
+
return onChange == null ? void 0 : onChange(null);
|
|
1743
|
+
},
|
|
1744
|
+
disabled: disabled || readOnly,
|
|
1745
|
+
focusable: false,
|
|
1746
|
+
labelClearSelected: labelClearSelectedItem,
|
|
1715
1747
|
isOpen: isOpen,
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
loadingText: loadingText,
|
|
1722
|
-
selectedItems: selectedItem !== null ? [selectedItem] : []
|
|
1748
|
+
itemIsSelected: selectedItem !== null,
|
|
1749
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1750
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1751
|
+
loading: false,
|
|
1752
|
+
loadingText: undefined
|
|
1723
1753
|
}));
|
|
1724
|
-
};
|
|
1754
|
+
});
|
|
1725
1755
|
|
|
1726
1756
|
var _excluded = ["className", "disabled", "disableLabelAnimation", "feedback", "items", "label", "loadingText", "onChange", "prepend", "readOnly", "selectedItem", "style", "value", "variant"];
|
|
1727
1757
|
/** @deprecated use variant="negative" instead */
|
|
1728
1758
|
var error = 'error';
|
|
1729
|
-
var NativeDropdown = function
|
|
1759
|
+
var NativeDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1730
1760
|
var _ref2;
|
|
1731
1761
|
var className = _ref.className,
|
|
1732
1762
|
_ref$disabled = _ref.disabled,
|
|
@@ -1782,14 +1812,15 @@ var NativeDropdown = function NativeDropdown(_ref) {
|
|
|
1782
1812
|
target: event.target
|
|
1783
1813
|
});
|
|
1784
1814
|
},
|
|
1785
|
-
value: (_ref2 = value != null ? value : selectedItem == null ? void 0 : selectedItem.value) != null ? _ref2 : undefined
|
|
1815
|
+
value: (_ref2 = value != null ? value : selectedItem == null ? void 0 : selectedItem.value) != null ? _ref2 : undefined,
|
|
1816
|
+
ref: ref
|
|
1786
1817
|
}, rest), normalizedItems.map(function (item) {
|
|
1787
1818
|
return React.createElement("option", {
|
|
1788
1819
|
key: item.value,
|
|
1789
1820
|
value: item.value
|
|
1790
1821
|
}, item.label);
|
|
1791
1822
|
})));
|
|
1792
|
-
};
|
|
1823
|
+
});
|
|
1793
1824
|
var FieldAppend = function FieldAppend(_ref3) {
|
|
1794
1825
|
var loading = _ref3.loading,
|
|
1795
1826
|
loadingText = _ref3.loadingText,
|