@entur/dropdown 5.0.9-beta.0 → 5.0.11

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.
@@ -19,6 +19,12 @@ export type DropdownProps = {
19
19
  */
20
20
  clearable?: boolean;
21
21
  /** Lar brukeren velge ved å "tab-e" seg ut av komponenten */
22
+ selectOnTab?: boolean;
23
+ /**
24
+ * @deprecated
25
+ * Bruk selectOnTab i stedet
26
+ *
27
+ * Lar brukeren velge ved å "tab-e" seg ut av komponenten */
22
28
  selectOnBlur?: boolean;
23
29
  /** Deaktiver dropdown-en */
24
30
  disabled?: boolean;
@@ -59,4 +65,4 @@ export type DropdownProps = {
59
65
  */
60
66
  ariaLabelOpenList?: string;
61
67
  };
62
- export declare const Dropdown: ({ ariaLabelCloseList, ariaLabelOpenList, className, clearable, disabled, disableLabelAnimation, feedback, items: initialItems, label, labelClearSelectedItem, listStyle, loadingText, onChange, placeholder, prepend, readOnly, selectedItem, selectOnBlur, style, variant, ...rest }: DropdownProps) => React.JSX.Element;
68
+ export declare const Dropdown: ({ ariaLabelCloseList, ariaLabelOpenList, className, clearable, disabled, disableLabelAnimation, feedback, items: initialItems, label, labelClearSelectedItem, listStyle, loadingText, onChange, placeholder, prepend, readOnly, selectedItem, selectOnBlur, selectOnTab, style, variant, ...rest }: DropdownProps) => React.JSX.Element;
@@ -59,6 +59,12 @@ export type MultiSelectProps = {
59
59
  */
60
60
  clearInputOnSelect?: boolean;
61
61
  /** Lar brukeren velge ved å "tab-e" seg ut av komponenten */
62
+ selectOnTab?: boolean;
63
+ /**
64
+ * @deprecated
65
+ * Bruk selectOnTab i stedet
66
+ *
67
+ * Lar brukeren velge ved å "tab-e" seg ut av komponenten */
62
68
  selectOnBlur?: boolean;
63
69
  style?: React.CSSProperties;
64
70
  /** Styling som sendes ned til MultiSelect-lista */
@@ -108,4 +114,4 @@ export type MultiSelectProps = {
108
114
  */
109
115
  ariaLabelSelectedItem?: string;
110
116
  };
111
- export declare const MultiSelect: ({ className, clearable, clearInputOnSelect, debounceTimeout, disabled, feedback, hideSelectAll, items: initialItems, itemFilter, label, labelAllItemsSelected, labelClearAllItems, labelSelectAll, listStyle, loadingText, maxChips, noMatchesText, onChange, placeholder, readOnly, selectedItems, selectOnBlur, style, variant, ariaLabelChosenSingular, ariaLabelChosenPlural, ariaLabelCloseList, ariaLabelJumpToInput, ariaLabelOpenList, ariaLabelRemoveSelected, ariaLabelSelectedItem, ...rest }: MultiSelectProps) => React.JSX.Element;
117
+ export declare const MultiSelect: ({ className, clearable, clearInputOnSelect, debounceTimeout, disabled, feedback, hideSelectAll, items: initialItems, itemFilter, label, labelAllItemsSelected, labelClearAllItems, labelSelectAll, listStyle, loadingText, maxChips, noMatchesText, onChange, placeholder, readOnly, selectedItems, selectOnBlur, selectOnTab, style, variant, ariaLabelChosenSingular, ariaLabelChosenPlural, ariaLabelCloseList, ariaLabelJumpToInput, ariaLabelOpenList, ariaLabelRemoveSelected, ariaLabelSelectedItem, ...rest }: MultiSelectProps) => React.JSX.Element;
@@ -33,6 +33,12 @@ export type SearchableDropdownProps = {
33
33
  /** Deaktiver dropdown-en */
34
34
  disabled?: boolean;
35
35
  /** Lar brukeren velge ved å "tab-e" seg ut av komponenten */
36
+ selectOnTab?: boolean;
37
+ /**
38
+ * @deprecated
39
+ * Bruk selectOnTab i stedet
40
+ *
41
+ * Lar brukeren velge ved å "tab-e" seg ut av komponenten */
36
42
  selectOnBlur?: boolean;
37
43
  /** Gjør dropdown-en til å kun kunne leses
38
44
  * @default false
@@ -67,4 +73,4 @@ export type SearchableDropdownProps = {
67
73
  */
68
74
  ariaLabelOpenList?: string;
69
75
  };
70
- export declare const SearchableDropdown: ({ ariaLabelCloseList, ariaLabelOpenList, className, clearable, debounceTimeout, disabled, disableLabelAnimation, feedback, items: initialItems, itemFilter, label, labelClearSelectedItem, listStyle, loadingText, onChange, placeholder, prepend, readOnly, selectedItem: value, selectOnBlur, style, variant, ...rest }: SearchableDropdownProps) => React.JSX.Element;
76
+ export declare const SearchableDropdown: ({ ariaLabelCloseList, ariaLabelOpenList, className, clearable, debounceTimeout, disabled, disableLabelAnimation, feedback, items: initialItems, itemFilter, label, labelClearSelectedItem, listStyle, loadingText, onChange, placeholder, prepend, readOnly, selectedItem: value, selectOnBlur, selectOnTab, style, variant, ...rest }: SearchableDropdownProps) => React.JSX.Element;
@@ -1317,7 +1317,7 @@ var DropdownList = function DropdownList(_ref) {
1317
1317
  className: "eds-dropdown__list__item__text"
1318
1318
  }, item.label, React.createElement(a11y.VisuallyHidden, null, isItemSelected(item) ? ariaLabelSelectedItem : '')), item.icons && React.createElement("span", null, item.icons.map(function (Icon) {
1319
1319
  return React.createElement(Icon, {
1320
- key: Icon.displayName,
1320
+ key: item.label + item.value + Icon.displayName,
1321
1321
  inline: true,
1322
1322
  className: "eds-dropdown__list__item__icon"
1323
1323
  });
@@ -1642,7 +1642,7 @@ var isVoiceOverClick = function isVoiceOverClick(clickEvent) {
1642
1642
  };
1643
1643
  /* end a11y utils */
1644
1644
 
1645
- var _excluded$3 = ["ariaLabelCloseList", "ariaLabelOpenList", "className", "clearable", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "items", "itemFilter", "label", "labelClearSelectedItem", "listStyle", "loadingText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "style", "variant"];
1645
+ var _excluded$3 = ["ariaLabelCloseList", "ariaLabelOpenList", "className", "clearable", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "items", "itemFilter", "label", "labelClearSelectedItem", "listStyle", "loadingText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
1646
1646
  var SearchableDropdown = function SearchableDropdown(_ref) {
1647
1647
  var _selectedItem$label;
1648
1648
  var ariaLabelCloseList = _ref.ariaLabelCloseList,
@@ -1664,7 +1664,10 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1664
1664
  labelClearSelectedItem = _ref$labelClearSelect === void 0 ? 'fjern valgt' : _ref$labelClearSelect,
1665
1665
  listStyle = _ref.listStyle,
1666
1666
  loadingText = _ref.loadingText,
1667
- onChange = _ref.onChange,
1667
+ _ref$onChange = _ref.onChange,
1668
+ onChange = _ref$onChange === void 0 ? function () {
1669
+ return undefined;
1670
+ } : _ref$onChange,
1668
1671
  placeholder = _ref.placeholder,
1669
1672
  prepend = _ref.prepend,
1670
1673
  _ref$readOnly = _ref.readOnly,
@@ -1672,6 +1675,8 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1672
1675
  value = _ref.selectedItem,
1673
1676
  _ref$selectOnBlur = _ref.selectOnBlur,
1674
1677
  selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
1678
+ _ref$selectOnTab = _ref.selectOnTab,
1679
+ selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
1675
1680
  style = _ref.style,
1676
1681
  _ref$variant = _ref.variant,
1677
1682
  variant = _ref$variant === void 0 ? 'info' : _ref$variant,
@@ -1740,7 +1745,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1740
1745
  if (isSpacePressedOnEmptyInput) {
1741
1746
  openMenu();
1742
1747
  if (isOpen && changes.highlightedIndex !== undefined) {
1743
- onChange == null ? void 0 : onChange(listItems[changes.highlightedIndex]);
1748
+ onChange(listItems[changes.highlightedIndex]);
1744
1749
  }
1745
1750
  }
1746
1751
  } else {
@@ -1769,7 +1774,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1769
1774
  if (!selectOnBlur) break;
1770
1775
  case Downshift.useCombobox.stateChangeTypes.InputKeyDownEnter: // eslint-disable-line no-fallthrough
1771
1776
  case Downshift.useCombobox.stateChangeTypes.ItemClick:
1772
- onChange == null ? void 0 : onChange(clickedItem != null ? clickedItem : null);
1777
+ onChange(clickedItem != null ? clickedItem : null);
1773
1778
  }
1774
1779
  },
1775
1780
  // Accessibility
@@ -1793,7 +1798,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1793
1798
  setInputValue = _useCombobox.setInputValue;
1794
1799
  var handleOnClear = function handleOnClear() {
1795
1800
  var _inputRef$current;
1796
- onChange == null ? void 0 : onChange(null);
1801
+ onChange(null);
1797
1802
  setInputValue(EMPTY_INPUT);
1798
1803
  (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
1799
1804
  updateListItems({
@@ -1850,6 +1855,9 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1850
1855
  onFocus: function onFocus() {
1851
1856
  setHideSelectedItem(true);
1852
1857
  },
1858
+ onKeyDown: function onKeyDown(e) {
1859
+ if (selectOnTab && e.key === 'Tab') onChange(listItems[highlightedIndex]);
1860
+ },
1853
1861
  ref: inputRef
1854
1862
  })))), React.createElement(DropdownList, {
1855
1863
  isOpen: isOpen,
@@ -1864,7 +1872,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
1864
1872
  }));
1865
1873
  };
1866
1874
 
1867
- var _excluded$2 = ["className", "clearable", "clearInputOnSelect", "debounceTimeout", "disabled", "feedback", "hideSelectAll", "items", "itemFilter", "label", "labelAllItemsSelected", "labelClearAllItems", "labelSelectAll", "listStyle", "loadingText", "maxChips", "noMatchesText", "onChange", "placeholder", "readOnly", "selectedItems", "selectOnBlur", "style", "variant", "ariaLabelChosenSingular", "ariaLabelChosenPlural", "ariaLabelCloseList", "ariaLabelJumpToInput", "ariaLabelOpenList", "ariaLabelRemoveSelected", "ariaLabelSelectedItem"];
1875
+ var _excluded$2 = ["className", "clearable", "clearInputOnSelect", "debounceTimeout", "disabled", "feedback", "hideSelectAll", "items", "itemFilter", "label", "labelAllItemsSelected", "labelClearAllItems", "labelSelectAll", "listStyle", "loadingText", "maxChips", "noMatchesText", "onChange", "placeholder", "readOnly", "selectedItems", "selectOnBlur", "selectOnTab", "style", "variant", "ariaLabelChosenSingular", "ariaLabelChosenPlural", "ariaLabelCloseList", "ariaLabelJumpToInput", "ariaLabelOpenList", "ariaLabelRemoveSelected", "ariaLabelSelectedItem"];
1868
1876
  var MultiSelect = function MultiSelect(_ref) {
1869
1877
  var className = _ref.className,
1870
1878
  _ref$clearable = _ref.clearable,
@@ -1902,6 +1910,8 @@ var MultiSelect = function MultiSelect(_ref) {
1902
1910
  selectedItems = _ref$selectedItems === void 0 ? [] : _ref$selectedItems,
1903
1911
  _ref$selectOnBlur = _ref.selectOnBlur,
1904
1912
  selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
1913
+ _ref$selectOnTab = _ref.selectOnTab,
1914
+ selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
1905
1915
  style = _ref.style,
1906
1916
  _ref$variant = _ref.variant,
1907
1917
  variant = _ref$variant === void 0 ? 'info' : _ref$variant,
@@ -2203,14 +2213,22 @@ var MultiSelect = function MultiSelect(_ref) {
2203
2213
  placeholder: placeholder,
2204
2214
  className: "eds-dropdown__input eds-form-control",
2205
2215
  disabled: readOnly || disabled
2206
- }, getInputProps(getDropdownProps({
2216
+ }, getInputProps(_extends({
2217
+ onKeyDown: function onKeyDown(e) {
2218
+ if (selectOnTab && e.key === 'Tab') handleListItemClicked({
2219
+ clickedItem: listItems[highlightedIndex],
2220
+ onChange: onChange,
2221
+ setLastRemovedItem: setLastRemovedItem
2222
+ });
2223
+ }
2224
+ }, getDropdownProps({
2207
2225
  onClick: function onClick(e) {
2208
2226
  if (!isOpen && isVoiceOverClick(e)) openMenu();
2209
2227
  },
2210
2228
  preventKeyAction: isOpen,
2211
2229
  ref: inputRef,
2212
2230
  value: inputValue != null ? inputValue : EMPTY_INPUT
2213
- })))))), React.createElement(DropdownList, {
2231
+ }))))))), React.createElement(DropdownList, {
2214
2232
  ariaLabelChosenSingular: ariaLabelChosenSingular,
2215
2233
  ariaLabelSelectedItem: ariaLabelSelectedItem,
2216
2234
  getItemProps: getItemProps,
@@ -2228,7 +2246,7 @@ var MultiSelect = function MultiSelect(_ref) {
2228
2246
  }));
2229
2247
  };
2230
2248
 
2231
- var _excluded$1 = ["ariaLabelCloseList", "ariaLabelOpenList", "className", "clearable", "disabled", "disableLabelAnimation", "feedback", "items", "label", "labelClearSelectedItem", "listStyle", "loadingText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "style", "variant"];
2249
+ var _excluded$1 = ["ariaLabelCloseList", "ariaLabelOpenList", "className", "clearable", "disabled", "disableLabelAnimation", "feedback", "items", "label", "labelClearSelectedItem", "listStyle", "loadingText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
2232
2250
  var Dropdown = function Dropdown(_ref) {
2233
2251
  var _ref3, _selectedItem$label;
2234
2252
  var ariaLabelCloseList = _ref.ariaLabelCloseList,
@@ -2254,6 +2272,8 @@ var Dropdown = function Dropdown(_ref) {
2254
2272
  selectedItem = _ref.selectedItem,
2255
2273
  _ref$selectOnBlur = _ref.selectOnBlur,
2256
2274
  selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
2275
+ _ref$selectOnTab = _ref.selectOnTab,
2276
+ selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
2257
2277
  style = _ref.style,
2258
2278
  _ref$variant = _ref.variant,
2259
2279
  variant = _ref$variant === void 0 ? 'info' : _ref$variant,
@@ -2325,7 +2345,10 @@ var Dropdown = function Dropdown(_ref) {
2325
2345
  }, rest), React.createElement("div", _extends({
2326
2346
  className: "eds-dropdown__selected-item"
2327
2347
  }, getToggleButtonProps({
2328
- id: undefined
2348
+ id: undefined,
2349
+ onKeyDown: function onKeyDown(e) {
2350
+ if (selectOnTab && e.key === 'Tab') onChange == null ? void 0 : onChange(normalizedItems[highlightedIndex]);
2351
+ }
2329
2352
  })), (_ref3 = (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : React.createElement("span", {
2330
2353
  className: classNames('eds-dropdown__selected-item__placeholder', {
2331
2354
  'eds-dropdown__selected-item__placeholder--readonly': readOnly