@entur/dropdown 7.1.1-beta.0 → 7.1.2

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.
@@ -569,6 +569,7 @@ var DropdownFieldAppendix = /*#__PURE__*/forwardRef(function (_ref3, ref) {
569
569
  ref: ref,
570
570
  "aria-label": getToggleAriaLabel()
571
571
  }, rest, {
572
+ type: "button",
572
573
  tabIndex: focusable ? 0 : -1
573
574
  }), !loading ? React.createElement(DownArrowIcon, {
574
575
  "aria-hidden": "true"
@@ -981,22 +982,20 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
981
982
  case useCombobox.stateChangeTypes.InputChange:
982
983
  {
983
984
  var _changes$inputValue;
984
- setLastHighlightedIndex(0);
985
985
  var leadingWhitespaceTest = /^\s+/g;
986
986
  var isSpacePressedOnEmptyInput = changes.inputValue === ' ';
987
+ if (!isSpacePressedOnEmptyInput) setLastHighlightedIndex(0);
987
988
  if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(leadingWhitespaceTest)) {
988
989
  var sanitizedInputValue = changes.inputValue.replace(leadingWhitespaceTest, EMPTY_INPUT);
989
990
  if (isSpacePressedOnEmptyInput) {
990
991
  if (!state.isOpen) return _extends({}, changes, {
991
992
  inputValue: sanitizedInputValue,
992
- isOpen: true,
993
- highlightedIndex: 0
993
+ isOpen: true
994
994
  });
995
995
  if (changes.highlightedIndex !== undefined) {
996
996
  return _extends({}, changes, {
997
997
  inputValue: sanitizedInputValue,
998
- selectedItem: listItems[changes.highlightedIndex],
999
- highlightedIndex: 0
998
+ selectedItem: listItems[changes.highlightedIndex]
1000
999
  });
1001
1000
  }
1002
1001
  }
@@ -1032,6 +1031,7 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1032
1031
  }));
1033
1032
  }
1034
1033
  }),
1034
+ closeMenu = _useCombobox.closeMenu,
1035
1035
  isOpen = _useCombobox.isOpen,
1036
1036
  getToggleButtonProps = _useCombobox.getToggleButtonProps,
1037
1037
  getLabelProps = _useCombobox.getLabelProps,
@@ -1143,15 +1143,23 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1143
1143
  'eds-dropdown__input--hidden': showSelectedItem
1144
1144
  })
1145
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
+ },
1146
1157
  onBlur: function onBlur() {
1147
1158
  if (selectedItem !== null) setShowSelectedItem(true);
1148
1159
  },
1149
1160
  onFocus: function onFocus() {
1150
1161
  setShowSelectedItem(false);
1151
1162
  },
1152
- onKeyDown: function onKeyDown(e) {
1153
- if (isOpen && (selectOnTab || selectOnBlur) && e.key === 'Tab' && highlightedIndex !== undefined) onChange(listItems[highlightedIndex]);
1154
- },
1155
1163
  disabled: disabled,
1156
1164
  readOnly: readOnly,
1157
1165
  placeholder: (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : placeholder,
@@ -1176,7 +1184,7 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1176
1184
 
1177
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"];
1178
1186
  var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1179
- var _inputRef$current4;
1187
+ var _inputRef$current5;
1180
1188
  var className = _ref.className,
1181
1189
  _ref$clearable = _ref.clearable,
1182
1190
  clearable = _ref$clearable === void 0 ? true : _ref$clearable,
@@ -1304,6 +1312,7 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1304
1312
  getSelectedItemProps = _useMultipleSelection.getSelectedItemProps,
1305
1313
  getDropdownProps = _useMultipleSelection.getDropdownProps;
1306
1314
  var stateReducer = React.useCallback(function (state, _ref5) {
1315
+ var _inputRef$current;
1307
1316
  var changes = _ref5.changes,
1308
1317
  type = _ref5.type;
1309
1318
  if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
@@ -1312,6 +1321,7 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1312
1321
  switch (type) {
1313
1322
  // reset input value when leaving input field
1314
1323
  case useCombobox.stateChangeTypes.InputBlur:
1324
+ if (state.isOpen) (_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
1315
1325
  return _extends({}, changes, {
1316
1326
  inputValue: EMPTY_INPUT
1317
1327
  });
@@ -1319,18 +1329,18 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1319
1329
  case useCombobox.stateChangeTypes.InputKeyDownEnter:
1320
1330
  case useCombobox.stateChangeTypes.ItemClick:
1321
1331
  {
1322
- var _inputRef$current$val, _inputRef$current;
1332
+ var _inputRef$current$val, _inputRef$current2;
1323
1333
  return _extends({}, changes, {
1324
1334
  isOpen: true,
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
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
1326
1336
  });
1327
1337
  }
1328
1338
  // edit input value when selected items is updated outside component
1329
1339
  case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
1330
1340
  {
1331
- var _inputRef$current$val2, _inputRef$current2;
1341
+ var _inputRef$current$val2, _inputRef$current3;
1332
1342
  return _extends({}, changes, {
1333
- inputValue: (_inputRef$current$val2 = inputRef == null || (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value) != null ? _inputRef$current$val2 : EMPTY_INPUT
1343
+ inputValue: (_inputRef$current$val2 = inputRef == null || (_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.value) != null ? _inputRef$current$val2 : EMPTY_INPUT
1334
1344
  });
1335
1345
  }
1336
1346
  // remove leading whitespace, select item with spacebar if input is empty and filter list items
@@ -1437,10 +1447,10 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1437
1447
  }
1438
1448
  }, [isOpen, refs.reference, refs.floating, update]);
1439
1449
  var handleOnClear = function handleOnClear() {
1440
- var _inputRef$current3;
1450
+ var _inputRef$current4;
1441
1451
  onChange([]);
1442
1452
  setInputValue(EMPTY_INPUT);
1443
- (_inputRef$current3 = inputRef.current) == null || _inputRef$current3.focus();
1453
+ (_inputRef$current4 = inputRef.current) == null || _inputRef$current4.focus();
1444
1454
  updateListItems({
1445
1455
  inputValue: inputValue
1446
1456
  });
@@ -1493,7 +1503,7 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1493
1503
  'eds-dropdown--multiselect__selected-items-and-input--filled': hasSelectedItems
1494
1504
  })
1495
1505
  }, selectedItems.length > 1 ? React.createElement(VisuallyHidden, {
1496
- onClick: (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus
1506
+ onClick: (_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.focus
1497
1507
  }, ariaLabelJumpToInput) : null, selectedItems.length <= maxChips ? selectedItems.map(function (selectedItem, index) {
1498
1508
  return React.createElement(SelectedItemTag, {
1499
1509
  ariaLabelChosen: ariaLabelChosenSingular,
@@ -1504,12 +1514,12 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1504
1514
  key: (selectedItem == null ? void 0 : selectedItem.label) + (typeof (selectedItem == null ? void 0 : selectedItem.value) === 'string' ? selectedItem.value : ''),
1505
1515
  readOnly: readOnly,
1506
1516
  removeSelectedItem: function removeSelectedItem() {
1507
- var _inputRef$current5;
1517
+ var _inputRef$current6;
1508
1518
  handleListItemClicked({
1509
1519
  clickedItem: selectedItem,
1510
1520
  onChange: onChange
1511
1521
  });
1512
- inputRef == null || (_inputRef$current5 = inputRef.current) == null || _inputRef$current5.focus();
1522
+ inputRef == null || (_inputRef$current6 = inputRef.current) == null || _inputRef$current6.focus();
1513
1523
  },
1514
1524
  selectedItem: selectedItem
1515
1525
  });
@@ -1620,6 +1630,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1620
1630
  },
1621
1631
  itemToString: itemToString
1622
1632
  }),
1633
+ closeMenu = _useSelect.closeMenu,
1623
1634
  isOpen = _useSelect.isOpen,
1624
1635
  getItemProps = _useSelect.getItemProps,
1625
1636
  getLabelProps = _useSelect.getLabelProps,
@@ -1683,7 +1694,15 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1683
1694
  children: undefined,
1684
1695
  tabIndex: disabled || readOnly ? -1 : 0,
1685
1696
  onKeyDown: function onKeyDown(e) {
1686
- if (isOpen && (selectOnTab || selectOnBlur) && e.key === 'Tab' && highlightedIndex !== undefined) onChange == null || onChange(normalizedItems[highlightedIndex]);
1697
+ if (isOpen && e.key === 'Tab') {
1698
+ var highlitedItem = normalizedItems[highlightedIndex];
1699
+ // we don't want to clear selection with tab
1700
+ if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
1701
+ onChange == null || onChange(highlitedItem);
1702
+ }
1703
+ closeMenu();
1704
+ e.preventDefault();
1705
+ }
1687
1706
  }
1688
1707
  }), {
1689
1708
  after: React.createElement(DropdownList, {