@entur/dropdown 7.0.3 → 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/README.md +2 -2
- package/dist/Dropdown.d.ts +4 -2
- package/dist/MultiSelect.d.ts +54 -72
- package/dist/NativeDropdown.d.ts +1 -1
- package/dist/SearchableDropdown.d.ts +16 -79
- package/dist/components/DropdownList.d.ts +2 -2
- package/dist/components/FieldComponents.d.ts +15 -13
- package/dist/dropdown.cjs.development.js +453 -438
- 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 +457 -442
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +21 -28
- package/dist/utils.d.ts +4 -0
- package/package.json +11 -11
|
@@ -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
|
|
|
@@ -691,7 +672,7 @@ debounceTimeout) {
|
|
|
691
672
|
_context.next = 11;
|
|
692
673
|
break;
|
|
693
674
|
}
|
|
694
|
-
console.warn('Avbryt den asynkrone funksjonen din med signalet fra AbortController-en for å for å unngå minnelekkasje.', 'Funksjonen bør kaste en DOMException med navnet "AbortError" når den avbrytes.', '', '\n\nSe eksempel her: https://
|
|
675
|
+
console.warn('Avbryt den asynkrone funksjonen din med signalet fra AbortController-en for å for å unngå minnelekkasje.', 'Funksjonen bør kaste en DOMException med navnet "AbortError" når den avbrytes.', '', '\n\nSe eksempel her: https://linje.entur.no/komponenter/skjemaelementer/dropdown#s%C3%B8kbar-dropdown-med-valg-fra-nettverkskall-bassert-p%C3%A5-tekstinput', '\nLes mer om AbortController her: https://developer.mozilla.org/en-US/docs/Web/API/AbortController');
|
|
695
676
|
return _context.abrupt("return");
|
|
696
677
|
case 11:
|
|
697
678
|
setLoading(false);
|
|
@@ -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,
|
|
@@ -871,12 +861,14 @@ function getA11yStatusMessage(options) {
|
|
|
871
861
|
}
|
|
872
862
|
/* end a11y utils */
|
|
873
863
|
|
|
874
|
-
var _excluded$3 = ["ariaLabelChosenSingular", "ariaLabelCloseList", "ariaLabelOpenList", "ariaLabelSelectedItem", "className", "clearable", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "items", "itemFilter", "label", "labelClearSelectedItem", "labelTooltip", "listStyle", "loadingText", "noMatchesText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
|
|
875
|
-
var SearchableDropdown = function
|
|
876
|
-
var _document, _selectedItem$label;
|
|
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"];
|
|
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,
|
|
@@ -895,8 +887,11 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
895
887
|
labelClearSelectedItem = _ref$labelClearSelect === void 0 ? 'fjern valgt' : _ref$labelClearSelect,
|
|
896
888
|
labelTooltip = _ref.labelTooltip,
|
|
897
889
|
listStyle = _ref.listStyle,
|
|
898
|
-
|
|
899
|
-
|
|
890
|
+
loading = _ref.loading,
|
|
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,
|
|
900
895
|
_ref$onChange = _ref.onChange,
|
|
901
896
|
onChange = _ref$onChange === void 0 ? function () {
|
|
902
897
|
return undefined;
|
|
@@ -923,7 +918,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
923
918
|
var inputRef = React.useRef(null);
|
|
924
919
|
var _useResolvedItems = useResolvedItems(initialItems, debounceTimeout),
|
|
925
920
|
normalizedItems = _useResolvedItems.items,
|
|
926
|
-
|
|
921
|
+
resolvedItemsLoading = _useResolvedItems.loading,
|
|
927
922
|
fetchItems = _useResolvedItems.fetchItems;
|
|
928
923
|
var _useState3 = React.useState(normalizedItems),
|
|
929
924
|
listItems = _useState3[0],
|
|
@@ -942,6 +937,15 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
942
937
|
inputValue: inputValue != null ? inputValue : EMPTY_INPUT
|
|
943
938
|
});
|
|
944
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
|
+
};
|
|
945
949
|
var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
|
|
946
950
|
React.useEffect(function () {
|
|
947
951
|
filterListItems({
|
|
@@ -958,9 +962,9 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
958
962
|
setInputValue(EMPTY_INPUT);
|
|
959
963
|
}
|
|
960
964
|
}, []);
|
|
961
|
-
var stateReducer = React.useCallback(function (
|
|
962
|
-
var type =
|
|
963
|
-
changes =
|
|
965
|
+
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
966
|
+
var type = _ref5.type,
|
|
967
|
+
changes = _ref5.changes;
|
|
964
968
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
965
969
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
966
970
|
}
|
|
@@ -969,67 +973,61 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
969
973
|
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
970
974
|
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
971
975
|
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
972
|
-
{
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
});
|
|
976
|
-
return _extends({}, changes, {
|
|
977
|
-
inputValue: EMPTY_INPUT
|
|
978
|
-
});
|
|
979
|
-
}
|
|
976
|
+
return resetInputState({
|
|
977
|
+
changes: changes
|
|
978
|
+
});
|
|
980
979
|
case downshift.useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
981
980
|
if (changes.selectedItem !== null && !inputHasFocus) setShowSelectedItem(true);
|
|
982
|
-
|
|
983
|
-
|
|
981
|
+
return resetInputState({
|
|
982
|
+
changes: changes
|
|
984
983
|
});
|
|
985
|
-
|
|
986
|
-
inputValue: EMPTY_INPUT
|
|
987
|
-
});
|
|
988
|
-
// 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
|
|
989
985
|
case downshift.useCombobox.stateChangeTypes.InputChange:
|
|
990
986
|
{
|
|
991
987
|
var _changes$inputValue;
|
|
988
|
+
setLastHighlightedIndex(0);
|
|
992
989
|
var leadingWhitespaceTest = /^\s+/g;
|
|
993
990
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
994
991
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
995
|
-
|
|
992
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
996
993
|
if (isSpacePressedOnEmptyInput) {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
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
|
+
});
|
|
1000
1005
|
}
|
|
1001
1006
|
}
|
|
1002
|
-
} else {
|
|
1003
|
-
updateListItems({
|
|
1004
|
-
inputValue: changes.inputValue
|
|
1005
|
-
});
|
|
1006
|
-
setHighlightedIndex(0);
|
|
1007
|
-
setLastHighlightedIndex(0);
|
|
1008
1007
|
}
|
|
1009
|
-
return changes
|
|
1008
|
+
return _extends({}, changes, {
|
|
1009
|
+
highlightedIndex: 0
|
|
1010
|
+
});
|
|
1010
1011
|
}
|
|
1011
1012
|
default:
|
|
1012
1013
|
return changes;
|
|
1013
1014
|
}
|
|
1014
|
-
}, [fetchItems, filterListItems]);
|
|
1015
|
-
var _useCombobox = downshift.useCombobox(
|
|
1015
|
+
}, [fetchItems, filterListItems, inputHasFocus, resetInputState]);
|
|
1016
|
+
var _useCombobox = downshift.useCombobox({
|
|
1016
1017
|
defaultHighlightedIndex: lastHighlightedIndex,
|
|
1017
1018
|
items: listItems,
|
|
1018
1019
|
itemToString: itemToString,
|
|
1019
1020
|
selectedItem: value,
|
|
1020
1021
|
stateReducer: stateReducer,
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
if (newSelectedItem === undefined) return;
|
|
1031
|
-
onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1032
|
-
}
|
|
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);
|
|
1033
1031
|
},
|
|
1034
1032
|
// Accessibility
|
|
1035
1033
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1037,37 +1035,51 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1037
1035
|
resultCount: listItems.length
|
|
1038
1036
|
}));
|
|
1039
1037
|
}
|
|
1040
|
-
}
|
|
1038
|
+
}),
|
|
1041
1039
|
isOpen = _useCombobox.isOpen,
|
|
1042
|
-
openMenu = _useCombobox.openMenu,
|
|
1043
1040
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1044
1041
|
getLabelProps = _useCombobox.getLabelProps,
|
|
1045
1042
|
getMenuProps = _useCombobox.getMenuProps,
|
|
1046
1043
|
getInputProps = _useCombobox.getInputProps,
|
|
1047
1044
|
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1048
|
-
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1049
1045
|
getItemProps = _useCombobox.getItemProps,
|
|
1050
1046
|
selectedItem = _useCombobox.selectedItem,
|
|
1051
1047
|
inputValue = _useCombobox.inputValue,
|
|
1052
1048
|
setInputValue = _useCombobox.setInputValue;
|
|
1049
|
+
// calculations for floating-UI popover position
|
|
1053
1050
|
var _useFloating = reactDom.useFloating({
|
|
1054
|
-
placement: 'bottom-start',
|
|
1055
1051
|
open: isOpen,
|
|
1056
|
-
|
|
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
|
+
})]
|
|
1057
1070
|
}),
|
|
1058
1071
|
refs = _useFloating.refs,
|
|
1059
1072
|
floatingStyles = _useFloating.floatingStyles,
|
|
1060
|
-
elements = _useFloating.elements,
|
|
1061
1073
|
update = _useFloating.update;
|
|
1062
|
-
//
|
|
1063
|
-
//
|
|
1064
|
-
//
|
|
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
|
|
1065
1078
|
React.useEffect(function () {
|
|
1066
|
-
if (isOpen &&
|
|
1067
|
-
|
|
1068
|
-
return cleanup;
|
|
1079
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1080
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1069
1081
|
}
|
|
1070
|
-
}, [isOpen,
|
|
1082
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1071
1083
|
var handleOnClear = function handleOnClear() {
|
|
1072
1084
|
var _inputRef$current;
|
|
1073
1085
|
onChange(null);
|
|
@@ -1079,20 +1091,6 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1079
1091
|
setShowSelectedItem(false);
|
|
1080
1092
|
};
|
|
1081
1093
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1082
|
-
append: React.createElement(FieldAppend$1, {
|
|
1083
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1084
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1085
|
-
clearable: clearable,
|
|
1086
|
-
labelClearSelectedItems: labelClearSelectedItem,
|
|
1087
|
-
disabled: readOnly || disabled,
|
|
1088
|
-
focusable: false,
|
|
1089
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
1090
|
-
isOpen: isOpen,
|
|
1091
|
-
loading: loading,
|
|
1092
|
-
loadingText: loadingText,
|
|
1093
|
-
onClear: handleOnClear,
|
|
1094
|
-
selectedItems: [selectedItem]
|
|
1095
|
-
}),
|
|
1096
1094
|
className: classNames('eds-dropdown', 'eds-dropdown--searchable', className, {
|
|
1097
1095
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1098
1096
|
}),
|
|
@@ -1104,31 +1102,50 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1104
1102
|
labelId: getLabelProps().id,
|
|
1105
1103
|
labelProps: getLabelProps(),
|
|
1106
1104
|
labelTooltip: labelTooltip,
|
|
1105
|
+
onBlur: function onBlur() {
|
|
1106
|
+
return setInputValue('');
|
|
1107
|
+
},
|
|
1107
1108
|
onClick: function onClick(e) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1109
|
+
if (e.target === e.currentTarget) {
|
|
1110
|
+
var _getInputProps;
|
|
1111
|
+
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1112
|
+
}
|
|
1110
1113
|
},
|
|
1111
1114
|
prepend: prepend,
|
|
1112
1115
|
readOnly: readOnly,
|
|
1113
1116
|
ref: refs.setReference,
|
|
1114
1117
|
style: style,
|
|
1115
|
-
|
|
1116
|
-
|
|
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", {
|
|
1117
1140
|
className: classNames('eds-dropdown--searchable__selected-item', {
|
|
1118
1141
|
'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
|
|
1119
1142
|
}),
|
|
1120
1143
|
"aria-hidden": "true",
|
|
1121
|
-
onClick:
|
|
1122
|
-
var _inputRef$current3;
|
|
1123
|
-
(_inputRef$current3 = inputRef.current) == null || _inputRef$current3.focus();
|
|
1124
|
-
openMenu();
|
|
1125
|
-
}
|
|
1144
|
+
onClick: (_getInputProps2 = getInputProps()) == null ? void 0 : _getInputProps2.onClick
|
|
1126
1145
|
}, showSelectedItem ? selectedItem == null ? void 0 : selectedItem.label : ''), React.createElement("input", _extends({
|
|
1127
1146
|
className: classNames('eds-dropdown__input eds-form-control', {
|
|
1128
1147
|
'eds-dropdown__input--hidden': showSelectedItem
|
|
1129
|
-
})
|
|
1130
|
-
disabled: readOnly || disabled,
|
|
1131
|
-
placeholder: (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : placeholder
|
|
1148
|
+
})
|
|
1132
1149
|
}, getInputProps({
|
|
1133
1150
|
onBlur: function onBlur() {
|
|
1134
1151
|
if (selectedItem !== null) setShowSelectedItem(true);
|
|
@@ -1137,29 +1154,33 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1137
1154
|
setShowSelectedItem(false);
|
|
1138
1155
|
},
|
|
1139
1156
|
onKeyDown: function onKeyDown(e) {
|
|
1140
|
-
if (
|
|
1157
|
+
if (isOpen && (selectOnTab || selectOnBlur) && e.key === 'Tab' && highlightedIndex !== undefined) onChange(listItems[highlightedIndex]);
|
|
1141
1158
|
},
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
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,
|
|
1150
1174
|
isOpen: isOpen,
|
|
1151
|
-
|
|
1152
|
-
style: listStyle,
|
|
1153
|
-
setListRef: refs.setFloating,
|
|
1154
|
-
loading: loading,
|
|
1175
|
+
itemIsSelected: selectedItem !== null,
|
|
1155
1176
|
loadingText: loadingText,
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
};
|
|
1177
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1178
|
+
})));
|
|
1179
|
+
});
|
|
1160
1180
|
|
|
1161
|
-
var _excluded$2 = ["className", "clearable", "clearInputOnSelect", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "hideSelectAll", "items", "itemFilter", "label", "labelAllItemsSelected", "labelClearAllItems", "labelSelectAll", "labelTooltip", "listStyle", "loadingText", "maxChips", "noMatchesText", "onChange", "placeholder", "readOnly", "selectedItems", "selectOnBlur", "selectOnTab", "style", "variant", "ariaLabelChosenSingular", "ariaLabelChosenPlural", "ariaLabelCloseList", "ariaLabelJumpToInput", "ariaLabelOpenList", "ariaLabelRemoveSelected", "ariaLabelSelectedItem"];
|
|
1162
|
-
var MultiSelect = function
|
|
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"];
|
|
1182
|
+
var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1183
|
+
var _inputRef$current4;
|
|
1163
1184
|
var className = _ref.className,
|
|
1164
1185
|
_ref$clearable = _ref.clearable,
|
|
1165
1186
|
clearable = _ref$clearable === void 0 ? true : _ref$clearable,
|
|
@@ -1184,7 +1205,9 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1184
1205
|
labelSelectAll = _ref$labelSelectAll === void 0 ? 'Velg alle' : _ref$labelSelectAll,
|
|
1185
1206
|
labelTooltip = _ref.labelTooltip,
|
|
1186
1207
|
listStyle = _ref.listStyle,
|
|
1187
|
-
|
|
1208
|
+
loading = _ref.loading,
|
|
1209
|
+
_ref$loadingText = _ref.loadingText,
|
|
1210
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1188
1211
|
_ref$maxChips = _ref.maxChips,
|
|
1189
1212
|
maxChips = _ref$maxChips === void 0 ? 10 : _ref$maxChips,
|
|
1190
1213
|
noMatchesText = _ref.noMatchesText,
|
|
@@ -1197,8 +1220,6 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1197
1220
|
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
1198
1221
|
_ref$selectedItems = _ref.selectedItems,
|
|
1199
1222
|
selectedItems = _ref$selectedItems === void 0 ? [] : _ref$selectedItems,
|
|
1200
|
-
_ref$selectOnBlur = _ref.selectOnBlur,
|
|
1201
|
-
selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
|
|
1202
1223
|
_ref$selectOnTab = _ref.selectOnTab,
|
|
1203
1224
|
selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
|
|
1204
1225
|
style = _ref.style,
|
|
@@ -1207,10 +1228,12 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1207
1228
|
ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1208
1229
|
_ref$ariaLabelChosenP = _ref.ariaLabelChosenPlural,
|
|
1209
1230
|
ariaLabelChosenPlural = _ref$ariaLabelChosenP === void 0 ? 'valgte' : _ref$ariaLabelChosenP,
|
|
1210
|
-
|
|
1231
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
1232
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
1211
1233
|
_ref$ariaLabelJumpToI = _ref.ariaLabelJumpToInput,
|
|
1212
1234
|
ariaLabelJumpToInput = _ref$ariaLabelJumpToI === void 0 ? selectedItems.length + " valgte elementer, trykk for \xE5 hoppe til tekstfeltet" : _ref$ariaLabelJumpToI,
|
|
1213
|
-
|
|
1235
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
1236
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
1214
1237
|
_ref$ariaLabelRemoveS = _ref.ariaLabelRemoveSelected,
|
|
1215
1238
|
ariaLabelRemoveSelected = _ref$ariaLabelRemoveS === void 0 ? 'trykk for å fjerne valg' : _ref$ariaLabelRemoveS,
|
|
1216
1239
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
@@ -1226,7 +1249,7 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1226
1249
|
}, [rest.selectedItem]);
|
|
1227
1250
|
var _useResolvedItems = useResolvedItems(initialItems, debounceTimeout),
|
|
1228
1251
|
normalizedItems = _useResolvedItems.items,
|
|
1229
|
-
|
|
1252
|
+
resolvedItemsLoading = _useResolvedItems.loading,
|
|
1230
1253
|
fetchItems = _useResolvedItems.fetchItems;
|
|
1231
1254
|
var isAllNonAsyncItemsSelected = typeof initialItems !== 'function' && selectedItems.length === normalizedItems.length;
|
|
1232
1255
|
// special 'item' used as Select All entry in the dropdown list
|
|
@@ -1278,39 +1301,29 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1278
1301
|
itemToString: itemToString,
|
|
1279
1302
|
itemToKey: itemToKey,
|
|
1280
1303
|
onStateChange: function onStateChange(_ref4) {
|
|
1281
|
-
var newSelectedItems = _ref4.selectedItems
|
|
1282
|
-
|
|
1283
|
-
switch (type) {
|
|
1284
|
-
case downshift.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownBackspace:
|
|
1285
|
-
case downshift.useMultipleSelection.stateChangeTypes.SelectedItemKeyDownDelete:
|
|
1286
|
-
case downshift.useMultipleSelection.stateChangeTypes.DropdownKeyDownBackspace:
|
|
1287
|
-
case downshift.useMultipleSelection.stateChangeTypes.FunctionRemoveSelectedItem:
|
|
1288
|
-
{
|
|
1289
|
-
if (newSelectedItems !== undefined) onChange(newSelectedItems);
|
|
1290
|
-
break;
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1304
|
+
var newSelectedItems = _ref4.selectedItems;
|
|
1305
|
+
if (newSelectedItems !== undefined) onChange(newSelectedItems);
|
|
1293
1306
|
}
|
|
1294
1307
|
}),
|
|
1295
1308
|
getSelectedItemProps = _useMultipleSelection.getSelectedItemProps,
|
|
1296
1309
|
getDropdownProps = _useMultipleSelection.getDropdownProps;
|
|
1297
|
-
var stateReducer = React.useCallback(function (
|
|
1310
|
+
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
1298
1311
|
var changes = _ref5.changes,
|
|
1299
1312
|
type = _ref5.type;
|
|
1300
1313
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
1301
1314
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
1302
1315
|
}
|
|
1303
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
|
+
});
|
|
1304
1322
|
// keep menu open and edit input value on item selection
|
|
1305
1323
|
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1306
1324
|
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
1307
1325
|
{
|
|
1308
1326
|
var _inputRef$current$val, _inputRef$current;
|
|
1309
|
-
if (clearInputOnSelect) {
|
|
1310
|
-
updateListItems({
|
|
1311
|
-
inputValue: EMPTY_INPUT
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
1327
|
return _extends({}, changes, {
|
|
1315
1328
|
isOpen: true,
|
|
1316
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
|
|
@@ -1331,38 +1344,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1331
1344
|
var leadingWhitespaceTest = /^\s+/g;
|
|
1332
1345
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
1333
1346
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
1334
|
-
|
|
1347
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
1335
1348
|
if (isSpacePressedOnEmptyInput) {
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
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]
|
|
1341
1357
|
});
|
|
1342
1358
|
}
|
|
1343
1359
|
}
|
|
1344
|
-
} else {
|
|
1345
|
-
updateListItems({
|
|
1346
|
-
inputValue: changes.inputValue
|
|
1347
|
-
});
|
|
1348
|
-
// set highlighted item to first item after search
|
|
1349
|
-
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1350
|
-
return _extends({}, changes, {
|
|
1351
|
-
highlightedIndex: hideSelectAll ? 0 : 1
|
|
1352
|
-
});
|
|
1353
1360
|
}
|
|
1354
1361
|
return changes;
|
|
1355
1362
|
}
|
|
1356
|
-
// reset input value when leaving input field
|
|
1357
|
-
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
1358
|
-
{
|
|
1359
|
-
updateListItems({
|
|
1360
|
-
inputValue: EMPTY_INPUT
|
|
1361
|
-
});
|
|
1362
|
-
return _extends({}, changes, {
|
|
1363
|
-
inputValue: EMPTY_INPUT
|
|
1364
|
-
});
|
|
1365
|
-
}
|
|
1366
1363
|
default:
|
|
1367
1364
|
return changes;
|
|
1368
1365
|
}
|
|
@@ -1374,24 +1371,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1374
1371
|
itemToString: itemToString,
|
|
1375
1372
|
selectedItem: null,
|
|
1376
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
|
+
},
|
|
1377
1382
|
onStateChange: function onStateChange(_ref6) {
|
|
1378
|
-
var
|
|
1379
|
-
clickedItem = _ref6.selectedItem;
|
|
1383
|
+
var clickedItem = _ref6.selectedItem;
|
|
1380
1384
|
// clickedItem means item chosen either via mouse or keyboard
|
|
1381
1385
|
if (!clickedItem) return;
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter: // eslint-disable-line no-fallthrough
|
|
1387
|
-
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
1388
|
-
{
|
|
1389
|
-
handleListItemClicked({
|
|
1390
|
-
clickedItem: clickedItem,
|
|
1391
|
-
onChange: onChange
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1386
|
+
handleListItemClicked({
|
|
1387
|
+
clickedItem: clickedItem,
|
|
1388
|
+
onChange: onChange
|
|
1389
|
+
});
|
|
1395
1390
|
},
|
|
1396
1391
|
// Accessibility
|
|
1397
1392
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1407,28 +1402,44 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1407
1402
|
getMenuProps = _useCombobox.getMenuProps,
|
|
1408
1403
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1409
1404
|
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1405
|
+
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1410
1406
|
inputValue = _useCombobox.inputValue,
|
|
1411
1407
|
isOpen = _useCombobox.isOpen,
|
|
1412
|
-
openMenu = _useCombobox.openMenu,
|
|
1413
1408
|
setInputValue = _useCombobox.setInputValue;
|
|
1409
|
+
// calculations for floating-UI popover position
|
|
1414
1410
|
var _useFloating = reactDom.useFloating({
|
|
1415
|
-
placement: 'bottom-start',
|
|
1416
1411
|
open: isOpen,
|
|
1417
|
-
|
|
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
|
+
})]
|
|
1418
1430
|
}),
|
|
1419
1431
|
refs = _useFloating.refs,
|
|
1420
1432
|
floatingStyles = _useFloating.floatingStyles,
|
|
1421
|
-
elements = _useFloating.elements,
|
|
1422
1433
|
update = _useFloating.update;
|
|
1423
|
-
//
|
|
1424
|
-
//
|
|
1425
|
-
//
|
|
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
|
|
1426
1438
|
React.useEffect(function () {
|
|
1427
|
-
if (isOpen &&
|
|
1428
|
-
|
|
1429
|
-
return cleanup;
|
|
1439
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1440
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1430
1441
|
}
|
|
1431
|
-
}, [isOpen,
|
|
1442
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1432
1443
|
var handleOnClear = function handleOnClear() {
|
|
1433
1444
|
var _inputRef$current3;
|
|
1434
1445
|
onChange([]);
|
|
@@ -1439,20 +1450,6 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1439
1450
|
});
|
|
1440
1451
|
};
|
|
1441
1452
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1442
|
-
append: React.createElement(FieldAppend$1, {
|
|
1443
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1444
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1445
|
-
selectedItems: selectedItems,
|
|
1446
|
-
isOpen: isOpen,
|
|
1447
|
-
clearable: clearable,
|
|
1448
|
-
labelClearSelectedItems: labelClearAllItems,
|
|
1449
|
-
focusable: false,
|
|
1450
|
-
loading: loading,
|
|
1451
|
-
loadingText: loadingText,
|
|
1452
|
-
disabled: readOnly || disabled,
|
|
1453
|
-
onClear: handleOnClear,
|
|
1454
|
-
getToggleButtonProps: getToggleButtonProps
|
|
1455
|
-
}),
|
|
1456
1453
|
className: classNames('eds-dropdown', 'eds-dropdown--multiselect', className, {
|
|
1457
1454
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1458
1455
|
}),
|
|
@@ -1464,27 +1461,44 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1464
1461
|
labelId: getLabelProps().id,
|
|
1465
1462
|
labelProps: getLabelProps(),
|
|
1466
1463
|
labelTooltip: labelTooltip,
|
|
1464
|
+
onBlur: function onBlur() {
|
|
1465
|
+
return setInputValue('');
|
|
1466
|
+
},
|
|
1467
1467
|
onClick: function onClick(e) {
|
|
1468
|
-
|
|
1469
|
-
|
|
1468
|
+
if (e.target === e.currentTarget) {
|
|
1469
|
+
var _getInputProps;
|
|
1470
|
+
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1471
|
+
}
|
|
1470
1472
|
},
|
|
1471
1473
|
readOnly: readOnly,
|
|
1472
1474
|
ref: refs.setReference,
|
|
1473
1475
|
style: style,
|
|
1474
|
-
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
|
+
})
|
|
1475
1495
|
}, rest), React.createElement("div", {
|
|
1476
1496
|
className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
|
|
1477
1497
|
'eds-dropdown--multiselect__selected-items-and-input--filled': hasSelectedItems
|
|
1478
|
-
})
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
}, selectedItems.length <= maxChips ? React.createElement(React.Fragment, null, selectedItems.length > 1 ? React.createElement(a11y.VisuallyHidden, {
|
|
1483
|
-
onClick: function onClick() {
|
|
1484
|
-
var _inputRef$current5;
|
|
1485
|
-
return (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.focus();
|
|
1486
|
-
}
|
|
1487
|
-
}, 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) {
|
|
1488
1502
|
return React.createElement(SelectedItemTag, {
|
|
1489
1503
|
ariaLabelChosen: ariaLabelChosenSingular,
|
|
1490
1504
|
ariaLabelRemoveSelected: ariaLabelRemoveSelected,
|
|
@@ -1494,27 +1508,23 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1494
1508
|
key: (selectedItem == null ? void 0 : selectedItem.label) + (typeof (selectedItem == null ? void 0 : selectedItem.value) === 'string' ? selectedItem.value : ''),
|
|
1495
1509
|
readOnly: readOnly,
|
|
1496
1510
|
removeSelectedItem: function removeSelectedItem() {
|
|
1497
|
-
var _inputRef$
|
|
1511
|
+
var _inputRef$current5;
|
|
1498
1512
|
handleListItemClicked({
|
|
1499
1513
|
clickedItem: selectedItem,
|
|
1500
1514
|
onChange: onChange
|
|
1501
1515
|
});
|
|
1502
|
-
inputRef == null || (_inputRef$
|
|
1516
|
+
inputRef == null || (_inputRef$current5 = inputRef.current) == null || _inputRef$current5.focus();
|
|
1503
1517
|
},
|
|
1504
1518
|
selectedItem: selectedItem
|
|
1505
1519
|
});
|
|
1506
|
-
})
|
|
1520
|
+
}) : React.createElement(SelectedItemTag, {
|
|
1507
1521
|
ariaLabelRemoveSelected: labelClearAllItems,
|
|
1508
1522
|
ariaLabelChosen: "",
|
|
1509
1523
|
disabled: disabled,
|
|
1510
1524
|
readOnly: readOnly,
|
|
1511
1525
|
removeSelectedItem: handleOnClear,
|
|
1512
1526
|
selectedItem: summarySelectedItems
|
|
1513
|
-
}), React.createElement("input", _extends({
|
|
1514
|
-
placeholder: placeholder,
|
|
1515
|
-
className: "eds-dropdown__input eds-form-control",
|
|
1516
|
-
disabled: readOnly || disabled
|
|
1517
|
-
}, getInputProps(_extends({
|
|
1527
|
+
}), React.createElement("input", _extends({}, getInputProps(_extends({
|
|
1518
1528
|
onKeyDown: function onKeyDown(e) {
|
|
1519
1529
|
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1520
1530
|
var highlitedItem = listItems[highlightedIndex];
|
|
@@ -1530,34 +1540,37 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1530
1540
|
}, getDropdownProps({
|
|
1531
1541
|
preventKeyAction: isOpen,
|
|
1532
1542
|
value: inputValue != null ? inputValue : EMPTY_INPUT,
|
|
1533
|
-
ref: inputRef
|
|
1534
|
-
})
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
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,
|
|
1542
1559
|
isOpen: isOpen,
|
|
1543
|
-
|
|
1544
|
-
style: listStyle,
|
|
1545
|
-
setListRef: refs.setFloating,
|
|
1546
|
-
loading: loading,
|
|
1560
|
+
itemIsSelected: selectedItems.length > 0,
|
|
1547
1561
|
loadingText: loadingText,
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
selectedItems: selectedItems
|
|
1552
|
-
}));
|
|
1553
|
-
};
|
|
1562
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1563
|
+
})));
|
|
1564
|
+
});
|
|
1554
1565
|
|
|
1555
|
-
var _excluded$1 = ["ariaLabelChosenSingular", "ariaLabelCloseList", "ariaLabelOpenList", "ariaLabelSelectedItem", "className", "clearable", "disabled", "disableLabelAnimation", "feedback", "items", "label", "labelClearSelectedItem", "labelTooltip", "listStyle", "loadingText", "noMatchesText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
|
|
1556
|
-
var Dropdown = function
|
|
1557
|
-
var
|
|
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"];
|
|
1567
|
+
var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1568
|
+
var _getLabelProps, _selectedItem$label;
|
|
1558
1569
|
var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1559
|
-
|
|
1560
|
-
|
|
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,
|
|
1561
1574
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
1562
1575
|
className = _ref.className,
|
|
1563
1576
|
_ref$clearable = _ref.clearable,
|
|
@@ -1572,7 +1585,9 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1572
1585
|
labelClearSelectedItem = _ref$labelClearSelect === void 0 ? 'fjern valgt' : _ref$labelClearSelect,
|
|
1573
1586
|
labelTooltip = _ref.labelTooltip,
|
|
1574
1587
|
listStyle = _ref.listStyle,
|
|
1575
|
-
|
|
1588
|
+
loading = _ref.loading,
|
|
1589
|
+
_ref$loadingText = _ref.loadingText,
|
|
1590
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1576
1591
|
_ref$noMatchesText = _ref.noMatchesText,
|
|
1577
1592
|
noMatchesText = _ref$noMatchesText === void 0 ? 'Ingen tilgjengelige valg …' : _ref$noMatchesText,
|
|
1578
1593
|
onChange = _ref.onChange,
|
|
@@ -1591,8 +1606,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1591
1606
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
1592
1607
|
var _useResolvedItems = useResolvedItems(initialItems),
|
|
1593
1608
|
normalizedItems = _useResolvedItems.items,
|
|
1594
|
-
|
|
1595
|
-
var toggleButtonRef = React.useRef(null);
|
|
1609
|
+
resolvedItemsLoading = _useResolvedItems.loading;
|
|
1596
1610
|
var isFilled = selectedItem !== null || placeholder !== undefined;
|
|
1597
1611
|
var _useSelect = downshift.useSelect({
|
|
1598
1612
|
items: normalizedItems,
|
|
@@ -1602,128 +1616,128 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1602
1616
|
var type = _ref2.type,
|
|
1603
1617
|
newSelectedItem = _ref2.selectedItem;
|
|
1604
1618
|
switch (type) {
|
|
1605
|
-
// @ts-expect-error This falltrough is wanted
|
|
1606
1619
|
case downshift.useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
1607
|
-
if (!selectOnBlur)
|
|
1608
|
-
case downshift.useSelect.stateChangeTypes.ToggleButtonKeyDownEnter: // eslint-disable-line no-fallthrough
|
|
1609
|
-
case downshift.useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
1610
|
-
case downshift.useSelect.stateChangeTypes.ItemClick:
|
|
1611
|
-
{
|
|
1612
|
-
if (newSelectedItem === undefined) return;
|
|
1613
|
-
onChange == null || onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1614
|
-
}
|
|
1620
|
+
if (!selectOnBlur) return;
|
|
1615
1621
|
}
|
|
1622
|
+
if (newSelectedItem === undefined) return;
|
|
1623
|
+
onChange == null || onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1616
1624
|
},
|
|
1617
1625
|
itemToString: itemToString
|
|
1618
1626
|
}),
|
|
1619
1627
|
isOpen = _useSelect.isOpen,
|
|
1620
|
-
openMenu = _useSelect.openMenu,
|
|
1621
1628
|
getItemProps = _useSelect.getItemProps,
|
|
1622
1629
|
getLabelProps = _useSelect.getLabelProps,
|
|
1623
1630
|
getMenuProps = _useSelect.getMenuProps,
|
|
1624
1631
|
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
1625
1632
|
highlightedIndex = _useSelect.highlightedIndex;
|
|
1633
|
+
// calculations for floating-UI popover position
|
|
1626
1634
|
var _useFloating = reactDom.useFloating({
|
|
1627
|
-
placement: 'bottom-start',
|
|
1628
1635
|
open: isOpen,
|
|
1629
|
-
|
|
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
|
+
})]
|
|
1630
1654
|
}),
|
|
1631
1655
|
refs = _useFloating.refs,
|
|
1632
1656
|
floatingStyles = _useFloating.floatingStyles,
|
|
1633
|
-
elements = _useFloating.elements,
|
|
1634
1657
|
update = _useFloating.update;
|
|
1635
|
-
//
|
|
1636
|
-
//
|
|
1637
|
-
//
|
|
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
|
|
1638
1662
|
React.useEffect(function () {
|
|
1639
|
-
if (isOpen &&
|
|
1640
|
-
|
|
1641
|
-
return cleanup;
|
|
1663
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1664
|
+
return reactDom.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1642
1665
|
}
|
|
1643
|
-
}, [isOpen,
|
|
1666
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1644
1667
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1645
|
-
append: React.createElement(FieldAppend$1, {
|
|
1646
|
-
ariaHiddenToggleButton: true,
|
|
1647
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1648
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1649
|
-
clearable: clearable,
|
|
1650
|
-
labelClearSelectedItems: labelClearSelectedItem,
|
|
1651
|
-
focusable: false,
|
|
1652
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
1653
|
-
isOpen: isOpen,
|
|
1654
|
-
loading: loading,
|
|
1655
|
-
loadingText: loadingText,
|
|
1656
|
-
onClear: function onClear() {
|
|
1657
|
-
var _toggleButtonRef$curr;
|
|
1658
|
-
onChange == null || onChange(null);
|
|
1659
|
-
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
1660
|
-
},
|
|
1661
|
-
disabled: readOnly || disabled,
|
|
1662
|
-
selectedItems: [selectedItem]
|
|
1663
|
-
}),
|
|
1664
1668
|
className: classNames('eds-dropdown', className, {
|
|
1665
1669
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1666
1670
|
}),
|
|
1667
|
-
disabled: disabled,
|
|
1668
1671
|
disableLabelAnimation: disableLabelAnimation,
|
|
1669
1672
|
feedback: feedback,
|
|
1670
1673
|
isFilled: isFilled,
|
|
1671
|
-
label: label,
|
|
1672
|
-
labelId: getLabelProps().id,
|
|
1673
1674
|
labelProps: getLabelProps(),
|
|
1674
1675
|
labelTooltip: labelTooltip,
|
|
1675
|
-
onClick: function onClick(e) {
|
|
1676
|
-
if (e.target === e.currentTarget) openMenu();
|
|
1677
|
-
},
|
|
1678
1676
|
prepend: prepend,
|
|
1679
|
-
readOnly: readOnly,
|
|
1680
|
-
ref: refs.setReference,
|
|
1681
1677
|
style: style,
|
|
1682
1678
|
variant: variant
|
|
1683
|
-
}, rest), React.createElement("div", _extends({
|
|
1684
|
-
className: "eds-dropdown__selected-item"
|
|
1685
1679
|
}, getToggleButtonProps({
|
|
1686
|
-
|
|
1687
|
-
onKeyDown: function onKeyDown(e) {
|
|
1688
|
-
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1689
|
-
// we don't want to clear selection with tab
|
|
1690
|
-
var highlitedItem = normalizedItems[highlightedIndex];
|
|
1691
|
-
if (highlitedItem) {
|
|
1692
|
-
onChange == null || onChange(highlitedItem);
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
},
|
|
1696
|
-
ref: toggleButtonRef,
|
|
1680
|
+
ref: utils.mergeRefs(ref, refs.setReference),
|
|
1697
1681
|
'aria-disabled': disabled,
|
|
1698
1682
|
'aria-label': disabled ? 'Disabled dropdown' : '',
|
|
1699
1683
|
disabled: disabled,
|
|
1700
|
-
|
|
1701
|
-
|
|
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", {
|
|
1702
1715
|
className: classNames('eds-dropdown__selected-item__placeholder', {
|
|
1703
1716
|
'eds-dropdown__selected-item__placeholder--readonly': readOnly
|
|
1704
1717
|
})
|
|
1705
|
-
}, placeholder))
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
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,
|
|
1712
1728
|
isOpen: isOpen,
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
loadingText: loadingText,
|
|
1719
|
-
selectedItems: selectedItem !== null ? [selectedItem] : []
|
|
1729
|
+
itemIsSelected: selectedItem !== null,
|
|
1730
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1731
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1732
|
+
loading: false,
|
|
1733
|
+
loadingText: undefined
|
|
1720
1734
|
}));
|
|
1721
|
-
};
|
|
1735
|
+
});
|
|
1722
1736
|
|
|
1723
1737
|
var _excluded = ["className", "disabled", "disableLabelAnimation", "feedback", "items", "label", "loadingText", "onChange", "prepend", "readOnly", "selectedItem", "style", "value", "variant"];
|
|
1724
1738
|
/** @deprecated use variant="negative" instead */
|
|
1725
1739
|
var error = 'error';
|
|
1726
|
-
var NativeDropdown = function
|
|
1740
|
+
var NativeDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1727
1741
|
var _ref2;
|
|
1728
1742
|
var className = _ref.className,
|
|
1729
1743
|
_ref$disabled = _ref.disabled,
|
|
@@ -1779,14 +1793,15 @@ var NativeDropdown = function NativeDropdown(_ref) {
|
|
|
1779
1793
|
target: event.target
|
|
1780
1794
|
});
|
|
1781
1795
|
},
|
|
1782
|
-
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
|
|
1783
1798
|
}, rest), normalizedItems.map(function (item) {
|
|
1784
1799
|
return React.createElement("option", {
|
|
1785
1800
|
key: item.value,
|
|
1786
1801
|
value: item.value
|
|
1787
1802
|
}, item.label);
|
|
1788
1803
|
})));
|
|
1789
|
-
};
|
|
1804
|
+
});
|
|
1790
1805
|
var FieldAppend = function FieldAppend(_ref3) {
|
|
1791
1806
|
var loading = _ref3.loading,
|
|
1792
1807
|
loadingText = _ref3.loadingText,
|