downshift 9.3.1 → 9.4.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/downshift.cjs.cjs +623 -702
  2. package/dist/downshift.d.ts +49 -55
  3. package/dist/downshift.esm.mjs +624 -703
  4. package/dist/downshift.native.cjs.cjs +578 -654
  5. package/dist/downshift.nativeweb.cjs.cjs +621 -697
  6. package/dist/downshift.types.d.ts +205 -0
  7. package/dist/downshift.umd.js +627 -706
  8. package/dist/downshift.umd.js.map +1 -1
  9. package/dist/downshift.umd.min.js +1 -1
  10. package/dist/downshift.umd.min.js.map +1 -1
  11. package/dist/hooks/testUtils/MemoizedItem.d.ts +10 -0
  12. package/dist/hooks/testUtils/fixtures.d.ts +16 -0
  13. package/dist/hooks/testUtils/index.d.ts +4 -0
  14. package/dist/hooks/testUtils/interactions.d.ts +16 -0
  15. package/dist/hooks/testUtils/testCases.d.ts +2 -0
  16. package/dist/hooks/useCombobox/__tests__/utils/index.d.ts +5 -0
  17. package/dist/hooks/useCombobox/__tests__/utils/interactions.d.ts +6 -0
  18. package/dist/hooks/useCombobox/__tests__/utils/renderCombobox.d.ts +72 -0
  19. package/dist/hooks/useCombobox/__tests__/utils/renderUseCombobox.d.ts +2 -0
  20. package/dist/hooks/useCombobox/index.d.ts +4 -94
  21. package/dist/hooks/useCombobox/index.types.d.ts +302 -0
  22. package/dist/hooks/useCombobox/reducer.d.ts +4 -1
  23. package/dist/hooks/useCombobox/stateChangeTypes.d.ts +24 -23
  24. package/dist/hooks/useCombobox/utils/getInitialState.d.ts +10 -0
  25. package/dist/hooks/useCombobox/utils/index.d.ts +3 -0
  26. package/dist/hooks/useCombobox/{utils.d.ts → utils/propTypes.d.ts} +2 -30
  27. package/dist/hooks/useCombobox/utils/useControlledReducer.d.ts +16 -0
  28. package/dist/hooks/useMultipleSelection/index.d.ts +25 -13
  29. package/dist/hooks/useMultipleSelection/index.types.d.ts +117 -0
  30. package/dist/hooks/useMultipleSelection/reducer.d.ts +1 -1
  31. package/dist/hooks/useMultipleSelection/utils.d.ts +14 -15
  32. package/dist/hooks/useSelect/__tests__/utils/getItemIndexByCharacter.d.ts +7 -0
  33. package/dist/hooks/useSelect/__tests__/utils/index.d.ts +6 -0
  34. package/dist/hooks/useSelect/__tests__/utils/renderSelect.d.ts +71 -0
  35. package/dist/hooks/useSelect/__tests__/utils/renderUseSelect.d.ts +2 -0
  36. package/dist/hooks/useSelect/__tests__/utils/stateChangeTestCases.d.ts +182 -0
  37. package/dist/hooks/useSelect/index.d.ts +4 -71
  38. package/dist/hooks/useSelect/index.types.d.ts +266 -0
  39. package/dist/hooks/useSelect/reducer.d.ts +4 -1
  40. package/dist/hooks/useSelect/stateChangeTypes.d.ts +23 -22
  41. package/dist/hooks/useSelect/utils/index.d.ts +0 -1
  42. package/dist/hooks/useTagGroup/__tests__/utils/renderTagGroup.d.ts +1 -1
  43. package/dist/hooks/useTagGroup/index.types.d.ts +10 -13
  44. package/dist/hooks/useTagGroup/reducer.d.ts +4 -2
  45. package/dist/hooks/useTagGroup/utils/index.d.ts +3 -1
  46. package/dist/hooks/utils/__tests__/dropdownDefaultProps.test.d.ts +1 -0
  47. package/dist/hooks/utils/__tests__/getChangesOnSelection.test.d.ts +1 -0
  48. package/dist/hooks/utils/__tests__/getDefaultHighlightedIndex.test.d.ts +1 -0
  49. package/dist/hooks/utils/__tests__/getDefaultValue.test.d.ts +1 -0
  50. package/dist/hooks/utils/__tests__/getHighlightedIndexOnOpen.test.d.ts +1 -0
  51. package/dist/hooks/utils/__tests__/getInitialValue.test.d.ts +1 -0
  52. package/dist/hooks/utils/__tests__/getItemAndIndex.test.d.ts +1 -0
  53. package/dist/hooks/utils/__tests__/isDropdownStateEqual.test.d.ts +1 -0
  54. package/dist/hooks/utils/__tests__/useA11yMessageStatus.test.d.ts +1 -0
  55. package/dist/hooks/utils/__tests__/useControlPropsValidator.test.d.ts +1 -0
  56. package/dist/hooks/utils/__tests__/useControlledReducer.test.d.ts +1 -0
  57. package/dist/hooks/utils/__tests__/useElementIds.legacy.test.d.ts +1 -0
  58. package/dist/hooks/utils/__tests__/useElementIds.r18.test.d.ts +1 -0
  59. package/dist/hooks/utils/__tests__/useEnhancedReducer.test.d.ts +1 -0
  60. package/dist/hooks/utils/__tests__/useGetterPropsCalledChecker.test.d.ts +1 -0
  61. package/dist/hooks/utils/__tests__/useIsInitialMount.test.d.ts +1 -0
  62. package/dist/hooks/utils/__tests__/useMouseAndTouchTracker.test.d.ts +1 -0
  63. package/dist/hooks/utils/__tests__/useScrollIntoView.test.d.ts +1 -0
  64. package/dist/hooks/utils/callOnChangeProps.d.ts +4 -0
  65. package/dist/hooks/utils/dropdownDefaultProps.d.ts +13 -0
  66. package/dist/hooks/{utils.dropdown/defaultStateValues.d.ts → utils/dropdownDefaultStateValues.d.ts} +2 -2
  67. package/dist/hooks/{utils.dropdown/propTypes.d.ts → utils/dropdownPropTypes.d.ts} +1 -1
  68. package/dist/hooks/utils/getChangesOnSelection.d.ts +17 -0
  69. package/dist/hooks/utils/getDefaultHighlightedIndex.d.ts +7 -0
  70. package/dist/hooks/utils/getDefaultValue.d.ts +8 -0
  71. package/dist/hooks/utils/getHighlightedIndexOnOpen.d.ts +16 -0
  72. package/dist/hooks/utils/getInitialState.d.ts +23 -0
  73. package/dist/hooks/utils/getInitialValue.d.ts +14 -0
  74. package/dist/hooks/utils/index.d.ts +24 -0
  75. package/dist/hooks/utils/index.types.d.ts +26 -0
  76. package/dist/hooks/utils/isDropdownStateEqual.d.ts +16 -0
  77. package/dist/hooks/utils/reducer.d.ts +27 -0
  78. package/dist/hooks/utils/useControlPropsValidator.d.ts +6 -0
  79. package/dist/hooks/utils/useControlledReducer.d.ts +13 -0
  80. package/dist/hooks/utils/useEnhancedReducer.d.ts +15 -0
  81. package/dist/hooks/utils/useGetterPropsCalledChecker.d.ts +2 -0
  82. package/dist/hooks/utils/useMouseAndTouchTracker.d.ts +15 -0
  83. package/dist/hooks/utils/useScrollIntoView.d.ts +11 -0
  84. package/dist/index.d.ts +1 -1
  85. package/dist/utils/__tests__/callAllEventHandlers.test.d.ts +1 -0
  86. package/dist/utils/__tests__/debounce.test.d.ts +1 -0
  87. package/dist/utils/__tests__/generateId.r18.test.d.ts +1 -0
  88. package/dist/utils/__tests__/generateId.test.d.ts +1 -0
  89. package/dist/utils/__tests__/getHighlightedIndex.test.d.ts +1 -0
  90. package/dist/utils/__tests__/getNonDisabledIndex.test.d.ts +1 -0
  91. package/dist/utils/__tests__/getState.test.d.ts +1 -0
  92. package/dist/utils/__tests__/handleRefs.test.d.ts +1 -0
  93. package/dist/utils/__tests__/normalizeArrowKey.test.d.ts +1 -0
  94. package/dist/utils/__tests__/scrollIntoView.test.d.ts +1 -0
  95. package/dist/utils/__tests__/setA11yStatus.test.d.ts +1 -0
  96. package/dist/utils/__tests__/targetWithinDownshift.test.d.ts +1 -0
  97. package/dist/utils/__tests__/useLatestRef.test.d.ts +1 -0
  98. package/dist/utils/__tests__/validateControlledUnchanged.test.d.ts +1 -0
  99. package/dist/utils/__tests__/validatePropTypes.test.d.ts +1 -0
  100. package/dist/utils/getHighlightedIndex.d.ts +11 -0
  101. package/dist/utils/getNonDisabledIndex.d.ts +11 -0
  102. package/dist/utils/getState.d.ts +12 -0
  103. package/dist/utils/handleRefs.d.ts +2 -0
  104. package/dist/{utils-ts → utils}/index.d.ts +5 -1
  105. package/dist/utils/normalizeArrowKey.d.ts +6 -0
  106. package/dist/utils/targetWithinDownshift.d.ts +12 -0
  107. package/dist/utils/validateControlledUnchanged.d.ts +1 -0
  108. package/dist/utils/validatePropTypes.d.ts +2 -0
  109. package/dist/utils.legacy.d.ts +54 -0
  110. package/flow-typed/npm/downshift_v2.x.x.js.flow +87 -62
  111. package/package.json +2 -4
  112. package/preact/dist/downshift.cjs.cjs +623 -702
  113. package/preact/dist/downshift.cjs.js +4265 -0
  114. package/preact/dist/downshift.esm.js +4238 -0
  115. package/preact/dist/downshift.esm.mjs +624 -703
  116. package/preact/dist/downshift.umd.js +623 -702
  117. package/preact/dist/downshift.umd.js.map +1 -1
  118. package/preact/dist/downshift.umd.min.js +1 -1
  119. package/preact/dist/downshift.umd.min.js.map +1 -1
  120. package/typings/index.d.ts +13 -21
  121. package/dist/hooks/reducer.d.ts +0 -1
  122. package/dist/hooks/useSelect/utils/defaultProps.d.ts +0 -8
  123. package/dist/hooks/utils-ts/callOnChangeProps.d.ts +0 -2
  124. package/dist/hooks/utils-ts/getDefaultValue.d.ts +0 -2
  125. package/dist/hooks/utils-ts/getInitialValue.d.ts +0 -2
  126. package/dist/hooks/utils-ts/index.d.ts +0 -11
  127. package/dist/hooks/utils-ts/stateReducer.d.ts +0 -6
  128. package/dist/hooks/utils-ts/useControlledReducer.d.ts +0 -12
  129. package/dist/hooks/utils-ts/useEnhancedReducer.d.ts +0 -13
  130. package/dist/hooks/utils.d.ts +0 -58
  131. package/dist/hooks/utils.dropdown/defaultProps.d.ts +0 -9
  132. package/dist/hooks/utils.dropdown/index.d.ts +0 -3
  133. package/dist/utils-ts/getState.d.ts +0 -22
  134. package/dist/utils-ts/handleRefs.d.ts +0 -2
  135. package/dist/utils-ts/validatePropTypes.d.ts +0 -2
  136. package/dist/utils.d.ts +0 -123
  137. package/typings/index.legacy.d.ts +0 -888
  138. /package/dist/hooks/{utils-ts/__tests__/getItemAndIndex.test.d.ts → useCombobox/utils/__tests__/getInitialState.test.d.ts} +0 -0
  139. /package/dist/hooks/{utils.dropdown/__tests__/useElementIds.legacy.test.d.ts → useCombobox/utils/__tests__/useControlledReducer.test.d.ts} +0 -0
  140. /package/dist/hooks/{utils.dropdown/__tests__/useElementIds.r18.test.d.ts → useSelect/utils/__tests__/getItemIndexByCharacterKey.test.d.ts} +0 -0
  141. /package/dist/{utils-ts/__tests__/getState.test.d.ts → hooks/utils/__tests__/callOnChangeProps.test.d.ts} +0 -0
  142. /package/dist/{utils-ts/__tests__/handleRefs.test.d.ts → hooks/utils/__tests__/capitalizeString.test.d.ts} +0 -0
  143. /package/dist/hooks/{utils-ts → utils}/capitalizeString.d.ts +0 -0
  144. /package/dist/hooks/{utils-ts → utils}/getItemAndIndex.d.ts +0 -0
  145. /package/dist/hooks/{utils-ts → utils}/propTypes.d.ts +0 -0
  146. /package/dist/hooks/{utils-ts → utils}/useA11yMessageStatus.d.ts +0 -0
  147. /package/dist/hooks/{utils.dropdown → utils}/useElementIds.d.ts +0 -0
  148. /package/dist/hooks/{utils-ts → utils}/useIsInitialMount.d.ts +0 -0
  149. /package/dist/{utils-ts → utils}/callAllEventHandlers.d.ts +0 -0
  150. /package/dist/{utils-ts → utils}/debounce.d.ts +0 -0
  151. /package/dist/{utils-ts → utils}/generateId.d.ts +0 -0
  152. /package/dist/{utils-ts → utils}/noop.d.ts +0 -0
  153. /package/dist/{utils-ts → utils}/scrollIntoView.d.ts +0 -0
  154. /package/dist/{utils-ts → utils}/setA11yStatus.d.ts +0 -0
  155. /package/dist/{utils-ts → utils}/useLatestRef.d.ts +0 -0
@@ -57,7 +57,7 @@
57
57
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
58
58
  }
59
59
 
60
- var propTypes$6 = {exports: {}};
60
+ var propTypes$5 = {exports: {}};
61
61
 
62
62
  var reactIs$1 = {exports: {}};
63
63
 
@@ -1129,7 +1129,7 @@
1129
1129
  var hasRequiredPropTypes;
1130
1130
 
1131
1131
  function requirePropTypes () {
1132
- if (hasRequiredPropTypes) return propTypes$6.exports;
1132
+ if (hasRequiredPropTypes) return propTypes$5.exports;
1133
1133
  hasRequiredPropTypes = 1;
1134
1134
  {
1135
1135
  var ReactIs = requireReactIs$1();
@@ -1137,9 +1137,9 @@
1137
1137
  // By explicitly using `prop-types` you are opting into new development behavior.
1138
1138
  // http://fb.me/prop-types-in-prod
1139
1139
  var throwOnDirectAccess = true;
1140
- propTypes$6.exports = /*@__PURE__*/ requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
1140
+ propTypes$5.exports = /*@__PURE__*/ requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
1141
1141
  }
1142
- return propTypes$6.exports;
1142
+ return propTypes$5.exports;
1143
1143
  }
1144
1144
 
1145
1145
  var propTypesExports = /*@__PURE__*/ requirePropTypes();
@@ -1462,7 +1462,7 @@
1462
1462
  return ref;
1463
1463
  }
1464
1464
 
1465
- function handleRefs$1() {
1465
+ function handleRefs() {
1466
1466
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
1467
1467
  refs[_key] = arguments[_key];
1468
1468
  }
@@ -1484,7 +1484,7 @@
1484
1484
  * @param fns the event handler functions
1485
1485
  * @return the event handler to add to an element
1486
1486
  */
1487
- function callAllEventHandlers$1() {
1487
+ function callAllEventHandlers() {
1488
1488
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
1489
1489
  fns[_key] = arguments[_key];
1490
1490
  }
@@ -1506,7 +1506,7 @@
1506
1506
  * function once after the time given has passed since
1507
1507
  * it was last called.
1508
1508
  */
1509
- function debounce$1(fn, time) {
1509
+ function debounce(fn, time) {
1510
1510
  var timeoutId;
1511
1511
  function cancel() {
1512
1512
  if (timeoutId) {
@@ -1527,7 +1527,7 @@
1527
1527
  return wrapper;
1528
1528
  }
1529
1529
 
1530
- var cleanupStatus = debounce$1(function (document) {
1530
+ var cleanupStatus = debounce(function (document) {
1531
1531
  getStatusDiv(document).textContent = '';
1532
1532
  }, 500);
1533
1533
 
@@ -1608,6 +1608,8 @@
1608
1608
  }
1609
1609
  var keys = Object.keys(state);
1610
1610
  return keys.reduce(function (newState, key) {
1611
+ // state keys could be in props, but with value undefined, which means they should be ignored.
1612
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1611
1613
  if (props[key] !== undefined) {
1612
1614
  newState[key] = props[key];
1613
1615
  }
@@ -1638,93 +1640,149 @@
1638
1640
  }
1639
1641
 
1640
1642
  /**
1641
- * Accepts a parameter and returns it if it's a function
1642
- * or a noop function if it's not. This allows us to
1643
- * accept a callback, but not worry about it if it's not
1644
- * passed.
1645
- * @param {Function} cb the callback
1646
- * @return {Function} a function
1647
- */
1648
- function cbToCb(cb) {
1649
- return typeof cb === 'function' ? cb : noop;
1650
- }
1651
-
1652
- /**
1653
- * @param {HTMLElement} parent the parent node
1654
- * @param {HTMLElement} child the child node
1655
- * @param {Window} environment The window context where downshift renders.
1656
- * @return {Boolean} whether the parent is the child or the child is in the parent
1643
+ * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
1644
+ * @param event a keyboardEvent object
1645
+ * @return keyboard key
1657
1646
  */
1658
- function isOrContainsNode(parent, child, environment) {
1659
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
1660
- return result;
1647
+ function normalizeArrowKey(event) {
1648
+ var key = event.key,
1649
+ keyCode = event.keyCode;
1650
+ /* istanbul ignore next (ie) */
1651
+ if (keyCode >= 37 && keyCode <= 40 && !key.startsWith('Arrow')) {
1652
+ return "Arrow" + key;
1653
+ }
1654
+ return key;
1661
1655
  }
1662
1656
 
1663
1657
  /**
1664
- * Simple debounce implementation. Will call the given
1665
- * function once after the time given has passed since
1666
- * it was last called.
1667
- * @param {Function} fn the function to call after the time
1668
- * @param {Number} time the time to wait
1669
- * @return {Function} the debounced function
1658
+ * Returns the next non-disabled highlightedIndex value.
1659
+ *
1660
+ * @param start The current highlightedIndex.
1661
+ * @param backwards If true, it will search backwards from the start.
1662
+ * @param items The items array.
1663
+ * @param isItemDisabled Function that tells if an item is disabled or not.
1664
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
1665
+ * @returns The next non-disabled index.
1670
1666
  */
1671
- function debounce(fn, time) {
1672
- var timeoutId;
1673
- function cancel() {
1674
- if (timeoutId) {
1675
- clearTimeout(timeoutId);
1676
- }
1667
+ function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
1668
+ if (circular === void 0) {
1669
+ circular = false;
1677
1670
  }
1678
- function wrapper() {
1679
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1680
- args[_key] = arguments[_key];
1671
+ var count = items.length;
1672
+ if (backwards) {
1673
+ for (var index = start; index >= 0; index--) {
1674
+ if (!isItemDisabled(items[index], index)) {
1675
+ return index;
1676
+ }
1677
+ }
1678
+ } else {
1679
+ for (var _index = start; _index < count; _index++) {
1680
+ if (!isItemDisabled(items[_index], _index)) {
1681
+ return _index;
1682
+ }
1681
1683
  }
1682
- cancel();
1683
- timeoutId = setTimeout(function () {
1684
- timeoutId = null;
1685
- fn.apply(void 0, args);
1686
- }, time);
1687
1684
  }
1688
- wrapper.cancel = cancel;
1689
- return wrapper;
1685
+ if (circular) {
1686
+ return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
1687
+ }
1688
+ return -1;
1690
1689
  }
1691
1690
 
1692
1691
  /**
1693
- * This is intended to be used to compose event handlers.
1694
- * They are executed in order until one of them sets
1695
- * `event.preventDownshiftDefault = true`.
1696
- * @param {...Function} fns the event handler functions
1697
- * @return {Function} the event handler to add to an element
1692
+ * Returns the next non-disabled highlightedIndex value.
1693
+ *
1694
+ * @param start The current highlightedIndex.
1695
+ * @param offset The offset from the current highlightedIndex to start searching.
1696
+ * @param items The items array.
1697
+ * @param isItemDisabled Function that tells if an item is disabled or not.
1698
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
1699
+ * @returns The next highlightedIndex.
1698
1700
  */
1699
- function callAllEventHandlers() {
1700
- for (var _len2 = arguments.length, fns = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1701
- fns[_key2] = arguments[_key2];
1701
+ function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
1702
+ if (circular === void 0) {
1703
+ circular = false;
1702
1704
  }
1703
- return function (event) {
1704
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
1705
- args[_key3 - 1] = arguments[_key3];
1706
- }
1707
- return fns.some(function (fn) {
1708
- if (fn) {
1709
- fn.apply(void 0, [event].concat(args));
1705
+ var count = items.length;
1706
+ if (count === 0) {
1707
+ return -1;
1708
+ }
1709
+ var itemsLastIndex = count - 1;
1710
+ if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
1711
+ start = offset > 0 ? -1 : itemsLastIndex + 1;
1712
+ }
1713
+ var current = start + offset;
1714
+ if (current < 0) {
1715
+ current = circular ? itemsLastIndex : 0;
1716
+ } else if (current > itemsLastIndex) {
1717
+ current = circular ? 0 : itemsLastIndex;
1718
+ }
1719
+ var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
1720
+ if (highlightedIndex === -1) {
1721
+ return start >= count ? -1 : start;
1722
+ }
1723
+ return highlightedIndex;
1724
+ }
1725
+
1726
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1727
+
1728
+ // eslint-disable-next-line import/no-mutable-exports
1729
+ var validateControlledUnchanged = noop;
1730
+ /* istanbul ignore next */
1731
+ {
1732
+ validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
1733
+ var warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
1734
+ Object.keys(state).forEach(function (propKey) {
1735
+ if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
1736
+ // eslint-disable-next-line no-console
1737
+ console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
1738
+ } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
1739
+ // eslint-disable-next-line no-console
1740
+ console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
1710
1741
  }
1711
- return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
1712
1742
  });
1713
1743
  };
1714
1744
  }
1715
- function handleRefs() {
1716
- for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1717
- refs[_key4] = arguments[_key4];
1745
+
1746
+ /**
1747
+ * Checks if event target is within the downshift elements.
1748
+ *
1749
+ * @param target Target to check.
1750
+ * @param downshiftElements The elements that form downshift (list, toggle button etc).
1751
+ * @param environment The window context where downshift renders.
1752
+ * @param checkActiveElement Whether to also check activeElement.
1753
+ *
1754
+ * @returns Whether or not the target is within downshift elements.
1755
+ */
1756
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
1757
+ if (checkActiveElement === void 0) {
1758
+ checkActiveElement = true;
1718
1759
  }
1719
- return function (node) {
1720
- refs.forEach(function (ref) {
1721
- if (typeof ref === 'function') {
1722
- ref(node);
1723
- } else if (ref) {
1724
- ref.current = node;
1725
- }
1726
- });
1727
- };
1760
+ return !!environment && downshiftElements.some(function (contextNode) {
1761
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
1762
+ });
1763
+ }
1764
+
1765
+ /**
1766
+ * @param parent the parent node
1767
+ * @param child the child node
1768
+ * @param environment The window context where downshift renders.
1769
+ * @return Whether the parent is the child or the child is in the parent
1770
+ */
1771
+ function isOrContainsNode(parent, child, environment) {
1772
+ var result = parent === child || child instanceof environment.Node && parent.contains(child);
1773
+ return result;
1774
+ }
1775
+
1776
+ /**
1777
+ * Accepts a parameter and returns it if it's a function
1778
+ * or a noop function if it's not. This allows us to
1779
+ * accept a callback, but not worry about it if it's not
1780
+ * passed.
1781
+ * @param {Function} cb the callback
1782
+ * @return {Function} a function
1783
+ */
1784
+ function cbToCb(cb) {
1785
+ return typeof cb === 'function' ? cb : noop;
1728
1786
  }
1729
1787
 
1730
1788
  /**
@@ -1813,34 +1871,6 @@
1813
1871
  return result;
1814
1872
  }
1815
1873
 
1816
- /**
1817
- * This determines whether a prop is a "controlled prop" meaning it is
1818
- * state which is controlled by the outside of this component rather
1819
- * than within this component.
1820
- *
1821
- * @param {Object} props The props that may contain controlled values.
1822
- * @param {String} key the key to check
1823
- * @return {Boolean} whether it is a controlled controlled prop
1824
- */
1825
- function isControlledProp(props, key) {
1826
- return props[key] !== undefined;
1827
- }
1828
-
1829
- /**
1830
- * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
1831
- * @param {Object} event a keyboardEvent object
1832
- * @return {String} keyboard key
1833
- */
1834
- function normalizeArrowKey(event) {
1835
- var key = event.key,
1836
- keyCode = event.keyCode;
1837
- /* istanbul ignore next (ie) */
1838
- if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
1839
- return "Arrow" + key;
1840
- }
1841
- return key;
1842
- }
1843
-
1844
1874
  /**
1845
1875
  * Simple check if the value passed is object literal
1846
1876
  * @param {*} obj any things
@@ -1850,112 +1880,6 @@
1850
1880
  return Object.prototype.toString.call(obj) === '[object Object]';
1851
1881
  }
1852
1882
 
1853
- /**
1854
- * Returns the next non-disabled highlightedIndex value.
1855
- *
1856
- * @param {number} start The current highlightedIndex.
1857
- * @param {number} offset The offset from the current highlightedIndex to start searching.
1858
- * @param {unknown[]} items The items array.
1859
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
1860
- * @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
1861
- * @returns {number} The next highlightedIndex.
1862
- */
1863
- function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
1864
- if (circular === void 0) {
1865
- circular = false;
1866
- }
1867
- var count = items.length;
1868
- if (count === 0) {
1869
- return -1;
1870
- }
1871
- var itemsLastIndex = count - 1;
1872
- if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
1873
- start = offset > 0 ? -1 : itemsLastIndex + 1;
1874
- }
1875
- var current = start + offset;
1876
- if (current < 0) {
1877
- current = circular ? itemsLastIndex : 0;
1878
- } else if (current > itemsLastIndex) {
1879
- current = circular ? 0 : itemsLastIndex;
1880
- }
1881
- var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
1882
- if (highlightedIndex === -1) {
1883
- return start >= count ? -1 : start;
1884
- }
1885
- return highlightedIndex;
1886
- }
1887
-
1888
- /**
1889
- * Returns the next non-disabled highlightedIndex value.
1890
- *
1891
- * @param {number} start The current highlightedIndex.
1892
- * @param {boolean} backwards If true, it will search backwards from the start.
1893
- * @param {unknown[]} items The items array.
1894
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
1895
- * @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
1896
- * @returns {number} The next non-disabled index.
1897
- */
1898
- function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
1899
- if (circular === void 0) {
1900
- circular = false;
1901
- }
1902
- var count = items.length;
1903
- if (backwards) {
1904
- for (var index = start; index >= 0; index--) {
1905
- if (!isItemDisabled(items[index], index)) {
1906
- return index;
1907
- }
1908
- }
1909
- } else {
1910
- for (var _index = start; _index < count; _index++) {
1911
- if (!isItemDisabled(items[_index], _index)) {
1912
- return _index;
1913
- }
1914
- }
1915
- }
1916
- if (circular) {
1917
- return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
1918
- }
1919
- return -1;
1920
- }
1921
-
1922
- /**
1923
- * Checks if event target is within the downshift elements.
1924
- *
1925
- * @param {EventTarget} target Target to check.
1926
- * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
1927
- * @param {Window} environment The window context where downshift renders.
1928
- * @param {boolean} checkActiveElement Whether to also check activeElement.
1929
- *
1930
- * @returns {boolean} Whether or not the target is within downshift elements.
1931
- */
1932
- function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
1933
- if (checkActiveElement === void 0) {
1934
- checkActiveElement = true;
1935
- }
1936
- return environment && downshiftElements.some(function (contextNode) {
1937
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
1938
- });
1939
- }
1940
-
1941
- // eslint-disable-next-line import/no-mutable-exports
1942
- var validateControlledUnchanged = noop;
1943
- /* istanbul ignore next */
1944
- {
1945
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
1946
- var warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
1947
- Object.keys(state).forEach(function (propKey) {
1948
- if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
1949
- // eslint-disable-next-line no-console
1950
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
1951
- } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
1952
- // eslint-disable-next-line no-console
1953
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
1954
- }
1955
- });
1956
- };
1957
- }
1958
-
1959
1883
  var _excluded$4 = ["refKey", "ref"],
1960
1884
  _excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
1961
1885
  _excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
@@ -2106,7 +2030,7 @@
2106
2030
  }
2107
2031
  newStateToSet[key];
2108
2032
  // if it's coming from props, then we don't care to set it internally
2109
- if (!isControlledProp(_this.props, key)) {
2033
+ if (_this.props[key] === undefined) {
2110
2034
  nextState[key] = newStateToSet[key];
2111
2035
  }
2112
2036
  });
@@ -2836,7 +2760,7 @@
2836
2760
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
2837
2761
  }
2838
2762
  }
2839
- if (isControlledProp(this.props, 'selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
2763
+ if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
2840
2764
  this.internalSetState({
2841
2765
  type: controlledPropUpdatedSelectedItem,
2842
2766
  inputValue: this.props.itemToString(this.props.selectedItem)
@@ -3019,7 +2943,7 @@
3019
2943
  changes[key] = newState[key];
3020
2944
  }
3021
2945
  }
3022
- if (props.onStateChange && Object.keys(changes).length) {
2946
+ if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
3023
2947
  props.onStateChange(_extends({
3024
2948
  type: type
3025
2949
  }, changes));
@@ -3045,50 +2969,53 @@
3045
2969
  * two reducers, one from downshift and an optional one from the user.
3046
2970
  * Also calls the onChange handlers for state values that have changed.
3047
2971
  *
3048
- * @param {Function} reducer Reducer function from downshift.
3049
- * @param {Object} props The hook props, also passed to createInitialState.
3050
- * @param {Function} createInitialState Function that returns the initial state.
3051
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
3052
- * @returns {Array} An array with the state and an action dispatcher.
2972
+ * @param reducer Reducer function from downshift.
2973
+ * @param props The hook props, also passed to createInitialState.
2974
+ * @param createInitialState Function that returns the initial state.
2975
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
2976
+ * @returns An array with the state and an action dispatcher.
3053
2977
  */
3054
2978
  function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
3055
- var prevStateRef = React__namespace.useRef(null);
3056
- var actionRef = React__namespace.useRef(undefined);
3057
- var propsRef = useLatestRef(props);
2979
+ var prevStateRef = React__namespace.useRef({});
2980
+ var actionRef = React__namespace.useRef();
3058
2981
  var enhancedReducer = React__namespace.useCallback(function (state, action) {
3059
2982
  actionRef.current = action;
3060
- state = getState(state, propsRef.current);
3061
- var changes = reducer(state, propsRef.current, action);
3062
- var newState = propsRef.current.stateReducer(state, _extends({}, action, {
2983
+ state = getState(state, action.props);
2984
+ var changes = reducer(state, action);
2985
+ var newState = action.props.stateReducer(state, _extends({}, action, {
3063
2986
  changes: changes
3064
2987
  }));
3065
2988
  return _extends({}, state, newState);
3066
- }, [propsRef, reducer]);
2989
+ }, [reducer]);
3067
2990
  var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
3068
2991
  state = _React$useReducer[0],
3069
2992
  dispatch = _React$useReducer[1];
2993
+ var propsRef = useLatestRef(props);
2994
+ var dispatchWithProps = React__namespace.useCallback(function (action) {
2995
+ return dispatch(_extends({}, action, {
2996
+ props: propsRef.current
2997
+ }));
2998
+ }, [propsRef]);
3070
2999
  var action = actionRef.current;
3071
3000
  React__namespace.useEffect(function () {
3072
- var _prevStateRef$current;
3073
- var prevState = getState((_prevStateRef$current = prevStateRef.current) != null ? _prevStateRef$current : {}, propsRef.current);
3074
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
3001
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
3002
+ var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
3075
3003
  if (shouldCallOnChangeProps) {
3076
- callOnChangeProps(action, propsRef.current, prevState, state);
3004
+ callOnChangeProps(action, action.props, prevState, state);
3077
3005
  }
3078
3006
  prevStateRef.current = state;
3079
- }, [state, action, isStateEqual, propsRef]);
3080
- return [state, dispatch];
3007
+ }, [state, action, isStateEqual]);
3008
+ return [state, dispatchWithProps];
3081
3009
  }
3082
3010
 
3083
3011
  /**
3084
3012
  * Wraps the useEnhancedReducer and applies the controlled prop values before
3085
3013
  * returning the new state.
3086
- *
3087
- * @param {Function} reducer Reducer function from downshift.
3088
- * @param {Object} props The hook props, also passed to createInitialState.
3089
- * @param {Function} createInitialState Function that returns the initial state.
3090
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
3091
- * @returns {Array} An array with the state and an action dispatcher.
3014
+ * @param reducer Reducer function from downshift.
3015
+ * @param props The hook props, also passed to createInitialState.
3016
+ * @param createInitialState Function that returns the initial state.
3017
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
3018
+ * @returns An array with the state and an action dispatcher.
3092
3019
  */
3093
3020
  function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
3094
3021
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
@@ -3141,16 +3068,8 @@
3141
3068
  return isInitialMountRef.current;
3142
3069
  }
3143
3070
 
3144
- /**
3145
- * Default state reducer that returns the changes.
3146
- *
3147
- */
3148
- function stateReducer(_s, a) {
3149
- return a.changes;
3150
- }
3151
-
3152
3071
  // Shared between all exports.
3153
- var propTypes$5 = {
3072
+ var propTypes$4 = {
3154
3073
  environment: PropTypes.shape({
3155
3074
  addEventListener: PropTypes.func.isRequired,
3156
3075
  removeEventListener: PropTypes.func.isRequired,
@@ -3166,30 +3085,47 @@
3166
3085
  stateReducer: PropTypes.func
3167
3086
  };
3168
3087
 
3169
- function getDefaultValue$1(props, propKey, defaultStateValues) {
3170
- var defaultValue = props["default" + capitalizeString(propKey)];
3171
- if (defaultValue !== undefined) {
3172
- return defaultValue;
3173
- }
3174
- return defaultStateValues[propKey];
3088
+ /**
3089
+ * Returns the default value based on the defaultProp and defaultStateValue.
3090
+ *
3091
+ * @param defaultProp The default prop value.
3092
+ * @param defaultStateValue The default state value.
3093
+ * @returns The resolved default value.
3094
+ */
3095
+ function getDefaultValue(defaultProp, defaultStateValue) {
3096
+ return defaultProp === undefined ? defaultStateValue : defaultProp;
3175
3097
  }
3176
3098
 
3177
- function getInitialValue$1(props, propKey, defaultStateValues) {
3178
- var value = props[propKey];
3099
+ /**
3100
+ * Returns the initial value for a state variable, based on the following precedence:
3101
+ * 1. The controlled value (if it's not undefined)
3102
+ * 2. The initialValue (if it's not undefined)
3103
+ * 3. The defaultValue (if it's not undefined)
3104
+ * 4. The defaultStateValue
3105
+ *
3106
+ * @param value The controlled value of the state variable.
3107
+ * @param initialValue The initial value of the state variable.
3108
+ * @param defaultValue The default value of the state variable.
3109
+ * @param defaultStateValue The default state value to use if all other values are undefined.
3110
+ * @returns The initial value for the state variable.
3111
+ */
3112
+ function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
3179
3113
  if (value !== undefined) {
3180
3114
  return value;
3181
3115
  }
3182
- var initialValue = props["initial" + capitalizeString(propKey)];
3183
3116
  if (initialValue !== undefined) {
3184
3117
  return initialValue;
3185
3118
  }
3186
- return getDefaultValue$1(props, propKey, defaultStateValues);
3119
+ if (defaultValue !== undefined) {
3120
+ return defaultValue;
3121
+ }
3122
+ return defaultStateValue;
3187
3123
  }
3188
3124
 
3189
3125
  /**
3190
3126
  * Debounced call for updating the a11y message.
3191
3127
  */
3192
- var updateA11yStatus = debounce$1(function (status, document) {
3128
+ var updateA11yStatus = debounce(function (status, document) {
3193
3129
  setStatus(status, document);
3194
3130
  }, 200);
3195
3131
 
@@ -3225,7 +3161,7 @@
3225
3161
  }
3226
3162
 
3227
3163
  // Shared between useSelect, useCombobox, Downshift.
3228
- var propTypes$4 = _extends({}, propTypes$5, {
3164
+ var dropdownPropTypes = _extends({}, propTypes$4, {
3229
3165
  getA11yStatusMessage: PropTypes.func,
3230
3166
  highlightedIndex: PropTypes.number,
3231
3167
  defaultHighlightedIndex: PropTypes.number,
@@ -3248,62 +3184,145 @@
3248
3184
  scrollIntoView: PropTypes.func
3249
3185
  });
3250
3186
 
3251
- var defaultProps$3 = {
3187
+ var dropdownDefaultProps = {
3252
3188
  itemToString: function itemToString(item) {
3253
3189
  return item ? String(item) : '';
3254
3190
  },
3255
3191
  itemToKey: function itemToKey(item) {
3256
3192
  return item;
3257
3193
  },
3258
- stateReducer: stateReducer,
3194
+ isItemDisabled: function isItemDisabled(_item) {
3195
+ return false;
3196
+ },
3197
+ stateReducer: function stateReducer(_state, actionAndChanges) {
3198
+ return actionAndChanges.changes;
3199
+ },
3259
3200
  scrollIntoView: scrollIntoView,
3260
3201
  environment: /* istanbul ignore next (ssr) */
3261
3202
  typeof window === 'undefined' || false ? undefined : window
3262
3203
  };
3263
3204
 
3264
- var defaultStateValues$1 = {
3205
+ var dropdownDefaultStateValues = {
3265
3206
  highlightedIndex: -1,
3266
3207
  isOpen: false,
3267
3208
  selectedItem: null,
3268
3209
  inputValue: ''
3269
3210
  };
3270
3211
 
3271
- // istanbul ignore next
3272
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
3273
- function isAcceptedCharacterKey(key) {
3274
- return /^\S{1}$/.test(key);
3212
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
3213
+ var SafeReact$1 = _extends({}, React__namespace);
3214
+ var reactUseId$1 = SafeReact$1.useId;
3215
+ var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
3216
+ function useElementIdsR18$1(_ref) {
3217
+ var id = _ref.id,
3218
+ labelId = _ref.labelId,
3219
+ menuId = _ref.menuId,
3220
+ getItemId = _ref.getItemId,
3221
+ toggleButtonId = _ref.toggleButtonId,
3222
+ inputId = _ref.inputId;
3223
+ var reactId = "downshift-" + reactUseId$1();
3224
+ if (!id) {
3225
+ id = reactId;
3226
+ }
3227
+ var elementIds = React__namespace.useMemo(function () {
3228
+ return {
3229
+ labelId: labelId != null ? labelId : id + "-label",
3230
+ menuId: menuId != null ? menuId : id + "-menu",
3231
+ getItemId: getItemId != null ? getItemId : function (index) {
3232
+ return id + "-item-" + index;
3233
+ },
3234
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
3235
+ inputId: inputId != null ? inputId : id + "-input"
3236
+ };
3237
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
3238
+ return elementIds;
3275
3239
  }
3276
- function getInitialState$3(props) {
3277
- var selectedItem = getInitialValue$1(props, 'selectedItem', defaultStateValues$1);
3278
- var isOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
3279
- var highlightedIndex = getInitialHighlightedIndex(props);
3280
- var inputValue = getInitialValue$1(props, 'inputValue', defaultStateValues$1);
3281
- return {
3282
- highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
3283
- return props.itemToKey(item) === props.itemToKey(selectedItem);
3284
- }) : highlightedIndex,
3285
- isOpen: isOpen,
3286
- selectedItem: selectedItem,
3287
- inputValue: inputValue
3288
- };
3240
+ function useElementIdsLegacy$1(_ref2) {
3241
+ var id = _ref2.id,
3242
+ labelId = _ref2.labelId,
3243
+ menuId = _ref2.menuId,
3244
+ getItemId = _ref2.getItemId,
3245
+ toggleButtonId = _ref2.toggleButtonId,
3246
+ inputId = _ref2.inputId;
3247
+ var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
3248
+ var baseId = baseIdRef.current;
3249
+ var elementIds = React__namespace.useMemo(function () {
3250
+ return {
3251
+ labelId: labelId != null ? labelId : baseId + "-label",
3252
+ menuId: menuId != null ? menuId : baseId + "-menu",
3253
+ getItemId: getItemId != null ? getItemId : function (index) {
3254
+ return baseId + "-item-" + index;
3255
+ },
3256
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
3257
+ inputId: inputId != null ? inputId : baseId + "-input"
3258
+ };
3259
+ }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
3260
+ return elementIds;
3289
3261
  }
3290
- function getHighlightedIndexOnOpen(props, state, offset) {
3291
- var items = props.items,
3292
- initialHighlightedIndex = props.initialHighlightedIndex,
3293
- defaultHighlightedIndex = props.defaultHighlightedIndex,
3294
- isItemDisabled = props.isItemDisabled,
3295
- itemToKey = props.itemToKey;
3296
- var selectedItem = state.selectedItem,
3297
- highlightedIndex = state.highlightedIndex;
3262
+
3263
+ /**
3264
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
3265
+ *
3266
+ * @param props Props passed to the hook.
3267
+ * @returns The highlighted index.
3268
+ */
3269
+ function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
3270
+ var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
3271
+ if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
3272
+ return -1;
3273
+ }
3274
+ return highlightedIndex;
3275
+ }
3276
+
3277
+ /**
3278
+ * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
3279
+ * In that case, selects the item and resets to defaults for open state and highlighted idex.
3280
+ *
3281
+ * @param props The Dropdown props.
3282
+ * @param highlightedIndex The index from the state.
3283
+ * @param inputValue Also return the input value for state.
3284
+ * @returns The changes for the state.
3285
+ */
3286
+ function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
3287
+ var shouldSelect = items.length && highlightedIndex >= 0;
3288
+ return _extends({
3289
+ isOpen: false,
3290
+ highlightedIndex: -1
3291
+ }, shouldSelect && _extends({
3292
+ selectedItem: items[highlightedIndex],
3293
+ isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
3294
+ highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
3295
+ }, inputValue && {
3296
+ inputValue: itemToString(items[highlightedIndex])
3297
+ }));
3298
+ }
3299
+
3300
+ /* eslint-disable max-params */
3301
+ /**
3302
+ * Returns the highlighted index when the menu is opened.
3303
+ * Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
3304
+ * selectedItem, and the open direction offset.
3305
+ *
3306
+ * @param items The list of items.
3307
+ * @param initialHighlightedIndex The initial highlighted index prop.
3308
+ * @param defaultHighlightedIndex The default highlighted index prop.
3309
+ * @param isItemDisabled Callback to determine if an item is disabled.
3310
+ * @param itemToKey Callback to get a unique key from an item.
3311
+ * @param selectedItem The currently selected item.
3312
+ * @param highlightedIndex The current highlighted index from state.
3313
+ * @param offset The direction of navigation: positive opens downward, negative opens upward.
3314
+ * @returns The new highlighted index.
3315
+ */
3316
+ function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
3298
3317
  if (items.length === 0) {
3299
3318
  return -1;
3300
3319
  }
3301
3320
 
3302
3321
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
3303
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
3322
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
3304
3323
  return initialHighlightedIndex;
3305
3324
  }
3306
- if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
3325
+ if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
3307
3326
  return defaultHighlightedIndex;
3308
3327
  }
3309
3328
  if (selectedItem) {
@@ -3311,21 +3330,71 @@
3311
3330
  return itemToKey(selectedItem) === itemToKey(item);
3312
3331
  });
3313
3332
  }
3314
- if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
3333
+ if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
3315
3334
  return items.length - 1;
3316
3335
  }
3317
- if (offset > 0 && !isItemDisabled(items[0], 0)) {
3336
+ if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
3318
3337
  return 0;
3319
3338
  }
3320
3339
  return -1;
3321
3340
  }
3341
+
3342
+ function getInitialState$3(props) {
3343
+ var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
3344
+ var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
3345
+ var highlightedIndex = getInitialHighlightedIndex(props);
3346
+ var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
3347
+ return {
3348
+ highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
3349
+ return props.itemToKey(item) === props.itemToKey(selectedItem);
3350
+ }) : highlightedIndex,
3351
+ isOpen: isOpen,
3352
+ selectedItem: selectedItem,
3353
+ inputValue: inputValue
3354
+ };
3355
+ }
3356
+
3357
+ /**
3358
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
3359
+ * @param props Props from useCombobox or useSelect.
3360
+ * @returns The highlighted index.
3361
+ */
3362
+ function getInitialHighlightedIndex(props) {
3363
+ var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
3364
+ if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
3365
+ return -1;
3366
+ }
3367
+ return highlightedIndex;
3368
+ }
3369
+
3370
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3371
+ // eslint-disable-next-line import/no-mutable-exports
3372
+ var useControlPropsValidator = noop;
3373
+ /* istanbul ignore next */
3374
+ {
3375
+ useControlPropsValidator = function useControlPropsValidator(_ref) {
3376
+ var props = _ref.props,
3377
+ state = _ref.state;
3378
+ // used for checking when props are moving from controlled to uncontrolled.
3379
+ var prevPropsRef = React__namespace.useRef(props);
3380
+ var isInitialMount = useIsInitialMount();
3381
+ React__namespace.useEffect(function () {
3382
+ if (isInitialMount) {
3383
+ return;
3384
+ }
3385
+ validateControlledUnchanged(state, prevPropsRef.current, props);
3386
+ prevPropsRef.current = props;
3387
+ }, [state, props, isInitialMount]);
3388
+ };
3389
+ }
3390
+
3322
3391
  /**
3323
3392
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
3324
3393
  *
3325
- * @param {Window} environment The environment to add the event listeners to, for instance window.
3326
- * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
3327
- * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
3328
- * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
3394
+ * @param environment The environment to add the event listeners to, for instance window.
3395
+ * @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
3396
+ * @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
3397
+ * @returns The mouse and touch events information.
3329
3398
  */
3330
3399
  function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
3331
3400
  var mouseAndTouchTrackersRef = React__namespace.useRef({
@@ -3389,8 +3458,8 @@
3389
3458
  /**
3390
3459
  * Custom hook that checks if getter props are called correctly.
3391
3460
  *
3392
- * @param {...any} propKeys Getter prop names to be handled.
3393
- * @returns {Function} Setter function called inside getter props to set call information.
3461
+ * @param propKeys Getter prop names to be handled.
3462
+ * @returns Setter function called inside getter props to set call information.
3394
3463
  */
3395
3464
  /* istanbul ignore next */
3396
3465
  {
@@ -3426,120 +3495,58 @@
3426
3495
  getterPropsCalledRef.current[propKey] = {
3427
3496
  suppressRefError: suppressRefError,
3428
3497
  refKey: refKey,
3429
- elementRef: elementRef
3430
- };
3431
- }, []);
3432
- return setGetterPropCallInfo;
3433
- };
3434
- }
3435
- function useScrollIntoView(_ref) {
3436
- var highlightedIndex = _ref.highlightedIndex,
3437
- isOpen = _ref.isOpen,
3438
- itemRefs = _ref.itemRefs,
3439
- getItemNodeFromIndex = _ref.getItemNodeFromIndex,
3440
- menuElement = _ref.menuElement,
3441
- scrollIntoViewProp = _ref.scrollIntoView;
3442
- // used not to scroll on highlight by mouse.
3443
- var shouldScrollRef = React__namespace.useRef(true);
3444
- // Scroll on highlighted item if change comes from keyboard.
3445
- useIsomorphicLayoutEffect(function () {
3446
- if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
3447
- return;
3448
- }
3449
- if (shouldScrollRef.current === false) {
3450
- shouldScrollRef.current = true;
3451
- } else {
3452
- scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
3453
- }
3454
- // eslint-disable-next-line react-hooks/exhaustive-deps
3455
- }, [highlightedIndex]);
3456
- return shouldScrollRef;
3457
- }
3458
-
3459
- // eslint-disable-next-line import/no-mutable-exports
3460
- var useControlPropsValidator = noop;
3461
- /* istanbul ignore next */
3462
- {
3463
- useControlPropsValidator = function useControlPropsValidator(_ref2) {
3464
- var props = _ref2.props,
3465
- state = _ref2.state;
3466
- // used for checking when props are moving from controlled to uncontrolled.
3467
- var prevPropsRef = React__namespace.useRef(props);
3468
- var isInitialMount = useIsInitialMount();
3469
- React__namespace.useEffect(function () {
3470
- if (isInitialMount) {
3471
- return;
3472
- }
3473
- validateControlledUnchanged(state, prevPropsRef.current, props);
3474
- prevPropsRef.current = props;
3475
- }, [state, props, isInitialMount]);
3476
- };
3477
- }
3478
-
3479
- /**
3480
- * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
3481
- * In that case, selects the item and resets to defaults for open state and highlighted idex.
3482
- * @param {Object} props The useCombobox props.
3483
- * @param {number} highlightedIndex The index from the state.
3484
- * @param {boolean} inputValue Also return the input value for state.
3485
- * @returns The changes for the state.
3486
- */
3487
- function getChangesOnSelection(props, highlightedIndex, inputValue) {
3488
- var _props$items;
3489
- if (inputValue === void 0) {
3490
- inputValue = true;
3491
- }
3492
- var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
3493
- return _extends({
3494
- isOpen: false,
3495
- highlightedIndex: -1
3496
- }, shouldSelect && _extends({
3497
- selectedItem: props.items[highlightedIndex],
3498
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
3499
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
3500
- }, inputValue && {
3501
- inputValue: props.itemToString(props.items[highlightedIndex])
3502
- }));
3503
- }
3504
-
3505
- /**
3506
- * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
3507
- * Used by useSelect and useCombobox.
3508
- *
3509
- * @param {Object} prevState
3510
- * @param {Object} newState
3511
- * @returns {boolean} Wheather the states are deeply equal.
3512
- */
3513
- function isDropdownsStateEqual(prevState, newState) {
3514
- return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
3498
+ elementRef: elementRef
3499
+ };
3500
+ }, []);
3501
+ return setGetterPropCallInfo;
3502
+ };
3515
3503
  }
3516
3504
 
3505
+ // istanbul ignore next
3506
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
3507
+
3517
3508
  /**
3518
- * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
3519
- *
3520
- * @param {Object} props Props from useCombobox or useSelect.
3521
- * @returns {number} The highlighted index.
3509
+ * Utility hook that scrolls an item from a menu into view.
3510
+ * @param scrollIntoView The function that does the scroll.
3511
+ * @param highlightedIndex The index of the item that should be scrolled.
3512
+ * @param isOpen If the menu is open or not.
3513
+ * @param menuElement The menu element.
3514
+ * @param itemElements The object containing item elements.
3515
+ * @param getItemId The function to get the item id from index.
3516
+ * @returns Function that when called prevents the scroll.
3522
3517
  */
3523
- function getDefaultHighlightedIndex(props) {
3524
- var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
3525
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
3526
- return -1;
3527
- }
3528
- return highlightedIndex;
3518
+ function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
3519
+ // used not to scroll on highlight by mouse.
3520
+ var shouldScrollRef = React__namespace.useRef(true);
3521
+ // Scroll on highlighted item if change comes from keyboard.
3522
+ useIsomorphicLayoutEffect(function () {
3523
+ if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
3524
+ return;
3525
+ }
3526
+ if (shouldScrollRef.current) {
3527
+ var itemElement = itemElements[getItemId(highlightedIndex)];
3528
+ if (itemElement && menuElement) {
3529
+ scrollIntoView(itemElement, menuElement);
3530
+ }
3531
+ } else {
3532
+ shouldScrollRef.current = true;
3533
+ }
3534
+ }, [highlightedIndex]);
3535
+ return React__namespace.useCallback(function preventScroll() {
3536
+ shouldScrollRef.current = false;
3537
+ }, []);
3529
3538
  }
3530
3539
 
3531
3540
  /**
3532
- * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
3541
+ * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
3542
+ * Used by useSelect and useCombobox.
3533
3543
  *
3534
- * @param {Object} props Props from useCombobox or useSelect.
3535
- * @returns {number} The highlighted index.
3544
+ * @param prevState The previous dropdown state.
3545
+ * @param newState The new dropdown state.
3546
+ * @returns Wheather the states are deeply equal.
3536
3547
  */
3537
- function getInitialHighlightedIndex(props) {
3538
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
3539
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
3540
- return -1;
3541
- }
3542
- return highlightedIndex;
3548
+ function isDropdownStateEqual(prevState, newState) {
3549
+ return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
3543
3550
  }
3544
3551
 
3545
3552
  function downshiftCommonReducer(state, props, action, stateChangeTypes) {
@@ -3560,13 +3567,13 @@
3560
3567
  case stateChangeTypes.FunctionToggleMenu:
3561
3568
  changes = {
3562
3569
  isOpen: !state.isOpen,
3563
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
3570
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
3564
3571
  };
3565
3572
  break;
3566
3573
  case stateChangeTypes.FunctionOpenMenu:
3567
3574
  changes = {
3568
3575
  isOpen: true,
3569
- highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
3576
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
3570
3577
  };
3571
3578
  break;
3572
3579
  case stateChangeTypes.FunctionCloseMenu:
@@ -3575,9 +3582,12 @@
3575
3582
  };
3576
3583
  break;
3577
3584
  case stateChangeTypes.FunctionSetHighlightedIndex:
3578
- changes = {
3579
- highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
3580
- };
3585
+ {
3586
+ var highlightedIndex = action.highlightedIndex;
3587
+ changes = {
3588
+ highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
3589
+ };
3590
+ }
3581
3591
  break;
3582
3592
  case stateChangeTypes.FunctionSetInputValue:
3583
3593
  changes = {
@@ -3586,10 +3596,10 @@
3586
3596
  break;
3587
3597
  case stateChangeTypes.FunctionReset:
3588
3598
  changes = {
3589
- highlightedIndex: getDefaultHighlightedIndex(props),
3590
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
3591
- selectedItem: getDefaultValue$1(props, 'selectedItem', defaultStateValues$1),
3592
- inputValue: getDefaultValue$1(props, 'inputValue', defaultStateValues$1)
3599
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3600
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
3601
+ selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
3602
+ inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
3593
3603
  };
3594
3604
  break;
3595
3605
  default:
@@ -3599,17 +3609,11 @@
3599
3609
  }
3600
3610
  /* eslint-enable complexity */
3601
3611
 
3602
- var propTypes$3 = _extends({}, propTypes$4, {
3612
+ var propTypes$3 = _extends({}, dropdownPropTypes, {
3603
3613
  items: PropTypes.array.isRequired,
3604
3614
  isItemDisabled: PropTypes.func
3605
3615
  });
3606
3616
 
3607
- var defaultProps$2 = _extends({}, defaultProps$3, {
3608
- isItemDisabled: function isItemDisabled() {
3609
- return false;
3610
- }
3611
- });
3612
-
3613
3617
  function getItemIndexByCharacterKey(_ref) {
3614
3618
  var keysSoFar = _ref.keysSoFar,
3615
3619
  highlightedIndex = _ref.highlightedIndex,
@@ -3678,16 +3682,15 @@
3678
3682
  });
3679
3683
 
3680
3684
  /* eslint-disable complexity */
3681
- function downshiftSelectReducer(state, props, action) {
3682
- var _props$items;
3685
+ function downshiftSelectReducer(state, action) {
3683
3686
  var type = action.type,
3684
- altKey = action.altKey;
3687
+ props = action.props;
3685
3688
  var changes;
3686
3689
  switch (type) {
3687
3690
  case ItemClick$1:
3688
3691
  changes = {
3689
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
3690
- highlightedIndex: getDefaultHighlightedIndex(props),
3692
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
3693
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3691
3694
  selectedItem: props.items[action.index]
3692
3695
  };
3693
3696
  break;
@@ -3714,7 +3717,8 @@
3714
3717
  break;
3715
3718
  case ToggleButtonKeyDownArrowDown:
3716
3719
  {
3717
- var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
3720
+ var altKey = action.altKey;
3721
+ var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1);
3718
3722
  changes = {
3719
3723
  highlightedIndex: _highlightedIndex,
3720
3724
  isOpen: true
@@ -3722,20 +3726,23 @@
3722
3726
  }
3723
3727
  break;
3724
3728
  case ToggleButtonKeyDownArrowUp:
3725
- if (state.isOpen && altKey) {
3726
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
3727
- } else {
3728
- var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props, state, -1);
3729
- changes = {
3730
- highlightedIndex: _highlightedIndex2,
3731
- isOpen: true
3732
- };
3729
+ {
3730
+ var _altKey = action.altKey;
3731
+ if (state.isOpen && _altKey) {
3732
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
3733
+ } else {
3734
+ var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1);
3735
+ changes = {
3736
+ highlightedIndex: _highlightedIndex2,
3737
+ isOpen: true
3738
+ };
3739
+ }
3733
3740
  }
3734
3741
  break;
3735
3742
  // only triggered when menu is open.
3736
3743
  case ToggleButtonKeyDownEnter:
3737
3744
  case ToggleButtonKeyDownSpaceButton:
3738
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
3745
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
3739
3746
  break;
3740
3747
  case ToggleButtonKeyDownHome:
3741
3748
  changes = {
@@ -3769,7 +3776,7 @@
3769
3776
  changes = _extends({
3770
3777
  isOpen: false,
3771
3778
  highlightedIndex: -1
3772
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
3779
+ }, state.highlightedIndex >= 0 && props.items.length && {
3773
3780
  selectedItem: props.items[state.highlightedIndex]
3774
3781
  });
3775
3782
  break;
@@ -3785,59 +3792,9 @@
3785
3792
  }
3786
3793
  /* eslint-enable complexity */
3787
3794
 
3788
- // eslint-disable-next-line @typescript-eslint/dot-notation
3789
- var reactUseId$1 = React__namespace['useId'];
3790
- var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
3791
- function useElementIdsR18$1(_ref) {
3792
- var id = _ref.id,
3793
- labelId = _ref.labelId,
3794
- menuId = _ref.menuId,
3795
- getItemId = _ref.getItemId,
3796
- toggleButtonId = _ref.toggleButtonId,
3797
- inputId = _ref.inputId;
3798
- var reactId = "downshift-" + reactUseId$1();
3799
- if (!id) {
3800
- id = reactId;
3801
- }
3802
- var elementIds = React__namespace.useMemo(function () {
3803
- return {
3804
- labelId: labelId != null ? labelId : id + "-label",
3805
- menuId: menuId != null ? menuId : id + "-menu",
3806
- getItemId: getItemId != null ? getItemId : function (index) {
3807
- return id + "-item-" + index;
3808
- },
3809
- toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
3810
- inputId: inputId != null ? inputId : id + "-input"
3811
- };
3812
- }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
3813
- return elementIds;
3814
- }
3815
- function useElementIdsLegacy$1(_ref2) {
3816
- var id = _ref2.id,
3817
- labelId = _ref2.labelId,
3818
- menuId = _ref2.menuId,
3819
- getItemId = _ref2.getItemId,
3820
- toggleButtonId = _ref2.toggleButtonId,
3821
- inputId = _ref2.inputId;
3822
- var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
3823
- var baseId = baseIdRef.current;
3824
- var elementIds = React__namespace.useMemo(function () {
3825
- return {
3826
- labelId: labelId != null ? labelId : baseId + "-label",
3827
- menuId: menuId != null ? menuId : baseId + "-menu",
3828
- getItemId: getItemId != null ? getItemId : function (index) {
3829
- return baseId + "-item-" + index;
3830
- },
3831
- toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
3832
- inputId: inputId != null ? inputId : baseId + "-input"
3833
- };
3834
- }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
3835
- return elementIds;
3836
- }
3837
-
3838
3795
  var _excluded$3 = ["onClick"],
3839
- _excluded2$3 = ["onMouseLeave", "refKey", "ref"],
3840
- _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
3796
+ _excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
3797
+ _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
3841
3798
  _excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
3842
3799
  useSelect.stateChangeTypes = stateChangeTypes$3;
3843
3800
  function useSelect(userProps) {
@@ -3846,22 +3803,23 @@
3846
3803
  }
3847
3804
  validatePropTypes$1(userProps, useSelect, propTypes$3);
3848
3805
  // Props defaults and destructuring.
3849
- var props = _extends({}, defaultProps$2, userProps);
3806
+ var props = _extends({}, dropdownDefaultProps, userProps);
3850
3807
  var scrollIntoView = props.scrollIntoView,
3851
3808
  environment = props.environment,
3852
3809
  getA11yStatusMessage = props.getA11yStatusMessage;
3853
3810
  // Initial state depending on controlled props.
3854
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownsStateEqual),
3811
+ var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
3855
3812
  state = _useControlledReducer[0],
3856
3813
  dispatch = _useControlledReducer[1];
3857
3814
  var isOpen = state.isOpen,
3858
3815
  highlightedIndex = state.highlightedIndex,
3859
3816
  selectedItem = state.selectedItem,
3860
3817
  inputValue = state.inputValue;
3861
- // Element efs.
3818
+
3819
+ // Element refs.
3862
3820
  var toggleButtonRef = React.useRef(null);
3863
3821
  var menuRef = React.useRef(null);
3864
- var itemRefs = React.useRef({});
3822
+ var itemsRef = React.useRef({});
3865
3823
 
3866
3824
  // used to keep the inputValue clearTimeout object between renders.
3867
3825
  var clearTimeoutRef = React.useRef(null);
@@ -3873,24 +3831,12 @@
3873
3831
  props: props
3874
3832
  });
3875
3833
 
3876
- // Some utils.
3877
- var getItemNodeFromIndex = React.useCallback(function (index) {
3878
- return itemRefs.current[elementIds.getItemId(index)];
3879
- }, [elementIds]);
3880
-
3881
3834
  // Effects.
3882
3835
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
3883
3836
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
3884
3837
  // Scroll on highlighted item if change comes from keyboard.
3885
- var shouldScrollRef = useScrollIntoView({
3886
- menuElement: menuRef.current,
3887
- highlightedIndex: highlightedIndex,
3888
- isOpen: isOpen,
3889
- itemRefs: itemRefs,
3890
- scrollIntoView: scrollIntoView,
3891
- getItemNodeFromIndex: getItemNodeFromIndex
3892
- });
3893
- // Sets cleanup for the keysSoFar callback, debounded after 500ms.
3838
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
3839
+ // Sets cleanup for the keysSoFar callback, debounced after 500ms.
3894
3840
  React.useEffect(function () {
3895
3841
  // init the clean function here as we need access to dispatch.
3896
3842
  clearTimeoutRef.current = debounce(function (outerDispatch) {
@@ -3902,7 +3848,8 @@
3902
3848
 
3903
3849
  // Cancel any pending debounced calls on mount
3904
3850
  return function () {
3905
- clearTimeoutRef.current.cancel();
3851
+ var _clearTimeoutRef$curr;
3852
+ (_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
3906
3853
  };
3907
3854
  }, []);
3908
3855
  // Invokes the keysSoFar callback set up above.
@@ -3910,7 +3857,7 @@
3910
3857
  if (!inputValue) {
3911
3858
  return;
3912
3859
  }
3913
- clearTimeoutRef.current(dispatch);
3860
+ clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
3914
3861
  }, [dispatch, inputValue]);
3915
3862
  useControlPropsValidator({
3916
3863
  props: props,
@@ -3918,7 +3865,7 @@
3918
3865
  });
3919
3866
  // Focus the toggle button on first render if required.
3920
3867
  React.useEffect(function () {
3921
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
3868
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
3922
3869
  if (focusOnOpen && toggleButtonRef.current) {
3923
3870
  toggleButtonRef.current.focus();
3924
3871
  }
@@ -3939,7 +3886,7 @@
3939
3886
  // Reset itemRefs on close.
3940
3887
  React.useEffect(function () {
3941
3888
  if (!isOpen) {
3942
- itemRefs.current = {};
3889
+ itemsRef.current = {};
3943
3890
  }
3944
3891
  }, [isOpen]);
3945
3892
 
@@ -4024,50 +3971,11 @@
4024
3971
  };
4025
3972
  }, [dispatch, latest]);
4026
3973
 
4027
- // Action functions.
4028
- var toggleMenu = React.useCallback(function () {
4029
- dispatch({
4030
- type: FunctionToggleMenu$1
4031
- });
4032
- }, [dispatch]);
4033
- var closeMenu = React.useCallback(function () {
4034
- dispatch({
4035
- type: FunctionCloseMenu$1
4036
- });
4037
- }, [dispatch]);
4038
- var openMenu = React.useCallback(function () {
4039
- dispatch({
4040
- type: FunctionOpenMenu$1
4041
- });
4042
- }, [dispatch]);
4043
- var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
4044
- dispatch({
4045
- type: FunctionSetHighlightedIndex$1,
4046
- highlightedIndex: newHighlightedIndex
4047
- });
4048
- }, [dispatch]);
4049
- var selectItem = React.useCallback(function (newSelectedItem) {
4050
- dispatch({
4051
- type: FunctionSelectItem$1,
4052
- selectedItem: newSelectedItem
4053
- });
4054
- }, [dispatch]);
4055
- var reset = React.useCallback(function () {
4056
- dispatch({
4057
- type: FunctionReset$2
4058
- });
4059
- }, [dispatch]);
4060
- var setInputValue = React.useCallback(function (newInputValue) {
4061
- dispatch({
4062
- type: FunctionSetInputValue$1,
4063
- inputValue: newInputValue
4064
- });
4065
- }, [dispatch]);
4066
3974
  // Getter functions.
4067
- var getLabelProps = React.useCallback(function (_temp) {
4068
- var _ref = _temp === void 0 ? {} : _temp,
3975
+ var getLabelProps = React.useCallback(function (labelProps) {
3976
+ var _ref = labelProps != null ? labelProps : {},
4069
3977
  onClick = _ref.onClick,
4070
- labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
3978
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
4071
3979
  var labelHandleClick = function labelHandleClick() {
4072
3980
  var _toggleButtonRef$curr;
4073
3981
  (_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
@@ -4076,17 +3984,18 @@
4076
3984
  id: elementIds.labelId,
4077
3985
  htmlFor: elementIds.toggleButtonId,
4078
3986
  onClick: callAllEventHandlers(onClick, labelHandleClick)
4079
- }, labelProps);
3987
+ }, rest);
4080
3988
  }, [elementIds]);
4081
- var getMenuProps = React.useCallback(function (_temp2, _temp3) {
3989
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
4082
3990
  var _extends2;
4083
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3991
+ var _ref2 = menuProps != null ? menuProps : {},
4084
3992
  onMouseLeave = _ref2.onMouseLeave,
4085
3993
  _ref2$refKey = _ref2.refKey,
4086
3994
  refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
4087
3995
  ref = _ref2.ref,
3996
+ ariaLabel = _ref2['aria-label'],
4088
3997
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
4089
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3998
+ var _ref3 = otherProps != null ? otherProps : {},
4090
3999
  _ref3$suppressRefErro = _ref3.suppressRefError,
4091
4000
  suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
4092
4001
  var menuHandleMouseLeave = function menuHandleMouseLeave() {
@@ -4097,11 +4006,11 @@
4097
4006
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
4098
4007
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
4099
4008
  menuRef.current = menuNode;
4100
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
4009
+ }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
4101
4010
  }, [dispatch, setGetterPropCallInfo, elementIds]);
4102
- var getToggleButtonProps = React.useCallback(function (_temp4, _temp5) {
4011
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
4103
4012
  var _extends3;
4104
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
4013
+ var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
4105
4014
  onBlur = _ref4.onBlur,
4106
4015
  onClick = _ref4.onClick;
4107
4016
  _ref4.onPress;
@@ -4109,8 +4018,9 @@
4109
4018
  _ref4$refKey = _ref4.refKey,
4110
4019
  refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
4111
4020
  ref = _ref4.ref,
4021
+ disabled = _ref4.disabled,
4112
4022
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
4113
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
4023
+ var _ref5 = otherProps != null ? otherProps : {},
4114
4024
  _ref5$suppressRefErro = _ref5.suppressRefError,
4115
4025
  suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
4116
4026
  var latestState = latest.current.state;
@@ -4128,9 +4038,9 @@
4128
4038
  };
4129
4039
  var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
4130
4040
  var key = normalizeArrowKey(event);
4131
- if (key && toggleButtonKeyDownHandlers[key]) {
4041
+ if (key && key in toggleButtonKeyDownHandlers) {
4132
4042
  toggleButtonKeyDownHandlers[key](event);
4133
- } else if (isAcceptedCharacterKey(key)) {
4043
+ } else if (/^\S{1}$/.test(key)) {
4134
4044
  dispatch({
4135
4045
  type: ToggleButtonKeyDownCharacter,
4136
4046
  key: key
@@ -4139,20 +4049,22 @@
4139
4049
  };
4140
4050
  var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
4141
4051
  toggleButtonRef.current = toggleButtonNode;
4142
- }), _extends3['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends3['aria-controls'] = elementIds.menuId, _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3), rest);
4143
- if (!rest.disabled) {
4052
+ }), _extends3['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends3['aria-controls'] = elementIds.menuId, _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-labelledby'] = rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3.disabled = disabled, _extends3), rest);
4053
+ if (!disabled) {
4144
4054
  /* istanbul ignore if (react-native) */
4145
4055
  {
4146
- toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
4147
- toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
4056
+ Object.assign(toggleProps, {
4057
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick),
4058
+ onKeyDown: callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown)
4059
+ });
4148
4060
  }
4149
4061
  }
4150
4062
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
4151
4063
  return toggleProps;
4152
4064
  }, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
4153
- var getItemProps = React.useCallback(function (_temp6) {
4065
+ var getItemProps = React.useCallback(function (itemProps) {
4154
4066
  var _extends4;
4155
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
4067
+ var _ref6 = itemProps != null ? itemProps : {},
4156
4068
  itemProp = _ref6.item,
4157
4069
  indexProp = _ref6.index,
4158
4070
  onMouseMove = _ref6.onMouseMove,
@@ -4178,7 +4090,7 @@
4178
4090
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
4179
4091
  return;
4180
4092
  }
4181
- shouldScrollRef.current = false;
4093
+ preventScroll();
4182
4094
  dispatch({
4183
4095
  type: ItemMouseMove$1,
4184
4096
  index: index,
@@ -4195,21 +4107,61 @@
4195
4107
  return e.preventDefault();
4196
4108
  }; // keep focus on the toggle after item click select.
4197
4109
 
4198
- var itemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
4110
+ var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
4199
4111
  if (itemNode) {
4200
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
4112
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
4201
4113
  }
4202
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
4114
+ }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove), _extends4.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown), _extends4), rest);
4203
4115
  if (!disabled) {
4204
4116
  /* istanbul ignore next (react-native) */
4205
4117
  {
4206
- itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
4118
+ Object.assign(resultItemProps, {
4119
+ onClick: callAllEventHandlers(onClick, itemHandleClick)
4120
+ });
4207
4121
  }
4208
4122
  }
4209
- itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
4210
- itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
4211
- return itemProps;
4212
- }, [latest, elementIds, mouseAndTouchTrackers, shouldScrollRef, dispatch]);
4123
+ return resultItemProps;
4124
+ }, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
4125
+
4126
+ // Action functions.
4127
+ var toggleMenu = React.useCallback(function () {
4128
+ dispatch({
4129
+ type: FunctionToggleMenu$1
4130
+ });
4131
+ }, [dispatch]);
4132
+ var closeMenu = React.useCallback(function () {
4133
+ dispatch({
4134
+ type: FunctionCloseMenu$1
4135
+ });
4136
+ }, [dispatch]);
4137
+ var openMenu = React.useCallback(function () {
4138
+ dispatch({
4139
+ type: FunctionOpenMenu$1
4140
+ });
4141
+ }, [dispatch]);
4142
+ var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
4143
+ dispatch({
4144
+ type: FunctionSetHighlightedIndex$1,
4145
+ highlightedIndex: newHighlightedIndex
4146
+ });
4147
+ }, [dispatch]);
4148
+ var selectItem = React.useCallback(function (newSelectedItem) {
4149
+ dispatch({
4150
+ type: FunctionSelectItem$1,
4151
+ selectedItem: newSelectedItem
4152
+ });
4153
+ }, [dispatch]);
4154
+ var reset = React.useCallback(function () {
4155
+ dispatch({
4156
+ type: FunctionReset$2
4157
+ });
4158
+ }, [dispatch]);
4159
+ var setInputValue = React.useCallback(function (newInputValue) {
4160
+ dispatch({
4161
+ type: FunctionSetInputValue$1,
4162
+ inputValue: newInputValue
4163
+ });
4164
+ }, [dispatch]);
4213
4165
  return {
4214
4166
  // prop getters.
4215
4167
  getToggleButtonProps: getToggleButtonProps,
@@ -4232,6 +4184,18 @@
4232
4184
  };
4233
4185
  }
4234
4186
 
4187
+ function getInitialState$2(props) {
4188
+ var initialState = getInitialState$3(props);
4189
+ var selectedItem = initialState.selectedItem;
4190
+ var inputValue = initialState.inputValue;
4191
+ if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
4192
+ inputValue = props.itemToString(selectedItem);
4193
+ }
4194
+ return _extends({}, initialState, {
4195
+ inputValue: inputValue
4196
+ });
4197
+ }
4198
+
4235
4199
  var InputKeyDownArrowDown = '__input_keydown_arrow_down__' ;
4236
4200
  var InputKeyDownArrowUp = '__input_keydown_arrow_up__' ;
4237
4201
  var InputKeyDownEscape = '__input_keydown_escape__' ;
@@ -4283,27 +4247,6 @@
4283
4247
  ToggleButtonClick: ToggleButtonClick
4284
4248
  });
4285
4249
 
4286
- function getInitialState$2(props) {
4287
- var initialState = getInitialState$3(props);
4288
- var selectedItem = initialState.selectedItem;
4289
- var inputValue = initialState.inputValue;
4290
- if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
4291
- inputValue = props.itemToString(selectedItem);
4292
- }
4293
- return _extends({}, initialState, {
4294
- inputValue: inputValue
4295
- });
4296
- }
4297
- var propTypes$2 = _extends({}, propTypes$4, {
4298
- items: PropTypes.array.isRequired,
4299
- isItemDisabled: PropTypes.func,
4300
- inputValue: PropTypes.string,
4301
- defaultInputValue: PropTypes.string,
4302
- initialInputValue: PropTypes.string,
4303
- inputId: PropTypes.string,
4304
- onInputValueChange: PropTypes.func
4305
- });
4306
-
4307
4250
  /**
4308
4251
  * The useCombobox version of useControlledReducer, which also
4309
4252
  * checks if the controlled prop selectedItem changed between
@@ -4311,20 +4254,20 @@
4311
4254
  * string equivalent. It uses the common useEnhancedReducer to
4312
4255
  * compute the rest of the state.
4313
4256
  *
4314
- * @param {Function} reducer Reducer function from downshift.
4315
- * @param {Object} props The hook props, also passed to createInitialState.
4316
- * @param {Function} createInitialState Function that returns the initial state.
4317
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
4318
- * @returns {Array} An array with the state and an action dispatcher.
4257
+ * @param reducer Reducer function from downshift.
4258
+ * @param props The hook props, also passed to createInitialState.
4259
+ * @param createInitialState Function that returns the initial state.
4260
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
4261
+ * @returns An array with the state and an action dispatcher.
4319
4262
  */
4320
4263
  function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
4321
- var previousSelectedItemRef = React.useRef();
4264
+ var previousSelectedItemRef = React.useRef(null);
4322
4265
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
4323
4266
  state = _useEnhancedReducer[0],
4324
4267
  dispatch = _useEnhancedReducer[1];
4325
4268
  var isInitialMount = useIsInitialMount();
4326
4269
  React.useEffect(function () {
4327
- if (!isControlledProp(props, 'selectedItem')) {
4270
+ if (props.selectedItem === undefined) {
4328
4271
  return;
4329
4272
  }
4330
4273
  if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
@@ -4342,23 +4285,27 @@
4342
4285
  }, [state.selectedItem, props.selectedItem]);
4343
4286
  return [getState(state, props), dispatch];
4344
4287
  }
4345
- var defaultProps$1 = _extends({}, defaultProps$3, {
4346
- isItemDisabled: function isItemDisabled() {
4347
- return false;
4348
- }
4288
+
4289
+ var propTypes$2 = _extends({}, dropdownPropTypes, {
4290
+ items: PropTypes.array.isRequired,
4291
+ isItemDisabled: PropTypes.func,
4292
+ inputValue: PropTypes.string,
4293
+ defaultInputValue: PropTypes.string,
4294
+ initialInputValue: PropTypes.string,
4295
+ inputId: PropTypes.string,
4296
+ onInputValueChange: PropTypes.func
4349
4297
  });
4350
4298
 
4351
4299
  /* eslint-disable complexity */
4352
- function downshiftUseComboboxReducer(state, props, action) {
4353
- var _props$items;
4300
+ function downshiftUseComboboxReducer(state, action) {
4354
4301
  var type = action.type,
4355
- altKey = action.altKey;
4302
+ props = action.props;
4356
4303
  var changes;
4357
4304
  switch (type) {
4358
4305
  case ItemClick:
4359
4306
  changes = {
4360
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
4361
- highlightedIndex: getDefaultHighlightedIndex(props),
4307
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
4308
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
4362
4309
  selectedItem: props.items[action.index],
4363
4310
  inputValue: props.itemToString(props.items[action.index])
4364
4311
  };
@@ -4370,15 +4317,15 @@
4370
4317
  };
4371
4318
  } else {
4372
4319
  changes = {
4373
- highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
4320
+ highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
4374
4321
  isOpen: props.items.length >= 0
4375
4322
  };
4376
4323
  }
4377
4324
  break;
4378
4325
  case InputKeyDownArrowUp:
4379
4326
  if (state.isOpen) {
4380
- if (altKey) {
4381
- changes = getChangesOnSelection(props, state.highlightedIndex);
4327
+ if (action.altKey) {
4328
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
4382
4329
  } else {
4383
4330
  changes = {
4384
4331
  highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
@@ -4386,13 +4333,13 @@
4386
4333
  }
4387
4334
  } else {
4388
4335
  changes = {
4389
- highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
4336
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
4390
4337
  isOpen: props.items.length >= 0
4391
4338
  };
4392
4339
  }
4393
4340
  break;
4394
4341
  case InputKeyDownEnter:
4395
- changes = getChangesOnSelection(props, state.highlightedIndex);
4342
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
4396
4343
  break;
4397
4344
  case InputKeyDownEscape:
4398
4345
  changes = _extends({
@@ -4427,7 +4374,7 @@
4427
4374
  changes = _extends({
4428
4375
  isOpen: false,
4429
4376
  highlightedIndex: -1
4430
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
4377
+ }, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
4431
4378
  selectedItem: props.items[state.highlightedIndex],
4432
4379
  inputValue: props.itemToString(props.items[state.highlightedIndex])
4433
4380
  });
@@ -4435,14 +4382,14 @@
4435
4382
  case InputChange:
4436
4383
  changes = {
4437
4384
  isOpen: true,
4438
- highlightedIndex: getDefaultHighlightedIndex(props),
4385
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
4439
4386
  inputValue: action.inputValue
4440
4387
  };
4441
4388
  break;
4442
4389
  case InputClick:
4443
4390
  changes = {
4444
4391
  isOpen: !state.isOpen,
4445
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
4392
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
4446
4393
  };
4447
4394
  break;
4448
4395
  case FunctionSelectItem:
@@ -4463,10 +4410,10 @@
4463
4410
  }
4464
4411
  /* eslint-enable complexity */
4465
4412
 
4466
- var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
4413
+ var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
4467
4414
  _excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
4468
- _excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
4469
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
4415
+ _excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
4416
+ _excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
4470
4417
  useCombobox.stateChangeTypes = stateChangeTypes$2;
4471
4418
  function useCombobox(userProps) {
4472
4419
  if (userProps === void 0) {
@@ -4474,13 +4421,13 @@
4474
4421
  }
4475
4422
  validatePropTypes$1(userProps, useCombobox, propTypes$2);
4476
4423
  // Props defaults and destructuring.
4477
- var props = _extends({}, defaultProps$1, userProps);
4424
+ var props = _extends({}, dropdownDefaultProps, userProps);
4478
4425
  var items = props.items,
4479
4426
  scrollIntoView = props.scrollIntoView,
4480
4427
  environment = props.environment,
4481
4428
  getA11yStatusMessage = props.getA11yStatusMessage;
4482
4429
  // Initial state depending on controlled props.
4483
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownsStateEqual),
4430
+ var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
4484
4431
  state = _useControlledReducer[0],
4485
4432
  dispatch = _useControlledReducer[1];
4486
4433
  var isOpen = state.isOpen,
@@ -4490,7 +4437,7 @@
4490
4437
 
4491
4438
  // Element refs.
4492
4439
  var menuRef = React.useRef(null);
4493
- var itemRefs = React.useRef({});
4440
+ var itemsRef = React.useRef({});
4494
4441
  var inputRef = React.useRef(null);
4495
4442
  var toggleButtonRef = React.useRef(null);
4496
4443
  var isInitialMount = useIsInitialMount();
@@ -4504,29 +4451,19 @@
4504
4451
  state: state,
4505
4452
  props: props
4506
4453
  });
4507
- var getItemNodeFromIndex = React.useCallback(function (index) {
4508
- return itemRefs.current[elementIds.getItemId(index)];
4509
- }, [elementIds]);
4510
4454
 
4511
4455
  // Effects.
4512
4456
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
4513
4457
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
4514
4458
  // Scroll on highlighted item if change comes from keyboard.
4515
- var shouldScrollRef = useScrollIntoView({
4516
- menuElement: menuRef.current,
4517
- highlightedIndex: highlightedIndex,
4518
- isOpen: isOpen,
4519
- itemRefs: itemRefs,
4520
- scrollIntoView: scrollIntoView,
4521
- getItemNodeFromIndex: getItemNodeFromIndex
4522
- });
4459
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
4523
4460
  useControlPropsValidator({
4524
- props: props,
4525
- state: state
4461
+ state: state,
4462
+ props: props
4526
4463
  });
4527
4464
  // Focus the input on first render if required.
4528
4465
  React.useEffect(function () {
4529
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
4466
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
4530
4467
  if (focusOnOpen && inputRef.current) {
4531
4468
  inputRef.current.focus();
4532
4469
  }
@@ -4552,13 +4489,13 @@
4552
4489
  // Reset itemRefs on close.
4553
4490
  React.useEffect(function () {
4554
4491
  if (!isOpen) {
4555
- itemRefs.current = {};
4492
+ itemsRef.current = {};
4556
4493
  }
4557
4494
  }, [isOpen]);
4558
4495
  // Reset itemRefs on close.
4559
4496
  React.useEffect(function () {
4560
4497
  var _inputRef$current;
4561
- if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
4498
+ if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
4562
4499
  return;
4563
4500
  }
4564
4501
  if (environment.document.activeElement !== inputRef.current) {
@@ -4648,29 +4585,30 @@
4648
4585
  htmlFor: elementIds.inputId
4649
4586
  }, labelProps);
4650
4587
  }, [elementIds]);
4651
- var getMenuProps = React.useCallback(function (_temp, _temp2) {
4588
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
4652
4589
  var _extends2;
4653
- var _ref = _temp === void 0 ? {} : _temp,
4590
+ var _ref = menuProps != null ? menuProps : {},
4654
4591
  onMouseLeave = _ref.onMouseLeave,
4655
4592
  _ref$refKey = _ref.refKey,
4656
4593
  refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
4657
4594
  ref = _ref.ref,
4595
+ ariaLabel = _ref['aria-label'],
4658
4596
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
4659
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
4597
+ var _ref2 = otherProps != null ? otherProps : {},
4660
4598
  _ref2$suppressRefErro = _ref2.suppressRefError,
4661
4599
  suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
4662
4600
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
4663
4601
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
4664
4602
  menuRef.current = menuNode;
4665
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
4603
+ }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
4666
4604
  dispatch({
4667
4605
  type: MenuMouseLeave
4668
4606
  });
4669
4607
  }), _extends2), rest);
4670
4608
  }, [dispatch, setGetterPropCallInfo, elementIds]);
4671
- var getItemProps = React.useCallback(function (_temp3) {
4609
+ var getItemProps = React.useCallback(function (itemProps) {
4672
4610
  var _extends3, _ref4;
4673
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
4611
+ var _ref3 = itemProps != null ? itemProps : {},
4674
4612
  itemProp = _ref3.item,
4675
4613
  indexProp = _ref3.index,
4676
4614
  _ref3$refKey = _ref3.refKey,
@@ -4698,7 +4636,7 @@
4698
4636
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
4699
4637
  return;
4700
4638
  }
4701
- shouldScrollRef.current = false;
4639
+ preventScroll();
4702
4640
  dispatch({
4703
4641
  type: ItemMouseMove,
4704
4642
  index: index,
@@ -4717,21 +4655,22 @@
4717
4655
 
4718
4656
  return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
4719
4657
  if (itemNode) {
4720
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
4658
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
4721
4659
  }
4722
4660
  }), _extends3['aria-disabled'] = disabled, _extends3['aria-selected'] = index === latestState.highlightedIndex, _extends3.id = elementIds.getItemId(index), _extends3.role = 'option', _extends3), !disabled && (_ref4 = {}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), {
4723
4661
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
4724
4662
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
4725
4663
  }, rest);
4726
- }, [dispatch, elementIds, latest, mouseAndTouchTrackers, shouldScrollRef]);
4727
- var getToggleButtonProps = React.useCallback(function (_temp4) {
4664
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
4665
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
4728
4666
  var _extends4;
4729
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
4667
+ var _ref5 = toggleButtonProps != null ? toggleButtonProps : {},
4730
4668
  onClick = _ref5.onClick;
4731
4669
  _ref5.onPress;
4732
4670
  var _ref5$refKey = _ref5.refKey,
4733
4671
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
4734
4672
  ref = _ref5.ref,
4673
+ disabled = _ref5.disabled,
4735
4674
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
4736
4675
  var latestState = latest.current.state;
4737
4676
  var toggleButtonHandleClick = function toggleButtonHandleClick() {
@@ -4741,13 +4680,17 @@
4741
4680
  };
4742
4681
  return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
4743
4682
  toggleButtonRef.current = toggleButtonNode;
4744
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
4683
+ }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, {
4745
4684
  onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
4746
- }), rest);
4685
+ }), {
4686
+ disabled: disabled
4687
+ }, rest);
4747
4688
  }, [dispatch, latest, elementIds]);
4748
- var getInputProps = React.useCallback(function (_temp5, _temp6) {
4689
+ var getInputProps = React.useCallback(function (inputProps, otherProps) {
4749
4690
  var _extends5;
4750
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
4691
+ var _ref6 = inputProps != null ? inputProps : {},
4692
+ ariaLabel = _ref6['aria-label'],
4693
+ disabled = _ref6.disabled,
4751
4694
  onKeyDown = _ref6.onKeyDown,
4752
4695
  onChange = _ref6.onChange,
4753
4696
  onInput = _ref6.onInput,
@@ -4758,15 +4701,16 @@
4758
4701
  refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
4759
4702
  ref = _ref6.ref,
4760
4703
  rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
4761
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
4704
+ var _ref7 = otherProps != null ? otherProps : {},
4762
4705
  _ref7$suppressRefErro = _ref7.suppressRefError,
4763
4706
  suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
4764
4707
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
4765
4708
  var latestState = latest.current.state;
4766
4709
  var inputHandleKeyDown = function inputHandleKeyDown(event) {
4767
4710
  var key = normalizeArrowKey(event);
4768
- if (key && inputKeyDownHandlers[key]) {
4769
- inputKeyDownHandlers[key](event);
4711
+ if (key && key in inputKeyDownHandlers) {
4712
+ var validKey = key;
4713
+ inputKeyDownHandlers[validKey](event);
4770
4714
  }
4771
4715
  };
4772
4716
  var inputHandleChange = function inputHandleChange(event) {
@@ -4794,13 +4738,13 @@
4794
4738
  /* istanbul ignore next (preact) */
4795
4739
  var onChangeKey = 'onChange';
4796
4740
  var eventHandlers = {};
4797
- if (!rest.disabled) {
4741
+ if (!disabled) {
4798
4742
  var _eventHandlers;
4799
4743
  eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
4800
4744
  }
4801
4745
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
4802
4746
  inputRef.current = inputNode;
4803
- }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = rest && rest['aria-label'] ? undefined : elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
4747
+ }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = ariaLabel ? undefined : elementIds.labelId, _extends5['aria-label'] = ariaLabel, _extends5.autoComplete = 'off', _extends5.disabled = disabled, _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
4804
4748
  }, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
4805
4749
 
4806
4750
  // returns
@@ -4870,31 +4814,6 @@
4870
4814
  selectedItems: []
4871
4815
  };
4872
4816
 
4873
- /**
4874
- * Returns the initial value for a state key in the following order:
4875
- * 1. controlled prop, 2. initial prop, 3. default prop, 4. default
4876
- * value from Downshift.
4877
- *
4878
- * @param {Object} props Props passed to the hook.
4879
- * @param {string} propKey Props key to generate the value for.
4880
- * @returns {any} The initial value for that prop.
4881
- */
4882
- function getInitialValue(props, propKey) {
4883
- return getInitialValue$1(props, propKey, defaultStateValues);
4884
- }
4885
-
4886
- /**
4887
- * Returns the default value for a state key in the following order:
4888
- * 1. controlled prop, 2. default prop, 3. default value from Downshift.
4889
- *
4890
- * @param {Object} props Props passed to the hook.
4891
- * @param {string} propKey Props key to generate the value for.
4892
- * @returns {any} The initial value for that prop.
4893
- */
4894
- function getDefaultValue(props, propKey) {
4895
- return getDefaultValue$1(props, propKey, defaultStateValues);
4896
- }
4897
-
4898
4817
  /**
4899
4818
  * Gets the initial state based on the provided props. It uses initial, default
4900
4819
  * and controlled props related to state in order to compute the initial value.
@@ -4903,8 +4822,8 @@
4903
4822
  * @returns {Object} The initial state.
4904
4823
  */
4905
4824
  function getInitialState$1(props) {
4906
- var activeIndex = getInitialValue(props, 'activeIndex');
4907
- var selectedItems = getInitialValue(props, 'selectedItems');
4825
+ var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
4826
+ var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
4908
4827
  return {
4909
4828
  activeIndex: activeIndex,
4910
4829
  selectedItems: selectedItems
@@ -4948,9 +4867,9 @@
4948
4867
  return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
4949
4868
  }
4950
4869
  var propTypes$1 = {
4951
- stateReducer: propTypes$4.stateReducer,
4952
- itemToKey: propTypes$4.itemToKey,
4953
- environment: propTypes$4.environment,
4870
+ stateReducer: dropdownPropTypes.stateReducer,
4871
+ itemToKey: dropdownPropTypes.itemToKey,
4872
+ environment: dropdownPropTypes.environment,
4954
4873
  selectedItems: PropTypes.array,
4955
4874
  initialSelectedItems: PropTypes.array,
4956
4875
  defaultSelectedItems: PropTypes.array,
@@ -4964,9 +4883,9 @@
4964
4883
  keyNavigationPrevious: PropTypes.string
4965
4884
  };
4966
4885
  var defaultProps = {
4967
- itemToKey: defaultProps$3.itemToKey,
4968
- stateReducer: defaultProps$3.stateReducer,
4969
- environment: defaultProps$3.environment,
4886
+ itemToKey: dropdownDefaultProps.itemToKey,
4887
+ stateReducer: dropdownDefaultProps.stateReducer,
4888
+ environment: dropdownDefaultProps.environment,
4970
4889
  keyNavigationNext: 'ArrowRight',
4971
4890
  keyNavigationPrevious: 'ArrowLeft'
4972
4891
  };
@@ -5012,10 +4931,11 @@
5012
4931
  });
5013
4932
 
5014
4933
  /* eslint-disable complexity */
5015
- function downshiftMultipleSelectionReducer(state, props, action) {
4934
+ function downshiftMultipleSelectionReducer(state, action) {
5016
4935
  var type = action.type,
5017
4936
  index = action.index,
5018
- selectedItem = action.selectedItem;
4937
+ selectedItem = action.selectedItem,
4938
+ props = action.props;
5019
4939
  var activeIndex = state.activeIndex,
5020
4940
  selectedItems = state.selectedItems;
5021
4941
  var changes;
@@ -5112,8 +5032,8 @@
5112
5032
  }
5113
5033
  case FunctionReset:
5114
5034
  changes = {
5115
- activeIndex: getDefaultValue(props, 'activeIndex'),
5116
- selectedItems: getDefaultValue(props, 'selectedItems')
5035
+ activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
5036
+ selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
5117
5037
  };
5118
5038
  break;
5119
5039
  default:
@@ -5345,7 +5265,7 @@
5345
5265
  TagRemoveClick: TagRemoveClick
5346
5266
  });
5347
5267
 
5348
- function useTagGroupReducer(state, _props, action) {
5268
+ function useTagGroupReducer(state, action) {
5349
5269
  var type = action.type;
5350
5270
  var changes;
5351
5271
  switch (type) {
@@ -5406,8 +5326,9 @@
5406
5326
  return _extends({}, state, changes);
5407
5327
  }
5408
5328
 
5409
- // eslint-disable-next-line @typescript-eslint/dot-notation
5410
- var reactUseId = React__namespace['useId'];
5329
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
5330
+ var SafeReact = _extends({}, React__namespace);
5331
+ var reactUseId = SafeReact.useId;
5411
5332
 
5412
5333
  // istanbul ignore next
5413
5334
  var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
@@ -5582,7 +5503,7 @@
5582
5503
  'aria-atomic': 'false',
5583
5504
  'aria-relevant': 'additions',
5584
5505
  role: 'listbox',
5585
- onKeyDown: callAllEventHandlers$1(onKeyDown, handleKeyDown)
5506
+ onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
5586
5507
  }, rest);
5587
5508
  return tagGroupProps;
5588
5509
  }, [dispatch, elementIds.tagGroupId]);
@@ -5607,11 +5528,11 @@
5607
5528
  var tagId = elementIds.getTagId(index);
5608
5529
  return _extends((_extends2 = {
5609
5530
  'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
5610
- }, _extends2[refKey] = handleRefs$1(ref, function (itemNode) {
5531
+ }, _extends2[refKey] = handleRefs(ref, function (itemNode) {
5611
5532
  if (itemNode) {
5612
5533
  itemRefs.current[tagId] = itemNode;
5613
5534
  }
5614
- }), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers$1(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
5535
+ }), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
5615
5536
  }, [dispatch, elementIds, latest, itemRefs]);
5616
5537
  var getTagRemoveProps = React.useCallback(function (options) {
5617
5538
  var index = options.index,
@@ -5633,7 +5554,7 @@
5633
5554
  id: tagRemoveId,
5634
5555
  tabIndex: -1,
5635
5556
  'aria-labelledby': tagRemoveId + " " + tagId,
5636
- onClick: callAllEventHandlers$1(onClick, handleClick)
5557
+ onClick: callAllEventHandlers(onClick, handleClick)
5637
5558
  }, rest);
5638
5559
  }, [elementIds, dispatch]);
5639
5560