@entur/dropdown 5.0.18 → 5.0.20

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.
@@ -1410,13 +1410,6 @@ var FieldAppend$1 = function FieldAppend(_ref3) {
1410
1410
  loadingText = _ref3$loadingText === void 0 ? 'Laster resultater …' : _ref3$loadingText,
1411
1411
  onClear = _ref3.onClear,
1412
1412
  selectedItems = _ref3.selectedItems;
1413
- if (loading) {
1414
- return React.createElement("div", {
1415
- className: 'eds-dropdown__appendix__toggle-button--loading-dots'
1416
- }, React.createElement(loader.LoadingDots, {
1417
- "aria-label": loadingText
1418
- }));
1419
- }
1420
1413
  if (disabled) {
1421
1414
  return null;
1422
1415
  }
@@ -1428,14 +1421,18 @@ var FieldAppend$1 = function FieldAppend(_ref3) {
1428
1421
  labelClearSelectedItems: labelClearSelectedItems
1429
1422
  }), React.createElement("div", {
1430
1423
  className: "eds-dropdown__appendix__divider"
1431
- })), React.createElement(ToggleButton, {
1424
+ })), !loading ? React.createElement(ToggleButton, {
1432
1425
  "aria-hidden": ariaHiddenToggleButton,
1433
1426
  ariaLabelCloseList: ariaLabelCloseList,
1434
1427
  ariaLabelOpenList: ariaLabelOpenList,
1435
1428
  getToggleButtonProps: getToggleButtonProps,
1436
1429
  isOpen: isOpen,
1437
1430
  focusable: focusable
1438
- }));
1431
+ }) : React.createElement("div", {
1432
+ className: 'eds-dropdown__appendix__toggle-button--loading-dots'
1433
+ }, React.createElement(loader.LoadingDots, {
1434
+ "aria-label": loadingText
1435
+ })));
1439
1436
  };
1440
1437
  var ClearableButton = function ClearableButton(_ref4) {
1441
1438
  var onClear = _ref4.onClear,
@@ -1645,7 +1642,7 @@ var isVoiceOverClick = function isVoiceOverClick(clickEvent) {
1645
1642
 
1646
1643
  var _excluded$3 = ["ariaLabelChosenSingular", "ariaLabelCloseList", "ariaLabelOpenList", "ariaLabelSelectedItem", "className", "clearable", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "items", "itemFilter", "label", "labelClearSelectedItem", "listStyle", "loadingText", "noMatchesText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
1647
1644
  var SearchableDropdown = function SearchableDropdown(_ref) {
1648
- var _selectedItem$label;
1645
+ var _document, _selectedItem$label;
1649
1646
  var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
1650
1647
  ariaLabelCloseList = _ref.ariaLabelCloseList,
1651
1648
  ariaLabelOpenList = _ref.ariaLabelOpenList,
@@ -1718,6 +1715,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1718
1715
  inputValue: inputValue
1719
1716
  });
1720
1717
  }, [normalizedItems]); // eslint-disable-line react-hooks/exhaustive-deps
1718
+ var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
1721
1719
  var stateReducer = React.useCallback(function (_, _ref4) {
1722
1720
  var type = _ref4.type,
1723
1721
  changes = _ref4.changes;
@@ -1729,7 +1727,6 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1729
1727
  case Downshift.useCombobox.stateChangeTypes.ItemClick:
1730
1728
  case Downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
1731
1729
  case Downshift.useCombobox.stateChangeTypes.InputBlur:
1732
- case Downshift.useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
1733
1730
  {
1734
1731
  updateListItems({
1735
1732
  inputValue: EMPTY_INPUT
@@ -1738,6 +1735,14 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1738
1735
  inputValue: EMPTY_INPUT
1739
1736
  });
1740
1737
  }
1738
+ case Downshift.useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
1739
+ if (!inputHasFocus) setShowSelectedItem(true);
1740
+ updateListItems({
1741
+ inputValue: EMPTY_INPUT
1742
+ });
1743
+ return _extends({}, changes, {
1744
+ inputValue: EMPTY_INPUT
1745
+ });
1741
1746
  // remove leading whitespace, select element with spacebar on empty input, and filter list based on input
1742
1747
  case Downshift.useCombobox.stateChangeTypes.InputChange:
1743
1748
  {
@@ -1808,11 +1813,24 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1808
1813
  updateListItems({
1809
1814
  inputValue: inputValue
1810
1815
  });
1816
+ setShowSelectedItem(false);
1811
1817
  };
1812
1818
  return React.createElement("div", {
1813
1819
  className: classNames('eds-dropdown__wrapper', className),
1814
1820
  style: style
1815
1821
  }, React.createElement(form.BaseFormControl, _extends({
1822
+ className: "eds-dropdown",
1823
+ disabled: disabled,
1824
+ disableLabelAnimation: disableLabelAnimation,
1825
+ feedback: feedback,
1826
+ isFilled: selectedItem !== null || inputValue !== EMPTY_INPUT,
1827
+ label: label,
1828
+ labelId: getLabelProps().id,
1829
+ labelProps: getLabelProps(),
1830
+ prepend: prepend,
1831
+ readOnly: readOnly,
1832
+ variant: variant
1833
+ }, rest, {
1816
1834
  append: React.createElement(FieldAppend$1, {
1817
1835
  ariaLabelCloseList: ariaLabelCloseList,
1818
1836
  ariaLabelOpenList: ariaLabelOpenList,
@@ -1826,19 +1844,8 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1826
1844
  loadingText: loadingText,
1827
1845
  onClear: handleOnClear,
1828
1846
  selectedItems: [selectedItem]
1829
- }),
1830
- className: "eds-dropdown",
1831
- disabled: disabled,
1832
- disableLabelAnimation: disableLabelAnimation,
1833
- feedback: feedback,
1834
- isFilled: selectedItem !== null || inputValue !== EMPTY_INPUT,
1835
- label: label,
1836
- labelId: getLabelProps().id,
1837
- labelProps: getLabelProps(),
1838
- prepend: prepend,
1839
- readOnly: readOnly,
1840
- variant: variant
1841
- }, rest), React.createElement("span", {
1847
+ })
1848
+ }), React.createElement("span", {
1842
1849
  className: classNames('eds-dropdown--searchable__selected-item', {
1843
1850
  'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
1844
1851
  }),
@@ -1847,7 +1854,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1847
1854
  var _inputRef$current2;
1848
1855
  return (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.focus();
1849
1856
  }
1850
- }, selectedItem == null ? void 0 : selectedItem.label), React.createElement("input", _extends({
1857
+ }, showSelectedItem ? selectedItem == null ? void 0 : selectedItem.label : ''), React.createElement("input", _extends({
1851
1858
  className: classNames('eds-dropdown__input eds-form-control', {
1852
1859
  'eds-dropdown__input--hidden': showSelectedItem
1853
1860
  }),