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