@entur/dropdown 7.1.0 → 7.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Dropdown.d.ts +2 -2
- package/dist/MultiSelect.d.ts +52 -1
- package/dist/NativeDropdown.d.ts +1 -1
- package/dist/SearchableDropdown.d.ts +14 -1
- package/dist/components/DropdownList.d.ts +2 -2
- package/dist/components/FieldComponents.d.ts +15 -13
- package/dist/dropdown.cjs.development.js +443 -431
- package/dist/dropdown.cjs.development.js.map +1 -1
- package/dist/dropdown.cjs.production.min.js +1 -1
- package/dist/dropdown.cjs.production.min.js.map +1 -1
- package/dist/dropdown.esm.js +447 -435
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +21 -28
- package/dist/utils.d.ts +4 -0
- package/package.json +4 -4
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
|
|
|
@@ -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,
|
|
@@ -868,11 +858,13 @@ function getA11yStatusMessage(options) {
|
|
|
868
858
|
/* end a11y utils */
|
|
869
859
|
|
|
870
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"];
|
|
871
|
-
var SearchableDropdown = function
|
|
872
|
-
var _document, _selectedItem$label;
|
|
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,
|
|
@@ -892,8 +884,10 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
892
884
|
labelTooltip = _ref.labelTooltip,
|
|
893
885
|
listStyle = _ref.listStyle,
|
|
894
886
|
loading = _ref.loading,
|
|
895
|
-
loadingText = _ref.loadingText,
|
|
896
|
-
|
|
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,
|
|
897
891
|
_ref$onChange = _ref.onChange,
|
|
898
892
|
onChange = _ref$onChange === void 0 ? function () {
|
|
899
893
|
return undefined;
|
|
@@ -939,6 +933,15 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
939
933
|
inputValue: inputValue != null ? inputValue : EMPTY_INPUT
|
|
940
934
|
});
|
|
941
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
|
+
};
|
|
942
945
|
var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
|
|
943
946
|
useEffect(function () {
|
|
944
947
|
filterListItems({
|
|
@@ -955,9 +958,9 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
955
958
|
setInputValue(EMPTY_INPUT);
|
|
956
959
|
}
|
|
957
960
|
}, []);
|
|
958
|
-
var stateReducer = useCallback(function (
|
|
959
|
-
var type =
|
|
960
|
-
changes =
|
|
961
|
+
var stateReducer = useCallback(function (state, _ref5) {
|
|
962
|
+
var type = _ref5.type,
|
|
963
|
+
changes = _ref5.changes;
|
|
961
964
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
962
965
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
963
966
|
}
|
|
@@ -966,67 +969,61 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
966
969
|
case useCombobox.stateChangeTypes.ItemClick:
|
|
967
970
|
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
968
971
|
case useCombobox.stateChangeTypes.InputBlur:
|
|
969
|
-
{
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
});
|
|
973
|
-
return _extends({}, changes, {
|
|
974
|
-
inputValue: EMPTY_INPUT
|
|
975
|
-
});
|
|
976
|
-
}
|
|
972
|
+
return resetInputState({
|
|
973
|
+
changes: changes
|
|
974
|
+
});
|
|
977
975
|
case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
978
976
|
if (changes.selectedItem !== null && !inputHasFocus) setShowSelectedItem(true);
|
|
979
|
-
|
|
980
|
-
|
|
977
|
+
return resetInputState({
|
|
978
|
+
changes: changes
|
|
981
979
|
});
|
|
982
|
-
|
|
983
|
-
inputValue: EMPTY_INPUT
|
|
984
|
-
});
|
|
985
|
-
// 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
|
|
986
981
|
case useCombobox.stateChangeTypes.InputChange:
|
|
987
982
|
{
|
|
988
983
|
var _changes$inputValue;
|
|
984
|
+
setLastHighlightedIndex(0);
|
|
989
985
|
var leadingWhitespaceTest = /^\s+/g;
|
|
990
986
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
991
987
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
992
|
-
|
|
988
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
993
989
|
if (isSpacePressedOnEmptyInput) {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
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
|
+
});
|
|
997
1001
|
}
|
|
998
1002
|
}
|
|
999
|
-
} else {
|
|
1000
|
-
updateListItems({
|
|
1001
|
-
inputValue: changes.inputValue
|
|
1002
|
-
});
|
|
1003
|
-
setHighlightedIndex(0);
|
|
1004
|
-
setLastHighlightedIndex(0);
|
|
1005
1003
|
}
|
|
1006
|
-
return changes
|
|
1004
|
+
return _extends({}, changes, {
|
|
1005
|
+
highlightedIndex: 0
|
|
1006
|
+
});
|
|
1007
1007
|
}
|
|
1008
1008
|
default:
|
|
1009
1009
|
return changes;
|
|
1010
1010
|
}
|
|
1011
|
-
}, [fetchItems, filterListItems]);
|
|
1012
|
-
var _useCombobox = useCombobox(
|
|
1011
|
+
}, [fetchItems, filterListItems, inputHasFocus, resetInputState]);
|
|
1012
|
+
var _useCombobox = useCombobox({
|
|
1013
1013
|
defaultHighlightedIndex: lastHighlightedIndex,
|
|
1014
1014
|
items: listItems,
|
|
1015
1015
|
itemToString: itemToString,
|
|
1016
1016
|
selectedItem: value,
|
|
1017
1017
|
stateReducer: stateReducer,
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
if (newSelectedItem === undefined) return;
|
|
1028
|
-
onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1029
|
-
}
|
|
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);
|
|
1030
1027
|
},
|
|
1031
1028
|
// Accessibility
|
|
1032
1029
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1034,37 +1031,51 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1034
1031
|
resultCount: listItems.length
|
|
1035
1032
|
}));
|
|
1036
1033
|
}
|
|
1037
|
-
}
|
|
1034
|
+
}),
|
|
1038
1035
|
isOpen = _useCombobox.isOpen,
|
|
1039
|
-
openMenu = _useCombobox.openMenu,
|
|
1040
1036
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1041
1037
|
getLabelProps = _useCombobox.getLabelProps,
|
|
1042
1038
|
getMenuProps = _useCombobox.getMenuProps,
|
|
1043
1039
|
getInputProps = _useCombobox.getInputProps,
|
|
1044
1040
|
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1045
|
-
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1046
1041
|
getItemProps = _useCombobox.getItemProps,
|
|
1047
1042
|
selectedItem = _useCombobox.selectedItem,
|
|
1048
1043
|
inputValue = _useCombobox.inputValue,
|
|
1049
1044
|
setInputValue = _useCombobox.setInputValue;
|
|
1045
|
+
// calculations for floating-UI popover position
|
|
1050
1046
|
var _useFloating = useFloating({
|
|
1051
|
-
placement: 'bottom-start',
|
|
1052
1047
|
open: isOpen,
|
|
1053
|
-
|
|
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
|
+
})]
|
|
1054
1066
|
}),
|
|
1055
1067
|
refs = _useFloating.refs,
|
|
1056
1068
|
floatingStyles = _useFloating.floatingStyles,
|
|
1057
|
-
elements = _useFloating.elements,
|
|
1058
1069
|
update = _useFloating.update;
|
|
1059
|
-
//
|
|
1060
|
-
//
|
|
1061
|
-
//
|
|
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
|
|
1062
1074
|
useEffect(function () {
|
|
1063
|
-
if (isOpen &&
|
|
1064
|
-
|
|
1065
|
-
return cleanup;
|
|
1075
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1076
|
+
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1066
1077
|
}
|
|
1067
|
-
}, [isOpen,
|
|
1078
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1068
1079
|
var handleOnClear = function handleOnClear() {
|
|
1069
1080
|
var _inputRef$current;
|
|
1070
1081
|
onChange(null);
|
|
@@ -1076,20 +1087,6 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1076
1087
|
setShowSelectedItem(false);
|
|
1077
1088
|
};
|
|
1078
1089
|
return React.createElement(BaseFormControl, _extends({
|
|
1079
|
-
append: React.createElement(FieldAppend$1, {
|
|
1080
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1081
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1082
|
-
clearable: clearable,
|
|
1083
|
-
labelClearSelectedItems: labelClearSelectedItem,
|
|
1084
|
-
disabled: readOnly || disabled,
|
|
1085
|
-
focusable: false,
|
|
1086
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
1087
|
-
isOpen: isOpen,
|
|
1088
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1089
|
-
loadingText: loadingText,
|
|
1090
|
-
onClear: handleOnClear,
|
|
1091
|
-
selectedItems: [selectedItem]
|
|
1092
|
-
}),
|
|
1093
1090
|
className: classNames('eds-dropdown', 'eds-dropdown--searchable', className, {
|
|
1094
1091
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1095
1092
|
}),
|
|
@@ -1101,31 +1098,50 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1101
1098
|
labelId: getLabelProps().id,
|
|
1102
1099
|
labelProps: getLabelProps(),
|
|
1103
1100
|
labelTooltip: labelTooltip,
|
|
1101
|
+
onBlur: function onBlur() {
|
|
1102
|
+
return setInputValue('');
|
|
1103
|
+
},
|
|
1104
1104
|
onClick: function onClick(e) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1105
|
+
if (e.target === e.currentTarget) {
|
|
1106
|
+
var _getInputProps;
|
|
1107
|
+
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1108
|
+
}
|
|
1107
1109
|
},
|
|
1108
1110
|
prepend: prepend,
|
|
1109
1111
|
readOnly: readOnly,
|
|
1110
1112
|
ref: refs.setReference,
|
|
1111
1113
|
style: style,
|
|
1112
|
-
|
|
1113
|
-
|
|
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", {
|
|
1114
1136
|
className: classNames('eds-dropdown--searchable__selected-item', {
|
|
1115
1137
|
'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
|
|
1116
1138
|
}),
|
|
1117
1139
|
"aria-hidden": "true",
|
|
1118
|
-
onClick:
|
|
1119
|
-
var _inputRef$current3;
|
|
1120
|
-
(_inputRef$current3 = inputRef.current) == null || _inputRef$current3.focus();
|
|
1121
|
-
openMenu();
|
|
1122
|
-
}
|
|
1140
|
+
onClick: (_getInputProps2 = getInputProps()) == null ? void 0 : _getInputProps2.onClick
|
|
1123
1141
|
}, showSelectedItem ? selectedItem == null ? void 0 : selectedItem.label : ''), React.createElement("input", _extends({
|
|
1124
1142
|
className: classNames('eds-dropdown__input eds-form-control', {
|
|
1125
1143
|
'eds-dropdown__input--hidden': showSelectedItem
|
|
1126
|
-
})
|
|
1127
|
-
disabled: readOnly || disabled,
|
|
1128
|
-
placeholder: (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : placeholder
|
|
1144
|
+
})
|
|
1129
1145
|
}, getInputProps({
|
|
1130
1146
|
onBlur: function onBlur() {
|
|
1131
1147
|
if (selectedItem !== null) setShowSelectedItem(true);
|
|
@@ -1134,29 +1150,33 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1134
1150
|
setShowSelectedItem(false);
|
|
1135
1151
|
},
|
|
1136
1152
|
onKeyDown: function onKeyDown(e) {
|
|
1137
|
-
if (
|
|
1153
|
+
if (isOpen && (selectOnTab || selectOnBlur) && e.key === 'Tab' && highlightedIndex !== undefined) onChange(listItems[highlightedIndex]);
|
|
1138
1154
|
},
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
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,
|
|
1147
1170
|
isOpen: isOpen,
|
|
1148
|
-
|
|
1149
|
-
style: listStyle,
|
|
1150
|
-
setListRef: refs.setFloating,
|
|
1151
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1171
|
+
itemIsSelected: selectedItem !== null,
|
|
1152
1172
|
loadingText: loadingText,
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
};
|
|
1173
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1174
|
+
})));
|
|
1175
|
+
});
|
|
1157
1176
|
|
|
1158
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"];
|
|
1159
|
-
var MultiSelect = function
|
|
1178
|
+
var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1179
|
+
var _inputRef$current4;
|
|
1160
1180
|
var className = _ref.className,
|
|
1161
1181
|
_ref$clearable = _ref.clearable,
|
|
1162
1182
|
clearable = _ref$clearable === void 0 ? true : _ref$clearable,
|
|
@@ -1182,7 +1202,8 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1182
1202
|
labelTooltip = _ref.labelTooltip,
|
|
1183
1203
|
listStyle = _ref.listStyle,
|
|
1184
1204
|
loading = _ref.loading,
|
|
1185
|
-
loadingText = _ref.loadingText,
|
|
1205
|
+
_ref$loadingText = _ref.loadingText,
|
|
1206
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1186
1207
|
_ref$maxChips = _ref.maxChips,
|
|
1187
1208
|
maxChips = _ref$maxChips === void 0 ? 10 : _ref$maxChips,
|
|
1188
1209
|
noMatchesText = _ref.noMatchesText,
|
|
@@ -1195,8 +1216,6 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1195
1216
|
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
1196
1217
|
_ref$selectedItems = _ref.selectedItems,
|
|
1197
1218
|
selectedItems = _ref$selectedItems === void 0 ? [] : _ref$selectedItems,
|
|
1198
|
-
_ref$selectOnBlur = _ref.selectOnBlur,
|
|
1199
|
-
selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
|
|
1200
1219
|
_ref$selectOnTab = _ref.selectOnTab,
|
|
1201
1220
|
selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
|
|
1202
1221
|
style = _ref.style,
|
|
@@ -1205,10 +1224,12 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1205
1224
|
ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1206
1225
|
_ref$ariaLabelChosenP = _ref.ariaLabelChosenPlural,
|
|
1207
1226
|
ariaLabelChosenPlural = _ref$ariaLabelChosenP === void 0 ? 'valgte' : _ref$ariaLabelChosenP,
|
|
1208
|
-
|
|
1227
|
+
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
1228
|
+
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
1209
1229
|
_ref$ariaLabelJumpToI = _ref.ariaLabelJumpToInput,
|
|
1210
1230
|
ariaLabelJumpToInput = _ref$ariaLabelJumpToI === void 0 ? selectedItems.length + " valgte elementer, trykk for \xE5 hoppe til tekstfeltet" : _ref$ariaLabelJumpToI,
|
|
1211
|
-
|
|
1231
|
+
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
1232
|
+
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
1212
1233
|
_ref$ariaLabelRemoveS = _ref.ariaLabelRemoveSelected,
|
|
1213
1234
|
ariaLabelRemoveSelected = _ref$ariaLabelRemoveS === void 0 ? 'trykk for å fjerne valg' : _ref$ariaLabelRemoveS,
|
|
1214
1235
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
@@ -1276,39 +1297,29 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1276
1297
|
itemToString: itemToString,
|
|
1277
1298
|
itemToKey: itemToKey,
|
|
1278
1299
|
onStateChange: function onStateChange(_ref4) {
|
|
1279
|
-
var newSelectedItems = _ref4.selectedItems
|
|
1280
|
-
|
|
1281
|
-
switch (type) {
|
|
1282
|
-
case useMultipleSelection.stateChangeTypes.SelectedItemKeyDownBackspace:
|
|
1283
|
-
case useMultipleSelection.stateChangeTypes.SelectedItemKeyDownDelete:
|
|
1284
|
-
case useMultipleSelection.stateChangeTypes.DropdownKeyDownBackspace:
|
|
1285
|
-
case useMultipleSelection.stateChangeTypes.FunctionRemoveSelectedItem:
|
|
1286
|
-
{
|
|
1287
|
-
if (newSelectedItems !== undefined) onChange(newSelectedItems);
|
|
1288
|
-
break;
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1300
|
+
var newSelectedItems = _ref4.selectedItems;
|
|
1301
|
+
if (newSelectedItems !== undefined) onChange(newSelectedItems);
|
|
1291
1302
|
}
|
|
1292
1303
|
}),
|
|
1293
1304
|
getSelectedItemProps = _useMultipleSelection.getSelectedItemProps,
|
|
1294
1305
|
getDropdownProps = _useMultipleSelection.getDropdownProps;
|
|
1295
|
-
var stateReducer = React.useCallback(function (
|
|
1306
|
+
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
1296
1307
|
var changes = _ref5.changes,
|
|
1297
1308
|
type = _ref5.type;
|
|
1298
1309
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
1299
1310
|
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
1300
1311
|
}
|
|
1301
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
|
+
});
|
|
1302
1318
|
// keep menu open and edit input value on item selection
|
|
1303
1319
|
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1304
1320
|
case useCombobox.stateChangeTypes.ItemClick:
|
|
1305
1321
|
{
|
|
1306
1322
|
var _inputRef$current$val, _inputRef$current;
|
|
1307
|
-
if (clearInputOnSelect) {
|
|
1308
|
-
updateListItems({
|
|
1309
|
-
inputValue: EMPTY_INPUT
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
1323
|
return _extends({}, changes, {
|
|
1313
1324
|
isOpen: true,
|
|
1314
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
|
|
@@ -1329,38 +1340,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1329
1340
|
var leadingWhitespaceTest = /^\s+/g;
|
|
1330
1341
|
var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
|
|
1331
1342
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
|
|
1332
|
-
|
|
1343
|
+
var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
|
|
1333
1344
|
if (isSpacePressedOnEmptyInput) {
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
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]
|
|
1339
1353
|
});
|
|
1340
1354
|
}
|
|
1341
1355
|
}
|
|
1342
|
-
} else {
|
|
1343
|
-
updateListItems({
|
|
1344
|
-
inputValue: changes.inputValue
|
|
1345
|
-
});
|
|
1346
|
-
// set highlighted item to first item after search
|
|
1347
|
-
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1348
|
-
return _extends({}, changes, {
|
|
1349
|
-
highlightedIndex: hideSelectAll ? 0 : 1
|
|
1350
|
-
});
|
|
1351
1356
|
}
|
|
1352
1357
|
return changes;
|
|
1353
1358
|
}
|
|
1354
|
-
// reset input value when leaving input field
|
|
1355
|
-
case useCombobox.stateChangeTypes.InputBlur:
|
|
1356
|
-
{
|
|
1357
|
-
updateListItems({
|
|
1358
|
-
inputValue: EMPTY_INPUT
|
|
1359
|
-
});
|
|
1360
|
-
return _extends({}, changes, {
|
|
1361
|
-
inputValue: EMPTY_INPUT
|
|
1362
|
-
});
|
|
1363
|
-
}
|
|
1364
1359
|
default:
|
|
1365
1360
|
return changes;
|
|
1366
1361
|
}
|
|
@@ -1372,24 +1367,22 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1372
1367
|
itemToString: itemToString,
|
|
1373
1368
|
selectedItem: null,
|
|
1374
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
|
+
},
|
|
1375
1378
|
onStateChange: function onStateChange(_ref6) {
|
|
1376
|
-
var
|
|
1377
|
-
clickedItem = _ref6.selectedItem;
|
|
1379
|
+
var clickedItem = _ref6.selectedItem;
|
|
1378
1380
|
// clickedItem means item chosen either via mouse or keyboard
|
|
1379
1381
|
if (!clickedItem) return;
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
case useCombobox.stateChangeTypes.InputKeyDownEnter: // eslint-disable-line no-fallthrough
|
|
1385
|
-
case useCombobox.stateChangeTypes.ItemClick:
|
|
1386
|
-
{
|
|
1387
|
-
handleListItemClicked({
|
|
1388
|
-
clickedItem: clickedItem,
|
|
1389
|
-
onChange: onChange
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1382
|
+
handleListItemClicked({
|
|
1383
|
+
clickedItem: clickedItem,
|
|
1384
|
+
onChange: onChange
|
|
1385
|
+
});
|
|
1393
1386
|
},
|
|
1394
1387
|
// Accessibility
|
|
1395
1388
|
getA11yStatusMessage: function getA11yStatusMessage$1(options) {
|
|
@@ -1405,28 +1398,44 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1405
1398
|
getMenuProps = _useCombobox.getMenuProps,
|
|
1406
1399
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1407
1400
|
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1401
|
+
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1408
1402
|
inputValue = _useCombobox.inputValue,
|
|
1409
1403
|
isOpen = _useCombobox.isOpen,
|
|
1410
|
-
openMenu = _useCombobox.openMenu,
|
|
1411
1404
|
setInputValue = _useCombobox.setInputValue;
|
|
1405
|
+
// calculations for floating-UI popover position
|
|
1412
1406
|
var _useFloating = useFloating({
|
|
1413
|
-
placement: 'bottom-start',
|
|
1414
1407
|
open: isOpen,
|
|
1415
|
-
|
|
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
|
+
})]
|
|
1416
1426
|
}),
|
|
1417
1427
|
refs = _useFloating.refs,
|
|
1418
1428
|
floatingStyles = _useFloating.floatingStyles,
|
|
1419
|
-
elements = _useFloating.elements,
|
|
1420
1429
|
update = _useFloating.update;
|
|
1421
|
-
//
|
|
1422
|
-
//
|
|
1423
|
-
//
|
|
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
|
|
1424
1434
|
useEffect(function () {
|
|
1425
|
-
if (isOpen &&
|
|
1426
|
-
|
|
1427
|
-
return cleanup;
|
|
1435
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1436
|
+
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1428
1437
|
}
|
|
1429
|
-
}, [isOpen,
|
|
1438
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1430
1439
|
var handleOnClear = function handleOnClear() {
|
|
1431
1440
|
var _inputRef$current3;
|
|
1432
1441
|
onChange([]);
|
|
@@ -1437,20 +1446,6 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1437
1446
|
});
|
|
1438
1447
|
};
|
|
1439
1448
|
return React.createElement(BaseFormControl, _extends({
|
|
1440
|
-
append: React.createElement(FieldAppend$1, {
|
|
1441
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1442
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1443
|
-
selectedItems: selectedItems,
|
|
1444
|
-
isOpen: isOpen,
|
|
1445
|
-
clearable: clearable,
|
|
1446
|
-
labelClearSelectedItems: labelClearAllItems,
|
|
1447
|
-
focusable: false,
|
|
1448
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1449
|
-
loadingText: loadingText,
|
|
1450
|
-
disabled: readOnly || disabled,
|
|
1451
|
-
onClear: handleOnClear,
|
|
1452
|
-
getToggleButtonProps: getToggleButtonProps
|
|
1453
|
-
}),
|
|
1454
1449
|
className: classNames('eds-dropdown', 'eds-dropdown--multiselect', className, {
|
|
1455
1450
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1456
1451
|
}),
|
|
@@ -1462,27 +1457,44 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1462
1457
|
labelId: getLabelProps().id,
|
|
1463
1458
|
labelProps: getLabelProps(),
|
|
1464
1459
|
labelTooltip: labelTooltip,
|
|
1460
|
+
onBlur: function onBlur() {
|
|
1461
|
+
return setInputValue('');
|
|
1462
|
+
},
|
|
1465
1463
|
onClick: function onClick(e) {
|
|
1466
|
-
|
|
1467
|
-
|
|
1464
|
+
if (e.target === e.currentTarget) {
|
|
1465
|
+
var _getInputProps;
|
|
1466
|
+
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1467
|
+
}
|
|
1468
1468
|
},
|
|
1469
1469
|
readOnly: readOnly,
|
|
1470
1470
|
ref: refs.setReference,
|
|
1471
1471
|
style: style,
|
|
1472
|
-
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
|
+
})
|
|
1473
1491
|
}, rest), React.createElement("div", {
|
|
1474
1492
|
className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
|
|
1475
1493
|
'eds-dropdown--multiselect__selected-items-and-input--filled': hasSelectedItems
|
|
1476
|
-
})
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
}, selectedItems.length <= maxChips ? React.createElement(React.Fragment, null, selectedItems.length > 1 ? React.createElement(VisuallyHidden, {
|
|
1481
|
-
onClick: function onClick() {
|
|
1482
|
-
var _inputRef$current5;
|
|
1483
|
-
return (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.focus();
|
|
1484
|
-
}
|
|
1485
|
-
}, 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) {
|
|
1486
1498
|
return React.createElement(SelectedItemTag, {
|
|
1487
1499
|
ariaLabelChosen: ariaLabelChosenSingular,
|
|
1488
1500
|
ariaLabelRemoveSelected: ariaLabelRemoveSelected,
|
|
@@ -1492,27 +1504,23 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1492
1504
|
key: (selectedItem == null ? void 0 : selectedItem.label) + (typeof (selectedItem == null ? void 0 : selectedItem.value) === 'string' ? selectedItem.value : ''),
|
|
1493
1505
|
readOnly: readOnly,
|
|
1494
1506
|
removeSelectedItem: function removeSelectedItem() {
|
|
1495
|
-
var _inputRef$
|
|
1507
|
+
var _inputRef$current5;
|
|
1496
1508
|
handleListItemClicked({
|
|
1497
1509
|
clickedItem: selectedItem,
|
|
1498
1510
|
onChange: onChange
|
|
1499
1511
|
});
|
|
1500
|
-
inputRef == null || (_inputRef$
|
|
1512
|
+
inputRef == null || (_inputRef$current5 = inputRef.current) == null || _inputRef$current5.focus();
|
|
1501
1513
|
},
|
|
1502
1514
|
selectedItem: selectedItem
|
|
1503
1515
|
});
|
|
1504
|
-
})
|
|
1516
|
+
}) : React.createElement(SelectedItemTag, {
|
|
1505
1517
|
ariaLabelRemoveSelected: labelClearAllItems,
|
|
1506
1518
|
ariaLabelChosen: "",
|
|
1507
1519
|
disabled: disabled,
|
|
1508
1520
|
readOnly: readOnly,
|
|
1509
1521
|
removeSelectedItem: handleOnClear,
|
|
1510
1522
|
selectedItem: summarySelectedItems
|
|
1511
|
-
}), React.createElement("input", _extends({
|
|
1512
|
-
placeholder: placeholder,
|
|
1513
|
-
className: "eds-dropdown__input eds-form-control",
|
|
1514
|
-
disabled: readOnly || disabled
|
|
1515
|
-
}, getInputProps(_extends({
|
|
1523
|
+
}), React.createElement("input", _extends({}, getInputProps(_extends({
|
|
1516
1524
|
onKeyDown: function onKeyDown(e) {
|
|
1517
1525
|
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1518
1526
|
var highlitedItem = listItems[highlightedIndex];
|
|
@@ -1528,34 +1536,37 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1528
1536
|
}, getDropdownProps({
|
|
1529
1537
|
preventKeyAction: isOpen,
|
|
1530
1538
|
value: inputValue != null ? inputValue : EMPTY_INPUT,
|
|
1531
|
-
ref: inputRef
|
|
1532
|
-
})
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
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,
|
|
1540
1555
|
isOpen: isOpen,
|
|
1541
|
-
|
|
1542
|
-
style: listStyle,
|
|
1543
|
-
setListRef: refs.setFloating,
|
|
1544
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1556
|
+
itemIsSelected: selectedItems.length > 0,
|
|
1545
1557
|
loadingText: loadingText,
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
selectedItems: selectedItems
|
|
1550
|
-
}));
|
|
1551
|
-
};
|
|
1558
|
+
loading: loading != null ? loading : resolvedItemsLoading
|
|
1559
|
+
})));
|
|
1560
|
+
});
|
|
1552
1561
|
|
|
1553
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"];
|
|
1554
|
-
var Dropdown = function
|
|
1555
|
-
var
|
|
1563
|
+
var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1564
|
+
var _getLabelProps, _selectedItem$label;
|
|
1556
1565
|
var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1557
|
-
|
|
1558
|
-
|
|
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,
|
|
1559
1570
|
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
1560
1571
|
className = _ref.className,
|
|
1561
1572
|
_ref$clearable = _ref.clearable,
|
|
@@ -1571,7 +1582,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1571
1582
|
labelTooltip = _ref.labelTooltip,
|
|
1572
1583
|
listStyle = _ref.listStyle,
|
|
1573
1584
|
loading = _ref.loading,
|
|
1574
|
-
loadingText = _ref.loadingText,
|
|
1585
|
+
_ref$loadingText = _ref.loadingText,
|
|
1586
|
+
loadingText = _ref$loadingText === void 0 ? 'Laster resultater …' : _ref$loadingText,
|
|
1575
1587
|
_ref$noMatchesText = _ref.noMatchesText,
|
|
1576
1588
|
noMatchesText = _ref$noMatchesText === void 0 ? 'Ingen tilgjengelige valg …' : _ref$noMatchesText,
|
|
1577
1589
|
onChange = _ref.onChange,
|
|
@@ -1591,7 +1603,6 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1591
1603
|
var _useResolvedItems = useResolvedItems(initialItems),
|
|
1592
1604
|
normalizedItems = _useResolvedItems.items,
|
|
1593
1605
|
resolvedItemsLoading = _useResolvedItems.loading;
|
|
1594
|
-
var toggleButtonRef = useRef(null);
|
|
1595
1606
|
var isFilled = selectedItem !== null || placeholder !== undefined;
|
|
1596
1607
|
var _useSelect = useSelect({
|
|
1597
1608
|
items: normalizedItems,
|
|
@@ -1601,128 +1612,128 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1601
1612
|
var type = _ref2.type,
|
|
1602
1613
|
newSelectedItem = _ref2.selectedItem;
|
|
1603
1614
|
switch (type) {
|
|
1604
|
-
// @ts-expect-error This falltrough is wanted
|
|
1605
1615
|
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
1606
|
-
if (!selectOnBlur)
|
|
1607
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter: // eslint-disable-line no-fallthrough
|
|
1608
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
1609
|
-
case useSelect.stateChangeTypes.ItemClick:
|
|
1610
|
-
{
|
|
1611
|
-
if (newSelectedItem === undefined) return;
|
|
1612
|
-
onChange == null || onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1613
|
-
}
|
|
1616
|
+
if (!selectOnBlur) return;
|
|
1614
1617
|
}
|
|
1618
|
+
if (newSelectedItem === undefined) return;
|
|
1619
|
+
onChange == null || onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1615
1620
|
},
|
|
1616
1621
|
itemToString: itemToString
|
|
1617
1622
|
}),
|
|
1618
1623
|
isOpen = _useSelect.isOpen,
|
|
1619
|
-
openMenu = _useSelect.openMenu,
|
|
1620
1624
|
getItemProps = _useSelect.getItemProps,
|
|
1621
1625
|
getLabelProps = _useSelect.getLabelProps,
|
|
1622
1626
|
getMenuProps = _useSelect.getMenuProps,
|
|
1623
1627
|
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
1624
1628
|
highlightedIndex = _useSelect.highlightedIndex;
|
|
1629
|
+
// calculations for floating-UI popover position
|
|
1625
1630
|
var _useFloating = useFloating({
|
|
1626
|
-
placement: 'bottom-start',
|
|
1627
1631
|
open: isOpen,
|
|
1628
|
-
|
|
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
|
+
})]
|
|
1629
1650
|
}),
|
|
1630
1651
|
refs = _useFloating.refs,
|
|
1631
1652
|
floatingStyles = _useFloating.floatingStyles,
|
|
1632
|
-
elements = _useFloating.elements,
|
|
1633
1653
|
update = _useFloating.update;
|
|
1634
|
-
//
|
|
1635
|
-
//
|
|
1636
|
-
//
|
|
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
|
|
1637
1658
|
useEffect(function () {
|
|
1638
|
-
if (isOpen &&
|
|
1639
|
-
|
|
1640
|
-
return cleanup;
|
|
1659
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1660
|
+
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1641
1661
|
}
|
|
1642
|
-
}, [isOpen,
|
|
1662
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1643
1663
|
return React.createElement(BaseFormControl, _extends({
|
|
1644
|
-
append: React.createElement(FieldAppend$1, {
|
|
1645
|
-
ariaHiddenToggleButton: true,
|
|
1646
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1647
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1648
|
-
clearable: clearable,
|
|
1649
|
-
labelClearSelectedItems: labelClearSelectedItem,
|
|
1650
|
-
focusable: false,
|
|
1651
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
1652
|
-
isOpen: isOpen,
|
|
1653
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1654
|
-
loadingText: loadingText,
|
|
1655
|
-
onClear: function onClear() {
|
|
1656
|
-
var _toggleButtonRef$curr;
|
|
1657
|
-
onChange == null || onChange(null);
|
|
1658
|
-
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
1659
|
-
},
|
|
1660
|
-
disabled: readOnly || disabled,
|
|
1661
|
-
selectedItems: [selectedItem]
|
|
1662
|
-
}),
|
|
1663
1664
|
className: classNames('eds-dropdown', className, {
|
|
1664
1665
|
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1665
1666
|
}),
|
|
1666
|
-
disabled: disabled,
|
|
1667
1667
|
disableLabelAnimation: disableLabelAnimation,
|
|
1668
1668
|
feedback: feedback,
|
|
1669
1669
|
isFilled: isFilled,
|
|
1670
|
-
label: label,
|
|
1671
|
-
labelId: getLabelProps().id,
|
|
1672
1670
|
labelProps: getLabelProps(),
|
|
1673
1671
|
labelTooltip: labelTooltip,
|
|
1674
|
-
onClick: function onClick(e) {
|
|
1675
|
-
if (e.target === e.currentTarget) openMenu();
|
|
1676
|
-
},
|
|
1677
1672
|
prepend: prepend,
|
|
1678
|
-
readOnly: readOnly,
|
|
1679
|
-
ref: refs.setReference,
|
|
1680
1673
|
style: style,
|
|
1681
1674
|
variant: variant
|
|
1682
|
-
}, rest), React.createElement("div", _extends({
|
|
1683
|
-
className: "eds-dropdown__selected-item"
|
|
1684
1675
|
}, getToggleButtonProps({
|
|
1685
|
-
|
|
1686
|
-
onKeyDown: function onKeyDown(e) {
|
|
1687
|
-
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1688
|
-
// we don't want to clear selection with tab
|
|
1689
|
-
var highlitedItem = normalizedItems[highlightedIndex];
|
|
1690
|
-
if (highlitedItem) {
|
|
1691
|
-
onChange == null || onChange(highlitedItem);
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
},
|
|
1695
|
-
ref: toggleButtonRef,
|
|
1676
|
+
ref: mergeRefs(ref, refs.setReference),
|
|
1696
1677
|
'aria-disabled': disabled,
|
|
1697
1678
|
'aria-label': disabled ? 'Disabled dropdown' : '',
|
|
1698
1679
|
disabled: disabled,
|
|
1699
|
-
|
|
1700
|
-
|
|
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", {
|
|
1701
1711
|
className: classNames('eds-dropdown__selected-item__placeholder', {
|
|
1702
1712
|
'eds-dropdown__selected-item__placeholder--readonly': readOnly
|
|
1703
1713
|
})
|
|
1704
|
-
}, placeholder))
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
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,
|
|
1711
1724
|
isOpen: isOpen,
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
loadingText: loadingText,
|
|
1718
|
-
selectedItems: selectedItem !== null ? [selectedItem] : []
|
|
1725
|
+
itemIsSelected: selectedItem !== null,
|
|
1726
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1727
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1728
|
+
loading: false,
|
|
1729
|
+
loadingText: undefined
|
|
1719
1730
|
}));
|
|
1720
|
-
};
|
|
1731
|
+
});
|
|
1721
1732
|
|
|
1722
1733
|
var _excluded = ["className", "disabled", "disableLabelAnimation", "feedback", "items", "label", "loadingText", "onChange", "prepend", "readOnly", "selectedItem", "style", "value", "variant"];
|
|
1723
1734
|
/** @deprecated use variant="negative" instead */
|
|
1724
1735
|
var error = 'error';
|
|
1725
|
-
var NativeDropdown = function
|
|
1736
|
+
var NativeDropdown = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
1726
1737
|
var _ref2;
|
|
1727
1738
|
var className = _ref.className,
|
|
1728
1739
|
_ref$disabled = _ref.disabled,
|
|
@@ -1778,14 +1789,15 @@ var NativeDropdown = function NativeDropdown(_ref) {
|
|
|
1778
1789
|
target: event.target
|
|
1779
1790
|
});
|
|
1780
1791
|
},
|
|
1781
|
-
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
|
|
1782
1794
|
}, rest), normalizedItems.map(function (item) {
|
|
1783
1795
|
return React.createElement("option", {
|
|
1784
1796
|
key: item.value,
|
|
1785
1797
|
value: item.value
|
|
1786
1798
|
}, item.label);
|
|
1787
1799
|
})));
|
|
1788
|
-
};
|
|
1800
|
+
});
|
|
1789
1801
|
var FieldAppend = function FieldAppend(_ref3) {
|
|
1790
1802
|
var loading = _ref3.loading,
|
|
1791
1803
|
loadingText = _ref3.loadingText,
|