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