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
@@ -370,7 +370,7 @@
370
370
  return ref;
371
371
  }
372
372
 
373
- function handleRefs$1() {
373
+ function handleRefs() {
374
374
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
375
375
  refs[_key] = arguments[_key];
376
376
  }
@@ -392,7 +392,7 @@
392
392
  * @param fns the event handler functions
393
393
  * @return the event handler to add to an element
394
394
  */
395
- function callAllEventHandlers$1() {
395
+ function callAllEventHandlers() {
396
396
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
397
397
  fns[_key] = arguments[_key];
398
398
  }
@@ -414,7 +414,7 @@
414
414
  * function once after the time given has passed since
415
415
  * it was last called.
416
416
  */
417
- function debounce$1(fn, time) {
417
+ function debounce(fn, time) {
418
418
  var timeoutId;
419
419
  function cancel() {
420
420
  if (timeoutId) {
@@ -435,7 +435,7 @@
435
435
  return wrapper;
436
436
  }
437
437
 
438
- var cleanupStatus = debounce$1(function (document) {
438
+ var cleanupStatus = debounce(function (document) {
439
439
  getStatusDiv(document).textContent = '';
440
440
  }, 500);
441
441
 
@@ -516,6 +516,8 @@
516
516
  }
517
517
  var keys = Object.keys(state);
518
518
  return keys.reduce(function (newState, key) {
519
+ // state keys could be in props, but with value undefined, which means they should be ignored.
520
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
519
521
  if (props[key] !== undefined) {
520
522
  newState[key] = props[key];
521
523
  }
@@ -546,93 +548,149 @@
546
548
  }
547
549
 
548
550
  /**
549
- * Accepts a parameter and returns it if it's a function
550
- * or a noop function if it's not. This allows us to
551
- * accept a callback, but not worry about it if it's not
552
- * passed.
553
- * @param {Function} cb the callback
554
- * @return {Function} a function
555
- */
556
- function cbToCb(cb) {
557
- return typeof cb === 'function' ? cb : noop;
558
- }
559
-
560
- /**
561
- * @param {HTMLElement} parent the parent node
562
- * @param {HTMLElement} child the child node
563
- * @param {Window} environment The window context where downshift renders.
564
- * @return {Boolean} whether the parent is the child or the child is in the parent
551
+ * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
552
+ * @param event a keyboardEvent object
553
+ * @return keyboard key
565
554
  */
566
- function isOrContainsNode(parent, child, environment) {
567
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
568
- return result;
555
+ function normalizeArrowKey(event) {
556
+ var key = event.key,
557
+ keyCode = event.keyCode;
558
+ /* istanbul ignore next (ie) */
559
+ if (keyCode >= 37 && keyCode <= 40 && !key.startsWith('Arrow')) {
560
+ return "Arrow" + key;
561
+ }
562
+ return key;
569
563
  }
570
564
 
571
565
  /**
572
- * Simple debounce implementation. Will call the given
573
- * function once after the time given has passed since
574
- * it was last called.
575
- * @param {Function} fn the function to call after the time
576
- * @param {Number} time the time to wait
577
- * @return {Function} the debounced function
566
+ * Returns the next non-disabled highlightedIndex value.
567
+ *
568
+ * @param start The current highlightedIndex.
569
+ * @param backwards If true, it will search backwards from the start.
570
+ * @param items The items array.
571
+ * @param isItemDisabled Function that tells if an item is disabled or not.
572
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
573
+ * @returns The next non-disabled index.
578
574
  */
579
- function debounce(fn, time) {
580
- var timeoutId;
581
- function cancel() {
582
- if (timeoutId) {
583
- clearTimeout(timeoutId);
584
- }
575
+ function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
576
+ if (circular === void 0) {
577
+ circular = false;
585
578
  }
586
- function wrapper() {
587
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
588
- args[_key] = arguments[_key];
579
+ var count = items.length;
580
+ if (backwards) {
581
+ for (var index = start; index >= 0; index--) {
582
+ if (!isItemDisabled(items[index], index)) {
583
+ return index;
584
+ }
585
+ }
586
+ } else {
587
+ for (var _index = start; _index < count; _index++) {
588
+ if (!isItemDisabled(items[_index], _index)) {
589
+ return _index;
590
+ }
589
591
  }
590
- cancel();
591
- timeoutId = setTimeout(function () {
592
- timeoutId = null;
593
- fn.apply(void 0, args);
594
- }, time);
595
592
  }
596
- wrapper.cancel = cancel;
597
- return wrapper;
593
+ if (circular) {
594
+ return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
595
+ }
596
+ return -1;
598
597
  }
599
598
 
600
599
  /**
601
- * This is intended to be used to compose event handlers.
602
- * They are executed in order until one of them sets
603
- * `event.preventDownshiftDefault = true`.
604
- * @param {...Function} fns the event handler functions
605
- * @return {Function} the event handler to add to an element
600
+ * Returns the next non-disabled highlightedIndex value.
601
+ *
602
+ * @param start The current highlightedIndex.
603
+ * @param offset The offset from the current highlightedIndex to start searching.
604
+ * @param items The items array.
605
+ * @param isItemDisabled Function that tells if an item is disabled or not.
606
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
607
+ * @returns The next highlightedIndex.
606
608
  */
607
- function callAllEventHandlers() {
608
- for (var _len2 = arguments.length, fns = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
609
- fns[_key2] = arguments[_key2];
609
+ function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
610
+ if (circular === void 0) {
611
+ circular = false;
610
612
  }
611
- return function (event) {
612
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
613
- args[_key3 - 1] = arguments[_key3];
614
- }
615
- return fns.some(function (fn) {
616
- if (fn) {
617
- fn.apply(void 0, [event].concat(args));
613
+ var count = items.length;
614
+ if (count === 0) {
615
+ return -1;
616
+ }
617
+ var itemsLastIndex = count - 1;
618
+ if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
619
+ start = offset > 0 ? -1 : itemsLastIndex + 1;
620
+ }
621
+ var current = start + offset;
622
+ if (current < 0) {
623
+ current = circular ? itemsLastIndex : 0;
624
+ } else if (current > itemsLastIndex) {
625
+ current = circular ? 0 : itemsLastIndex;
626
+ }
627
+ var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
628
+ if (highlightedIndex === -1) {
629
+ return start >= count ? -1 : start;
630
+ }
631
+ return highlightedIndex;
632
+ }
633
+
634
+ /* eslint-disable @typescript-eslint/no-explicit-any */
635
+
636
+ // eslint-disable-next-line import/no-mutable-exports
637
+ var validateControlledUnchanged = noop;
638
+ /* istanbul ignore next */
639
+ {
640
+ validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
641
+ 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";
642
+ Object.keys(state).forEach(function (propKey) {
643
+ if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
644
+ // eslint-disable-next-line no-console
645
+ console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
646
+ } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
647
+ // eslint-disable-next-line no-console
648
+ console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
618
649
  }
619
- return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
620
650
  });
621
651
  };
622
652
  }
623
- function handleRefs() {
624
- for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
625
- refs[_key4] = arguments[_key4];
653
+
654
+ /**
655
+ * Checks if event target is within the downshift elements.
656
+ *
657
+ * @param target Target to check.
658
+ * @param downshiftElements The elements that form downshift (list, toggle button etc).
659
+ * @param environment The window context where downshift renders.
660
+ * @param checkActiveElement Whether to also check activeElement.
661
+ *
662
+ * @returns Whether or not the target is within downshift elements.
663
+ */
664
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
665
+ if (checkActiveElement === void 0) {
666
+ checkActiveElement = true;
626
667
  }
627
- return function (node) {
628
- refs.forEach(function (ref) {
629
- if (typeof ref === 'function') {
630
- ref(node);
631
- } else if (ref) {
632
- ref.current = node;
633
- }
634
- });
635
- };
668
+ return !!environment && downshiftElements.some(function (contextNode) {
669
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
670
+ });
671
+ }
672
+
673
+ /**
674
+ * @param parent the parent node
675
+ * @param child the child node
676
+ * @param environment The window context where downshift renders.
677
+ * @return Whether the parent is the child or the child is in the parent
678
+ */
679
+ function isOrContainsNode(parent, child, environment) {
680
+ var result = parent === child || child instanceof environment.Node && parent.contains(child);
681
+ return result;
682
+ }
683
+
684
+ /**
685
+ * Accepts a parameter and returns it if it's a function
686
+ * or a noop function if it's not. This allows us to
687
+ * accept a callback, but not worry about it if it's not
688
+ * passed.
689
+ * @param {Function} cb the callback
690
+ * @return {Function} a function
691
+ */
692
+ function cbToCb(cb) {
693
+ return typeof cb === 'function' ? cb : noop;
636
694
  }
637
695
 
638
696
  /**
@@ -728,34 +786,6 @@
728
786
  return result;
729
787
  }
730
788
 
731
- /**
732
- * This determines whether a prop is a "controlled prop" meaning it is
733
- * state which is controlled by the outside of this component rather
734
- * than within this component.
735
- *
736
- * @param {Object} props The props that may contain controlled values.
737
- * @param {String} key the key to check
738
- * @return {Boolean} whether it is a controlled controlled prop
739
- */
740
- function isControlledProp(props, key) {
741
- return props[key] !== undefined;
742
- }
743
-
744
- /**
745
- * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
746
- * @param {Object} event a keyboardEvent object
747
- * @return {String} keyboard key
748
- */
749
- function normalizeArrowKey(event) {
750
- var key = event.key,
751
- keyCode = event.keyCode;
752
- /* istanbul ignore next (ie) */
753
- if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
754
- return "Arrow" + key;
755
- }
756
- return key;
757
- }
758
-
759
789
  /**
760
790
  * Simple check if the value passed is object literal
761
791
  * @param {*} obj any things
@@ -765,112 +795,6 @@
765
795
  return Object.prototype.toString.call(obj) === '[object Object]';
766
796
  }
767
797
 
768
- /**
769
- * Returns the next non-disabled highlightedIndex value.
770
- *
771
- * @param {number} start The current highlightedIndex.
772
- * @param {number} offset The offset from the current highlightedIndex to start searching.
773
- * @param {unknown[]} items The items array.
774
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
775
- * @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
776
- * @returns {number} The next highlightedIndex.
777
- */
778
- function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
779
- if (circular === void 0) {
780
- circular = false;
781
- }
782
- var count = items.length;
783
- if (count === 0) {
784
- return -1;
785
- }
786
- var itemsLastIndex = count - 1;
787
- if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
788
- start = offset > 0 ? -1 : itemsLastIndex + 1;
789
- }
790
- var current = start + offset;
791
- if (current < 0) {
792
- current = circular ? itemsLastIndex : 0;
793
- } else if (current > itemsLastIndex) {
794
- current = circular ? 0 : itemsLastIndex;
795
- }
796
- var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
797
- if (highlightedIndex === -1) {
798
- return start >= count ? -1 : start;
799
- }
800
- return highlightedIndex;
801
- }
802
-
803
- /**
804
- * Returns the next non-disabled highlightedIndex value.
805
- *
806
- * @param {number} start The current highlightedIndex.
807
- * @param {boolean} backwards If true, it will search backwards from the start.
808
- * @param {unknown[]} items The items array.
809
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
810
- * @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
811
- * @returns {number} The next non-disabled index.
812
- */
813
- function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
814
- if (circular === void 0) {
815
- circular = false;
816
- }
817
- var count = items.length;
818
- if (backwards) {
819
- for (var index = start; index >= 0; index--) {
820
- if (!isItemDisabled(items[index], index)) {
821
- return index;
822
- }
823
- }
824
- } else {
825
- for (var _index = start; _index < count; _index++) {
826
- if (!isItemDisabled(items[_index], _index)) {
827
- return _index;
828
- }
829
- }
830
- }
831
- if (circular) {
832
- return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
833
- }
834
- return -1;
835
- }
836
-
837
- /**
838
- * Checks if event target is within the downshift elements.
839
- *
840
- * @param {EventTarget} target Target to check.
841
- * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
842
- * @param {Window} environment The window context where downshift renders.
843
- * @param {boolean} checkActiveElement Whether to also check activeElement.
844
- *
845
- * @returns {boolean} Whether or not the target is within downshift elements.
846
- */
847
- function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
848
- if (checkActiveElement === void 0) {
849
- checkActiveElement = true;
850
- }
851
- return environment && downshiftElements.some(function (contextNode) {
852
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
853
- });
854
- }
855
-
856
- // eslint-disable-next-line import/no-mutable-exports
857
- var validateControlledUnchanged = noop;
858
- /* istanbul ignore next */
859
- {
860
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
861
- 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";
862
- Object.keys(state).forEach(function (propKey) {
863
- if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
864
- // eslint-disable-next-line no-console
865
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
866
- } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
867
- // eslint-disable-next-line no-console
868
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
869
- }
870
- });
871
- };
872
- }
873
-
874
798
  var _excluded$4 = ["refKey", "ref"],
875
799
  _excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
876
800
  _excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
@@ -1021,7 +945,7 @@
1021
945
  }
1022
946
  newStateToSet[key];
1023
947
  // if it's coming from props, then we don't care to set it internally
1024
- if (!isControlledProp(_this.props, key)) {
948
+ if (_this.props[key] === undefined) {
1025
949
  nextState[key] = newStateToSet[key];
1026
950
  }
1027
951
  });
@@ -1751,7 +1675,7 @@
1751
1675
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1752
1676
  }
1753
1677
  }
1754
- if (isControlledProp(this.props, 'selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1678
+ if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1755
1679
  this.internalSetState({
1756
1680
  type: controlledPropUpdatedSelectedItem,
1757
1681
  inputValue: this.props.itemToString(this.props.selectedItem)
@@ -1888,7 +1812,7 @@
1888
1812
  changes[key] = newState[key];
1889
1813
  }
1890
1814
  }
1891
- if (props.onStateChange && Object.keys(changes).length) {
1815
+ if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
1892
1816
  props.onStateChange(_extends({
1893
1817
  type: type
1894
1818
  }, changes));
@@ -1914,50 +1838,53 @@
1914
1838
  * two reducers, one from downshift and an optional one from the user.
1915
1839
  * Also calls the onChange handlers for state values that have changed.
1916
1840
  *
1917
- * @param {Function} reducer Reducer function from downshift.
1918
- * @param {Object} props The hook props, also passed to createInitialState.
1919
- * @param {Function} createInitialState Function that returns the initial state.
1920
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1921
- * @returns {Array} An array with the state and an action dispatcher.
1841
+ * @param reducer Reducer function from downshift.
1842
+ * @param props The hook props, also passed to createInitialState.
1843
+ * @param createInitialState Function that returns the initial state.
1844
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1845
+ * @returns An array with the state and an action dispatcher.
1922
1846
  */
1923
1847
  function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
1924
- var prevStateRef = React__namespace.useRef(null);
1925
- var actionRef = React__namespace.useRef(undefined);
1926
- var propsRef = useLatestRef(props);
1848
+ var prevStateRef = React__namespace.useRef({});
1849
+ var actionRef = React__namespace.useRef();
1927
1850
  var enhancedReducer = React__namespace.useCallback(function (state, action) {
1928
1851
  actionRef.current = action;
1929
- state = getState(state, propsRef.current);
1930
- var changes = reducer(state, propsRef.current, action);
1931
- var newState = propsRef.current.stateReducer(state, _extends({}, action, {
1852
+ state = getState(state, action.props);
1853
+ var changes = reducer(state, action);
1854
+ var newState = action.props.stateReducer(state, _extends({}, action, {
1932
1855
  changes: changes
1933
1856
  }));
1934
1857
  return _extends({}, state, newState);
1935
- }, [propsRef, reducer]);
1858
+ }, [reducer]);
1936
1859
  var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
1937
1860
  state = _React$useReducer[0],
1938
1861
  dispatch = _React$useReducer[1];
1862
+ var propsRef = useLatestRef(props);
1863
+ var dispatchWithProps = React__namespace.useCallback(function (action) {
1864
+ return dispatch(_extends({}, action, {
1865
+ props: propsRef.current
1866
+ }));
1867
+ }, [propsRef]);
1939
1868
  var action = actionRef.current;
1940
1869
  React__namespace.useEffect(function () {
1941
- var _prevStateRef$current;
1942
- var prevState = getState((_prevStateRef$current = prevStateRef.current) != null ? _prevStateRef$current : {}, propsRef.current);
1943
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
1870
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
1871
+ var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
1944
1872
  if (shouldCallOnChangeProps) {
1945
- callOnChangeProps(action, propsRef.current, prevState, state);
1873
+ callOnChangeProps(action, action.props, prevState, state);
1946
1874
  }
1947
1875
  prevStateRef.current = state;
1948
- }, [state, action, isStateEqual, propsRef]);
1949
- return [state, dispatch];
1876
+ }, [state, action, isStateEqual]);
1877
+ return [state, dispatchWithProps];
1950
1878
  }
1951
1879
 
1952
1880
  /**
1953
1881
  * Wraps the useEnhancedReducer and applies the controlled prop values before
1954
1882
  * returning the new state.
1955
- *
1956
- * @param {Function} reducer Reducer function from downshift.
1957
- * @param {Object} props The hook props, also passed to createInitialState.
1958
- * @param {Function} createInitialState Function that returns the initial state.
1959
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1960
- * @returns {Array} An array with the state and an action dispatcher.
1883
+ * @param reducer Reducer function from downshift.
1884
+ * @param props The hook props, also passed to createInitialState.
1885
+ * @param createInitialState Function that returns the initial state.
1886
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1887
+ * @returns An array with the state and an action dispatcher.
1961
1888
  */
1962
1889
  function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
1963
1890
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
@@ -2010,16 +1937,8 @@
2010
1937
  return isInitialMountRef.current;
2011
1938
  }
2012
1939
 
2013
- /**
2014
- * Default state reducer that returns the changes.
2015
- *
2016
- */
2017
- function stateReducer(_s, a) {
2018
- return a.changes;
2019
- }
2020
-
2021
1940
  // Shared between all exports.
2022
- var propTypes$5 = {
1941
+ var propTypes$4 = {
2023
1942
  environment: PropTypes.shape({
2024
1943
  addEventListener: PropTypes.func.isRequired,
2025
1944
  removeEventListener: PropTypes.func.isRequired,
@@ -2035,30 +1954,47 @@
2035
1954
  stateReducer: PropTypes.func
2036
1955
  };
2037
1956
 
2038
- function getDefaultValue$1(props, propKey, defaultStateValues) {
2039
- var defaultValue = props["default" + capitalizeString(propKey)];
2040
- if (defaultValue !== undefined) {
2041
- return defaultValue;
2042
- }
2043
- return defaultStateValues[propKey];
1957
+ /**
1958
+ * Returns the default value based on the defaultProp and defaultStateValue.
1959
+ *
1960
+ * @param defaultProp The default prop value.
1961
+ * @param defaultStateValue The default state value.
1962
+ * @returns The resolved default value.
1963
+ */
1964
+ function getDefaultValue(defaultProp, defaultStateValue) {
1965
+ return defaultProp === undefined ? defaultStateValue : defaultProp;
2044
1966
  }
2045
1967
 
2046
- function getInitialValue$1(props, propKey, defaultStateValues) {
2047
- var value = props[propKey];
1968
+ /**
1969
+ * Returns the initial value for a state variable, based on the following precedence:
1970
+ * 1. The controlled value (if it's not undefined)
1971
+ * 2. The initialValue (if it's not undefined)
1972
+ * 3. The defaultValue (if it's not undefined)
1973
+ * 4. The defaultStateValue
1974
+ *
1975
+ * @param value The controlled value of the state variable.
1976
+ * @param initialValue The initial value of the state variable.
1977
+ * @param defaultValue The default value of the state variable.
1978
+ * @param defaultStateValue The default state value to use if all other values are undefined.
1979
+ * @returns The initial value for the state variable.
1980
+ */
1981
+ function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
2048
1982
  if (value !== undefined) {
2049
1983
  return value;
2050
1984
  }
2051
- var initialValue = props["initial" + capitalizeString(propKey)];
2052
1985
  if (initialValue !== undefined) {
2053
1986
  return initialValue;
2054
1987
  }
2055
- return getDefaultValue$1(props, propKey, defaultStateValues);
1988
+ if (defaultValue !== undefined) {
1989
+ return defaultValue;
1990
+ }
1991
+ return defaultStateValue;
2056
1992
  }
2057
1993
 
2058
1994
  /**
2059
1995
  * Debounced call for updating the a11y message.
2060
1996
  */
2061
- var updateA11yStatus = debounce$1(function (status, document) {
1997
+ var updateA11yStatus = debounce(function (status, document) {
2062
1998
  setStatus(status, document);
2063
1999
  }, 200);
2064
2000
 
@@ -2094,7 +2030,7 @@
2094
2030
  }
2095
2031
 
2096
2032
  // Shared between useSelect, useCombobox, Downshift.
2097
- var propTypes$4 = _extends({}, propTypes$5, {
2033
+ var dropdownPropTypes = _extends({}, propTypes$4, {
2098
2034
  getA11yStatusMessage: PropTypes.func,
2099
2035
  highlightedIndex: PropTypes.number,
2100
2036
  defaultHighlightedIndex: PropTypes.number,
@@ -2117,62 +2053,145 @@
2117
2053
  scrollIntoView: PropTypes.func
2118
2054
  });
2119
2055
 
2120
- var defaultProps$3 = {
2056
+ var dropdownDefaultProps = {
2121
2057
  itemToString: function itemToString(item) {
2122
2058
  return item ? String(item) : '';
2123
2059
  },
2124
2060
  itemToKey: function itemToKey(item) {
2125
2061
  return item;
2126
2062
  },
2127
- stateReducer: stateReducer,
2063
+ isItemDisabled: function isItemDisabled(_item) {
2064
+ return false;
2065
+ },
2066
+ stateReducer: function stateReducer(_state, actionAndChanges) {
2067
+ return actionAndChanges.changes;
2068
+ },
2128
2069
  scrollIntoView: scrollIntoView,
2129
2070
  environment: /* istanbul ignore next (ssr) */
2130
2071
  typeof window === 'undefined' || false ? undefined : window
2131
2072
  };
2132
2073
 
2133
- var defaultStateValues$1 = {
2074
+ var dropdownDefaultStateValues = {
2134
2075
  highlightedIndex: -1,
2135
2076
  isOpen: false,
2136
2077
  selectedItem: null,
2137
2078
  inputValue: ''
2138
2079
  };
2139
2080
 
2140
- // istanbul ignore next
2141
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2142
- function isAcceptedCharacterKey(key) {
2143
- return /^\S{1}$/.test(key);
2081
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
2082
+ var SafeReact$1 = _extends({}, React__namespace);
2083
+ var reactUseId$1 = SafeReact$1.useId;
2084
+ var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
2085
+ function useElementIdsR18$1(_ref) {
2086
+ var id = _ref.id,
2087
+ labelId = _ref.labelId,
2088
+ menuId = _ref.menuId,
2089
+ getItemId = _ref.getItemId,
2090
+ toggleButtonId = _ref.toggleButtonId,
2091
+ inputId = _ref.inputId;
2092
+ var reactId = "downshift-" + reactUseId$1();
2093
+ if (!id) {
2094
+ id = reactId;
2095
+ }
2096
+ var elementIds = React__namespace.useMemo(function () {
2097
+ return {
2098
+ labelId: labelId != null ? labelId : id + "-label",
2099
+ menuId: menuId != null ? menuId : id + "-menu",
2100
+ getItemId: getItemId != null ? getItemId : function (index) {
2101
+ return id + "-item-" + index;
2102
+ },
2103
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
2104
+ inputId: inputId != null ? inputId : id + "-input"
2105
+ };
2106
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2107
+ return elementIds;
2144
2108
  }
2145
- function getInitialState$3(props) {
2146
- var selectedItem = getInitialValue$1(props, 'selectedItem', defaultStateValues$1);
2147
- var isOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
2148
- var highlightedIndex = getInitialHighlightedIndex(props);
2149
- var inputValue = getInitialValue$1(props, 'inputValue', defaultStateValues$1);
2150
- return {
2151
- highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
2152
- return props.itemToKey(item) === props.itemToKey(selectedItem);
2153
- }) : highlightedIndex,
2154
- isOpen: isOpen,
2155
- selectedItem: selectedItem,
2156
- inputValue: inputValue
2157
- };
2109
+ function useElementIdsLegacy$1(_ref2) {
2110
+ var id = _ref2.id,
2111
+ labelId = _ref2.labelId,
2112
+ menuId = _ref2.menuId,
2113
+ getItemId = _ref2.getItemId,
2114
+ toggleButtonId = _ref2.toggleButtonId,
2115
+ inputId = _ref2.inputId;
2116
+ var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
2117
+ var baseId = baseIdRef.current;
2118
+ var elementIds = React__namespace.useMemo(function () {
2119
+ return {
2120
+ labelId: labelId != null ? labelId : baseId + "-label",
2121
+ menuId: menuId != null ? menuId : baseId + "-menu",
2122
+ getItemId: getItemId != null ? getItemId : function (index) {
2123
+ return baseId + "-item-" + index;
2124
+ },
2125
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
2126
+ inputId: inputId != null ? inputId : baseId + "-input"
2127
+ };
2128
+ }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
2129
+ return elementIds;
2158
2130
  }
2159
- function getHighlightedIndexOnOpen(props, state, offset) {
2160
- var items = props.items,
2161
- initialHighlightedIndex = props.initialHighlightedIndex,
2162
- defaultHighlightedIndex = props.defaultHighlightedIndex,
2163
- isItemDisabled = props.isItemDisabled,
2164
- itemToKey = props.itemToKey;
2165
- var selectedItem = state.selectedItem,
2166
- highlightedIndex = state.highlightedIndex;
2131
+
2132
+ /**
2133
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2134
+ *
2135
+ * @param props Props passed to the hook.
2136
+ * @returns The highlighted index.
2137
+ */
2138
+ function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
2139
+ var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
2140
+ if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
2141
+ return -1;
2142
+ }
2143
+ return highlightedIndex;
2144
+ }
2145
+
2146
+ /**
2147
+ * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
2148
+ * In that case, selects the item and resets to defaults for open state and highlighted idex.
2149
+ *
2150
+ * @param props The Dropdown props.
2151
+ * @param highlightedIndex The index from the state.
2152
+ * @param inputValue Also return the input value for state.
2153
+ * @returns The changes for the state.
2154
+ */
2155
+ function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
2156
+ var shouldSelect = items.length && highlightedIndex >= 0;
2157
+ return _extends({
2158
+ isOpen: false,
2159
+ highlightedIndex: -1
2160
+ }, shouldSelect && _extends({
2161
+ selectedItem: items[highlightedIndex],
2162
+ isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
2163
+ highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
2164
+ }, inputValue && {
2165
+ inputValue: itemToString(items[highlightedIndex])
2166
+ }));
2167
+ }
2168
+
2169
+ /* eslint-disable max-params */
2170
+ /**
2171
+ * Returns the highlighted index when the menu is opened.
2172
+ * Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
2173
+ * selectedItem, and the open direction offset.
2174
+ *
2175
+ * @param items The list of items.
2176
+ * @param initialHighlightedIndex The initial highlighted index prop.
2177
+ * @param defaultHighlightedIndex The default highlighted index prop.
2178
+ * @param isItemDisabled Callback to determine if an item is disabled.
2179
+ * @param itemToKey Callback to get a unique key from an item.
2180
+ * @param selectedItem The currently selected item.
2181
+ * @param highlightedIndex The current highlighted index from state.
2182
+ * @param offset The direction of navigation: positive opens downward, negative opens upward.
2183
+ * @returns The new highlighted index.
2184
+ */
2185
+ function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
2167
2186
  if (items.length === 0) {
2168
2187
  return -1;
2169
2188
  }
2170
2189
 
2171
2190
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
2172
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
2191
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
2173
2192
  return initialHighlightedIndex;
2174
2193
  }
2175
- if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
2194
+ if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
2176
2195
  return defaultHighlightedIndex;
2177
2196
  }
2178
2197
  if (selectedItem) {
@@ -2180,21 +2199,71 @@
2180
2199
  return itemToKey(selectedItem) === itemToKey(item);
2181
2200
  });
2182
2201
  }
2183
- if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
2202
+ if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
2184
2203
  return items.length - 1;
2185
2204
  }
2186
- if (offset > 0 && !isItemDisabled(items[0], 0)) {
2205
+ if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
2187
2206
  return 0;
2188
2207
  }
2189
2208
  return -1;
2190
2209
  }
2210
+
2211
+ function getInitialState$3(props) {
2212
+ var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
2213
+ var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
2214
+ var highlightedIndex = getInitialHighlightedIndex(props);
2215
+ var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
2216
+ return {
2217
+ highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
2218
+ return props.itemToKey(item) === props.itemToKey(selectedItem);
2219
+ }) : highlightedIndex,
2220
+ isOpen: isOpen,
2221
+ selectedItem: selectedItem,
2222
+ inputValue: inputValue
2223
+ };
2224
+ }
2225
+
2226
+ /**
2227
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2228
+ * @param props Props from useCombobox or useSelect.
2229
+ * @returns The highlighted index.
2230
+ */
2231
+ function getInitialHighlightedIndex(props) {
2232
+ var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
2233
+ if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2234
+ return -1;
2235
+ }
2236
+ return highlightedIndex;
2237
+ }
2238
+
2239
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2240
+ // eslint-disable-next-line import/no-mutable-exports
2241
+ var useControlPropsValidator = noop;
2242
+ /* istanbul ignore next */
2243
+ {
2244
+ useControlPropsValidator = function useControlPropsValidator(_ref) {
2245
+ var props = _ref.props,
2246
+ state = _ref.state;
2247
+ // used for checking when props are moving from controlled to uncontrolled.
2248
+ var prevPropsRef = React__namespace.useRef(props);
2249
+ var isInitialMount = useIsInitialMount();
2250
+ React__namespace.useEffect(function () {
2251
+ if (isInitialMount) {
2252
+ return;
2253
+ }
2254
+ validateControlledUnchanged(state, prevPropsRef.current, props);
2255
+ prevPropsRef.current = props;
2256
+ }, [state, props, isInitialMount]);
2257
+ };
2258
+ }
2259
+
2191
2260
  /**
2192
2261
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
2193
2262
  *
2194
- * @param {Window} environment The environment to add the event listeners to, for instance window.
2195
- * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
2196
- * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
2197
- * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
2263
+ * @param environment The environment to add the event listeners to, for instance window.
2264
+ * @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
2265
+ * @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
2266
+ * @returns The mouse and touch events information.
2198
2267
  */
2199
2268
  function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
2200
2269
  var mouseAndTouchTrackersRef = React__namespace.useRef({
@@ -2258,8 +2327,8 @@
2258
2327
  /**
2259
2328
  * Custom hook that checks if getter props are called correctly.
2260
2329
  *
2261
- * @param {...any} propKeys Getter prop names to be handled.
2262
- * @returns {Function} Setter function called inside getter props to set call information.
2330
+ * @param propKeys Getter prop names to be handled.
2331
+ * @returns Setter function called inside getter props to set call information.
2263
2332
  */
2264
2333
  /* istanbul ignore next */
2265
2334
  {
@@ -2295,120 +2364,58 @@
2295
2364
  getterPropsCalledRef.current[propKey] = {
2296
2365
  suppressRefError: suppressRefError,
2297
2366
  refKey: refKey,
2298
- elementRef: elementRef
2299
- };
2300
- }, []);
2301
- return setGetterPropCallInfo;
2302
- };
2303
- }
2304
- function useScrollIntoView(_ref) {
2305
- var highlightedIndex = _ref.highlightedIndex,
2306
- isOpen = _ref.isOpen,
2307
- itemRefs = _ref.itemRefs,
2308
- getItemNodeFromIndex = _ref.getItemNodeFromIndex,
2309
- menuElement = _ref.menuElement,
2310
- scrollIntoViewProp = _ref.scrollIntoView;
2311
- // used not to scroll on highlight by mouse.
2312
- var shouldScrollRef = React__namespace.useRef(true);
2313
- // Scroll on highlighted item if change comes from keyboard.
2314
- useIsomorphicLayoutEffect(function () {
2315
- if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2316
- return;
2317
- }
2318
- if (shouldScrollRef.current === false) {
2319
- shouldScrollRef.current = true;
2320
- } else {
2321
- scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
2322
- }
2323
- // eslint-disable-next-line react-hooks/exhaustive-deps
2324
- }, [highlightedIndex]);
2325
- return shouldScrollRef;
2326
- }
2327
-
2328
- // eslint-disable-next-line import/no-mutable-exports
2329
- var useControlPropsValidator = noop;
2330
- /* istanbul ignore next */
2331
- {
2332
- useControlPropsValidator = function useControlPropsValidator(_ref2) {
2333
- var props = _ref2.props,
2334
- state = _ref2.state;
2335
- // used for checking when props are moving from controlled to uncontrolled.
2336
- var prevPropsRef = React__namespace.useRef(props);
2337
- var isInitialMount = useIsInitialMount();
2338
- React__namespace.useEffect(function () {
2339
- if (isInitialMount) {
2340
- return;
2341
- }
2342
- validateControlledUnchanged(state, prevPropsRef.current, props);
2343
- prevPropsRef.current = props;
2344
- }, [state, props, isInitialMount]);
2345
- };
2346
- }
2347
-
2348
- /**
2349
- * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
2350
- * In that case, selects the item and resets to defaults for open state and highlighted idex.
2351
- * @param {Object} props The useCombobox props.
2352
- * @param {number} highlightedIndex The index from the state.
2353
- * @param {boolean} inputValue Also return the input value for state.
2354
- * @returns The changes for the state.
2355
- */
2356
- function getChangesOnSelection(props, highlightedIndex, inputValue) {
2357
- var _props$items;
2358
- if (inputValue === void 0) {
2359
- inputValue = true;
2360
- }
2361
- var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
2362
- return _extends({
2363
- isOpen: false,
2364
- highlightedIndex: -1
2365
- }, shouldSelect && _extends({
2366
- selectedItem: props.items[highlightedIndex],
2367
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2368
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
2369
- }, inputValue && {
2370
- inputValue: props.itemToString(props.items[highlightedIndex])
2371
- }));
2372
- }
2373
-
2374
- /**
2375
- * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2376
- * Used by useSelect and useCombobox.
2377
- *
2378
- * @param {Object} prevState
2379
- * @param {Object} newState
2380
- * @returns {boolean} Wheather the states are deeply equal.
2381
- */
2382
- function isDropdownsStateEqual(prevState, newState) {
2383
- return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2367
+ elementRef: elementRef
2368
+ };
2369
+ }, []);
2370
+ return setGetterPropCallInfo;
2371
+ };
2384
2372
  }
2385
2373
 
2374
+ // istanbul ignore next
2375
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2376
+
2386
2377
  /**
2387
- * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2388
- *
2389
- * @param {Object} props Props from useCombobox or useSelect.
2390
- * @returns {number} The highlighted index.
2378
+ * Utility hook that scrolls an item from a menu into view.
2379
+ * @param scrollIntoView The function that does the scroll.
2380
+ * @param highlightedIndex The index of the item that should be scrolled.
2381
+ * @param isOpen If the menu is open or not.
2382
+ * @param menuElement The menu element.
2383
+ * @param itemElements The object containing item elements.
2384
+ * @param getItemId The function to get the item id from index.
2385
+ * @returns Function that when called prevents the scroll.
2391
2386
  */
2392
- function getDefaultHighlightedIndex(props) {
2393
- var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
2394
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2395
- return -1;
2396
- }
2397
- return highlightedIndex;
2387
+ function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
2388
+ // used not to scroll on highlight by mouse.
2389
+ var shouldScrollRef = React__namespace.useRef(true);
2390
+ // Scroll on highlighted item if change comes from keyboard.
2391
+ useIsomorphicLayoutEffect(function () {
2392
+ if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
2393
+ return;
2394
+ }
2395
+ if (shouldScrollRef.current) {
2396
+ var itemElement = itemElements[getItemId(highlightedIndex)];
2397
+ if (itemElement && menuElement) {
2398
+ scrollIntoView(itemElement, menuElement);
2399
+ }
2400
+ } else {
2401
+ shouldScrollRef.current = true;
2402
+ }
2403
+ }, [highlightedIndex]);
2404
+ return React__namespace.useCallback(function preventScroll() {
2405
+ shouldScrollRef.current = false;
2406
+ }, []);
2398
2407
  }
2399
2408
 
2400
2409
  /**
2401
- * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2410
+ * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2411
+ * Used by useSelect and useCombobox.
2402
2412
  *
2403
- * @param {Object} props Props from useCombobox or useSelect.
2404
- * @returns {number} The highlighted index.
2413
+ * @param prevState The previous dropdown state.
2414
+ * @param newState The new dropdown state.
2415
+ * @returns Wheather the states are deeply equal.
2405
2416
  */
2406
- function getInitialHighlightedIndex(props) {
2407
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
2408
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2409
- return -1;
2410
- }
2411
- return highlightedIndex;
2417
+ function isDropdownStateEqual(prevState, newState) {
2418
+ return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2412
2419
  }
2413
2420
 
2414
2421
  function downshiftCommonReducer(state, props, action, stateChangeTypes) {
@@ -2429,13 +2436,13 @@
2429
2436
  case stateChangeTypes.FunctionToggleMenu:
2430
2437
  changes = {
2431
2438
  isOpen: !state.isOpen,
2432
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
2439
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2433
2440
  };
2434
2441
  break;
2435
2442
  case stateChangeTypes.FunctionOpenMenu:
2436
2443
  changes = {
2437
2444
  isOpen: true,
2438
- highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
2445
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2439
2446
  };
2440
2447
  break;
2441
2448
  case stateChangeTypes.FunctionCloseMenu:
@@ -2444,9 +2451,12 @@
2444
2451
  };
2445
2452
  break;
2446
2453
  case stateChangeTypes.FunctionSetHighlightedIndex:
2447
- changes = {
2448
- highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
2449
- };
2454
+ {
2455
+ var highlightedIndex = action.highlightedIndex;
2456
+ changes = {
2457
+ highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
2458
+ };
2459
+ }
2450
2460
  break;
2451
2461
  case stateChangeTypes.FunctionSetInputValue:
2452
2462
  changes = {
@@ -2455,10 +2465,10 @@
2455
2465
  break;
2456
2466
  case stateChangeTypes.FunctionReset:
2457
2467
  changes = {
2458
- highlightedIndex: getDefaultHighlightedIndex(props),
2459
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2460
- selectedItem: getDefaultValue$1(props, 'selectedItem', defaultStateValues$1),
2461
- inputValue: getDefaultValue$1(props, 'inputValue', defaultStateValues$1)
2468
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2469
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2470
+ selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
2471
+ inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
2462
2472
  };
2463
2473
  break;
2464
2474
  default:
@@ -2468,17 +2478,11 @@
2468
2478
  }
2469
2479
  /* eslint-enable complexity */
2470
2480
 
2471
- var propTypes$3 = _extends({}, propTypes$4, {
2481
+ var propTypes$3 = _extends({}, dropdownPropTypes, {
2472
2482
  items: PropTypes.array.isRequired,
2473
2483
  isItemDisabled: PropTypes.func
2474
2484
  });
2475
2485
 
2476
- var defaultProps$2 = _extends({}, defaultProps$3, {
2477
- isItemDisabled: function isItemDisabled() {
2478
- return false;
2479
- }
2480
- });
2481
-
2482
2486
  function getItemIndexByCharacterKey(_ref) {
2483
2487
  var keysSoFar = _ref.keysSoFar,
2484
2488
  highlightedIndex = _ref.highlightedIndex,
@@ -2547,16 +2551,15 @@
2547
2551
  });
2548
2552
 
2549
2553
  /* eslint-disable complexity */
2550
- function downshiftSelectReducer(state, props, action) {
2551
- var _props$items;
2554
+ function downshiftSelectReducer(state, action) {
2552
2555
  var type = action.type,
2553
- altKey = action.altKey;
2556
+ props = action.props;
2554
2557
  var changes;
2555
2558
  switch (type) {
2556
2559
  case ItemClick$1:
2557
2560
  changes = {
2558
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2559
- highlightedIndex: getDefaultHighlightedIndex(props),
2561
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2562
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2560
2563
  selectedItem: props.items[action.index]
2561
2564
  };
2562
2565
  break;
@@ -2583,7 +2586,8 @@
2583
2586
  break;
2584
2587
  case ToggleButtonKeyDownArrowDown:
2585
2588
  {
2586
- var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2589
+ var altKey = action.altKey;
2590
+ 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);
2587
2591
  changes = {
2588
2592
  highlightedIndex: _highlightedIndex,
2589
2593
  isOpen: true
@@ -2591,20 +2595,23 @@
2591
2595
  }
2592
2596
  break;
2593
2597
  case ToggleButtonKeyDownArrowUp:
2594
- if (state.isOpen && altKey) {
2595
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2596
- } else {
2597
- var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props, state, -1);
2598
- changes = {
2599
- highlightedIndex: _highlightedIndex2,
2600
- isOpen: true
2601
- };
2598
+ {
2599
+ var _altKey = action.altKey;
2600
+ if (state.isOpen && _altKey) {
2601
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2602
+ } else {
2603
+ 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);
2604
+ changes = {
2605
+ highlightedIndex: _highlightedIndex2,
2606
+ isOpen: true
2607
+ };
2608
+ }
2602
2609
  }
2603
2610
  break;
2604
2611
  // only triggered when menu is open.
2605
2612
  case ToggleButtonKeyDownEnter:
2606
2613
  case ToggleButtonKeyDownSpaceButton:
2607
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2614
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2608
2615
  break;
2609
2616
  case ToggleButtonKeyDownHome:
2610
2617
  changes = {
@@ -2638,7 +2645,7 @@
2638
2645
  changes = _extends({
2639
2646
  isOpen: false,
2640
2647
  highlightedIndex: -1
2641
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
2648
+ }, state.highlightedIndex >= 0 && props.items.length && {
2642
2649
  selectedItem: props.items[state.highlightedIndex]
2643
2650
  });
2644
2651
  break;
@@ -2654,59 +2661,9 @@
2654
2661
  }
2655
2662
  /* eslint-enable complexity */
2656
2663
 
2657
- // eslint-disable-next-line @typescript-eslint/dot-notation
2658
- var reactUseId$1 = React__namespace['useId'];
2659
- var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
2660
- function useElementIdsR18$1(_ref) {
2661
- var id = _ref.id,
2662
- labelId = _ref.labelId,
2663
- menuId = _ref.menuId,
2664
- getItemId = _ref.getItemId,
2665
- toggleButtonId = _ref.toggleButtonId,
2666
- inputId = _ref.inputId;
2667
- var reactId = "downshift-" + reactUseId$1();
2668
- if (!id) {
2669
- id = reactId;
2670
- }
2671
- var elementIds = React__namespace.useMemo(function () {
2672
- return {
2673
- labelId: labelId != null ? labelId : id + "-label",
2674
- menuId: menuId != null ? menuId : id + "-menu",
2675
- getItemId: getItemId != null ? getItemId : function (index) {
2676
- return id + "-item-" + index;
2677
- },
2678
- toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
2679
- inputId: inputId != null ? inputId : id + "-input"
2680
- };
2681
- }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2682
- return elementIds;
2683
- }
2684
- function useElementIdsLegacy$1(_ref2) {
2685
- var id = _ref2.id,
2686
- labelId = _ref2.labelId,
2687
- menuId = _ref2.menuId,
2688
- getItemId = _ref2.getItemId,
2689
- toggleButtonId = _ref2.toggleButtonId,
2690
- inputId = _ref2.inputId;
2691
- var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
2692
- var baseId = baseIdRef.current;
2693
- var elementIds = React__namespace.useMemo(function () {
2694
- return {
2695
- labelId: labelId != null ? labelId : baseId + "-label",
2696
- menuId: menuId != null ? menuId : baseId + "-menu",
2697
- getItemId: getItemId != null ? getItemId : function (index) {
2698
- return baseId + "-item-" + index;
2699
- },
2700
- toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
2701
- inputId: inputId != null ? inputId : baseId + "-input"
2702
- };
2703
- }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
2704
- return elementIds;
2705
- }
2706
-
2707
2664
  var _excluded$3 = ["onClick"],
2708
- _excluded2$3 = ["onMouseLeave", "refKey", "ref"],
2709
- _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
2665
+ _excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
2666
+ _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
2710
2667
  _excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
2711
2668
  useSelect.stateChangeTypes = stateChangeTypes$3;
2712
2669
  function useSelect(userProps) {
@@ -2715,22 +2672,23 @@
2715
2672
  }
2716
2673
  validatePropTypes$1(userProps, useSelect, propTypes$3);
2717
2674
  // Props defaults and destructuring.
2718
- var props = _extends({}, defaultProps$2, userProps);
2675
+ var props = _extends({}, dropdownDefaultProps, userProps);
2719
2676
  var scrollIntoView = props.scrollIntoView,
2720
2677
  environment = props.environment,
2721
2678
  getA11yStatusMessage = props.getA11yStatusMessage;
2722
2679
  // Initial state depending on controlled props.
2723
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownsStateEqual),
2680
+ var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
2724
2681
  state = _useControlledReducer[0],
2725
2682
  dispatch = _useControlledReducer[1];
2726
2683
  var isOpen = state.isOpen,
2727
2684
  highlightedIndex = state.highlightedIndex,
2728
2685
  selectedItem = state.selectedItem,
2729
2686
  inputValue = state.inputValue;
2730
- // Element efs.
2687
+
2688
+ // Element refs.
2731
2689
  var toggleButtonRef = React.useRef(null);
2732
2690
  var menuRef = React.useRef(null);
2733
- var itemRefs = React.useRef({});
2691
+ var itemsRef = React.useRef({});
2734
2692
 
2735
2693
  // used to keep the inputValue clearTimeout object between renders.
2736
2694
  var clearTimeoutRef = React.useRef(null);
@@ -2742,24 +2700,12 @@
2742
2700
  props: props
2743
2701
  });
2744
2702
 
2745
- // Some utils.
2746
- var getItemNodeFromIndex = React.useCallback(function (index) {
2747
- return itemRefs.current[elementIds.getItemId(index)];
2748
- }, [elementIds]);
2749
-
2750
2703
  // Effects.
2751
2704
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
2752
2705
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
2753
2706
  // Scroll on highlighted item if change comes from keyboard.
2754
- var shouldScrollRef = useScrollIntoView({
2755
- menuElement: menuRef.current,
2756
- highlightedIndex: highlightedIndex,
2757
- isOpen: isOpen,
2758
- itemRefs: itemRefs,
2759
- scrollIntoView: scrollIntoView,
2760
- getItemNodeFromIndex: getItemNodeFromIndex
2761
- });
2762
- // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2707
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
2708
+ // Sets cleanup for the keysSoFar callback, debounced after 500ms.
2763
2709
  React.useEffect(function () {
2764
2710
  // init the clean function here as we need access to dispatch.
2765
2711
  clearTimeoutRef.current = debounce(function (outerDispatch) {
@@ -2771,7 +2717,8 @@
2771
2717
 
2772
2718
  // Cancel any pending debounced calls on mount
2773
2719
  return function () {
2774
- clearTimeoutRef.current.cancel();
2720
+ var _clearTimeoutRef$curr;
2721
+ (_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
2775
2722
  };
2776
2723
  }, []);
2777
2724
  // Invokes the keysSoFar callback set up above.
@@ -2779,7 +2726,7 @@
2779
2726
  if (!inputValue) {
2780
2727
  return;
2781
2728
  }
2782
- clearTimeoutRef.current(dispatch);
2729
+ clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
2783
2730
  }, [dispatch, inputValue]);
2784
2731
  useControlPropsValidator({
2785
2732
  props: props,
@@ -2787,7 +2734,7 @@
2787
2734
  });
2788
2735
  // Focus the toggle button on first render if required.
2789
2736
  React.useEffect(function () {
2790
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
2737
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
2791
2738
  if (focusOnOpen && toggleButtonRef.current) {
2792
2739
  toggleButtonRef.current.focus();
2793
2740
  }
@@ -2808,7 +2755,7 @@
2808
2755
  // Reset itemRefs on close.
2809
2756
  React.useEffect(function () {
2810
2757
  if (!isOpen) {
2811
- itemRefs.current = {};
2758
+ itemsRef.current = {};
2812
2759
  }
2813
2760
  }, [isOpen]);
2814
2761
 
@@ -2893,50 +2840,11 @@
2893
2840
  };
2894
2841
  }, [dispatch, latest]);
2895
2842
 
2896
- // Action functions.
2897
- var toggleMenu = React.useCallback(function () {
2898
- dispatch({
2899
- type: FunctionToggleMenu$1
2900
- });
2901
- }, [dispatch]);
2902
- var closeMenu = React.useCallback(function () {
2903
- dispatch({
2904
- type: FunctionCloseMenu$1
2905
- });
2906
- }, [dispatch]);
2907
- var openMenu = React.useCallback(function () {
2908
- dispatch({
2909
- type: FunctionOpenMenu$1
2910
- });
2911
- }, [dispatch]);
2912
- var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
2913
- dispatch({
2914
- type: FunctionSetHighlightedIndex$1,
2915
- highlightedIndex: newHighlightedIndex
2916
- });
2917
- }, [dispatch]);
2918
- var selectItem = React.useCallback(function (newSelectedItem) {
2919
- dispatch({
2920
- type: FunctionSelectItem$1,
2921
- selectedItem: newSelectedItem
2922
- });
2923
- }, [dispatch]);
2924
- var reset = React.useCallback(function () {
2925
- dispatch({
2926
- type: FunctionReset$2
2927
- });
2928
- }, [dispatch]);
2929
- var setInputValue = React.useCallback(function (newInputValue) {
2930
- dispatch({
2931
- type: FunctionSetInputValue$1,
2932
- inputValue: newInputValue
2933
- });
2934
- }, [dispatch]);
2935
2843
  // Getter functions.
2936
- var getLabelProps = React.useCallback(function (_temp) {
2937
- var _ref = _temp === void 0 ? {} : _temp,
2844
+ var getLabelProps = React.useCallback(function (labelProps) {
2845
+ var _ref = labelProps != null ? labelProps : {},
2938
2846
  onClick = _ref.onClick,
2939
- labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2847
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2940
2848
  var labelHandleClick = function labelHandleClick() {
2941
2849
  var _toggleButtonRef$curr;
2942
2850
  (_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
@@ -2945,17 +2853,18 @@
2945
2853
  id: elementIds.labelId,
2946
2854
  htmlFor: elementIds.toggleButtonId,
2947
2855
  onClick: callAllEventHandlers(onClick, labelHandleClick)
2948
- }, labelProps);
2856
+ }, rest);
2949
2857
  }, [elementIds]);
2950
- var getMenuProps = React.useCallback(function (_temp2, _temp3) {
2858
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
2951
2859
  var _extends2;
2952
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2860
+ var _ref2 = menuProps != null ? menuProps : {},
2953
2861
  onMouseLeave = _ref2.onMouseLeave,
2954
2862
  _ref2$refKey = _ref2.refKey,
2955
2863
  refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
2956
2864
  ref = _ref2.ref,
2865
+ ariaLabel = _ref2['aria-label'],
2957
2866
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
2958
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2867
+ var _ref3 = otherProps != null ? otherProps : {},
2959
2868
  _ref3$suppressRefErro = _ref3.suppressRefError,
2960
2869
  suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
2961
2870
  var menuHandleMouseLeave = function menuHandleMouseLeave() {
@@ -2966,11 +2875,11 @@
2966
2875
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2967
2876
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2968
2877
  menuRef.current = menuNode;
2969
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
2878
+ }), _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);
2970
2879
  }, [dispatch, setGetterPropCallInfo, elementIds]);
2971
- var getToggleButtonProps = React.useCallback(function (_temp4, _temp5) {
2880
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
2972
2881
  var _extends3;
2973
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2882
+ var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
2974
2883
  onBlur = _ref4.onBlur,
2975
2884
  onClick = _ref4.onClick;
2976
2885
  _ref4.onPress;
@@ -2978,8 +2887,9 @@
2978
2887
  _ref4$refKey = _ref4.refKey,
2979
2888
  refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
2980
2889
  ref = _ref4.ref,
2890
+ disabled = _ref4.disabled,
2981
2891
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
2982
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2892
+ var _ref5 = otherProps != null ? otherProps : {},
2983
2893
  _ref5$suppressRefErro = _ref5.suppressRefError,
2984
2894
  suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
2985
2895
  var latestState = latest.current.state;
@@ -2997,9 +2907,9 @@
2997
2907
  };
2998
2908
  var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2999
2909
  var key = normalizeArrowKey(event);
3000
- if (key && toggleButtonKeyDownHandlers[key]) {
2910
+ if (key && key in toggleButtonKeyDownHandlers) {
3001
2911
  toggleButtonKeyDownHandlers[key](event);
3002
- } else if (isAcceptedCharacterKey(key)) {
2912
+ } else if (/^\S{1}$/.test(key)) {
3003
2913
  dispatch({
3004
2914
  type: ToggleButtonKeyDownCharacter,
3005
2915
  key: key
@@ -3008,20 +2918,22 @@
3008
2918
  };
3009
2919
  var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
3010
2920
  toggleButtonRef.current = toggleButtonNode;
3011
- }), _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);
3012
- if (!rest.disabled) {
2921
+ }), _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);
2922
+ if (!disabled) {
3013
2923
  /* istanbul ignore if (react-native) */
3014
2924
  {
3015
- toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
3016
- toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
2925
+ Object.assign(toggleProps, {
2926
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick),
2927
+ onKeyDown: callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown)
2928
+ });
3017
2929
  }
3018
2930
  }
3019
2931
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
3020
2932
  return toggleProps;
3021
2933
  }, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
3022
- var getItemProps = React.useCallback(function (_temp6) {
2934
+ var getItemProps = React.useCallback(function (itemProps) {
3023
2935
  var _extends4;
3024
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
2936
+ var _ref6 = itemProps != null ? itemProps : {},
3025
2937
  itemProp = _ref6.item,
3026
2938
  indexProp = _ref6.index,
3027
2939
  onMouseMove = _ref6.onMouseMove,
@@ -3047,7 +2959,7 @@
3047
2959
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
3048
2960
  return;
3049
2961
  }
3050
- shouldScrollRef.current = false;
2962
+ preventScroll();
3051
2963
  dispatch({
3052
2964
  type: ItemMouseMove$1,
3053
2965
  index: index,
@@ -3064,21 +2976,61 @@
3064
2976
  return e.preventDefault();
3065
2977
  }; // keep focus on the toggle after item click select.
3066
2978
 
3067
- var itemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2979
+ var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
3068
2980
  if (itemNode) {
3069
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
2981
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
3070
2982
  }
3071
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2983
+ }), _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);
3072
2984
  if (!disabled) {
3073
2985
  /* istanbul ignore next (react-native) */
3074
2986
  {
3075
- itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2987
+ Object.assign(resultItemProps, {
2988
+ onClick: callAllEventHandlers(onClick, itemHandleClick)
2989
+ });
3076
2990
  }
3077
2991
  }
3078
- itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
3079
- itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
3080
- return itemProps;
3081
- }, [latest, elementIds, mouseAndTouchTrackers, shouldScrollRef, dispatch]);
2992
+ return resultItemProps;
2993
+ }, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
2994
+
2995
+ // Action functions.
2996
+ var toggleMenu = React.useCallback(function () {
2997
+ dispatch({
2998
+ type: FunctionToggleMenu$1
2999
+ });
3000
+ }, [dispatch]);
3001
+ var closeMenu = React.useCallback(function () {
3002
+ dispatch({
3003
+ type: FunctionCloseMenu$1
3004
+ });
3005
+ }, [dispatch]);
3006
+ var openMenu = React.useCallback(function () {
3007
+ dispatch({
3008
+ type: FunctionOpenMenu$1
3009
+ });
3010
+ }, [dispatch]);
3011
+ var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
3012
+ dispatch({
3013
+ type: FunctionSetHighlightedIndex$1,
3014
+ highlightedIndex: newHighlightedIndex
3015
+ });
3016
+ }, [dispatch]);
3017
+ var selectItem = React.useCallback(function (newSelectedItem) {
3018
+ dispatch({
3019
+ type: FunctionSelectItem$1,
3020
+ selectedItem: newSelectedItem
3021
+ });
3022
+ }, [dispatch]);
3023
+ var reset = React.useCallback(function () {
3024
+ dispatch({
3025
+ type: FunctionReset$2
3026
+ });
3027
+ }, [dispatch]);
3028
+ var setInputValue = React.useCallback(function (newInputValue) {
3029
+ dispatch({
3030
+ type: FunctionSetInputValue$1,
3031
+ inputValue: newInputValue
3032
+ });
3033
+ }, [dispatch]);
3082
3034
  return {
3083
3035
  // prop getters.
3084
3036
  getToggleButtonProps: getToggleButtonProps,
@@ -3101,6 +3053,18 @@
3101
3053
  };
3102
3054
  }
3103
3055
 
3056
+ function getInitialState$2(props) {
3057
+ var initialState = getInitialState$3(props);
3058
+ var selectedItem = initialState.selectedItem;
3059
+ var inputValue = initialState.inputValue;
3060
+ if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
3061
+ inputValue = props.itemToString(selectedItem);
3062
+ }
3063
+ return _extends({}, initialState, {
3064
+ inputValue: inputValue
3065
+ });
3066
+ }
3067
+
3104
3068
  var InputKeyDownArrowDown = '__input_keydown_arrow_down__' ;
3105
3069
  var InputKeyDownArrowUp = '__input_keydown_arrow_up__' ;
3106
3070
  var InputKeyDownEscape = '__input_keydown_escape__' ;
@@ -3152,27 +3116,6 @@
3152
3116
  ToggleButtonClick: ToggleButtonClick
3153
3117
  });
3154
3118
 
3155
- function getInitialState$2(props) {
3156
- var initialState = getInitialState$3(props);
3157
- var selectedItem = initialState.selectedItem;
3158
- var inputValue = initialState.inputValue;
3159
- if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
3160
- inputValue = props.itemToString(selectedItem);
3161
- }
3162
- return _extends({}, initialState, {
3163
- inputValue: inputValue
3164
- });
3165
- }
3166
- var propTypes$2 = _extends({}, propTypes$4, {
3167
- items: PropTypes.array.isRequired,
3168
- isItemDisabled: PropTypes.func,
3169
- inputValue: PropTypes.string,
3170
- defaultInputValue: PropTypes.string,
3171
- initialInputValue: PropTypes.string,
3172
- inputId: PropTypes.string,
3173
- onInputValueChange: PropTypes.func
3174
- });
3175
-
3176
3119
  /**
3177
3120
  * The useCombobox version of useControlledReducer, which also
3178
3121
  * checks if the controlled prop selectedItem changed between
@@ -3180,20 +3123,20 @@
3180
3123
  * string equivalent. It uses the common useEnhancedReducer to
3181
3124
  * compute the rest of the state.
3182
3125
  *
3183
- * @param {Function} reducer Reducer function from downshift.
3184
- * @param {Object} props The hook props, also passed to createInitialState.
3185
- * @param {Function} createInitialState Function that returns the initial state.
3186
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
3187
- * @returns {Array} An array with the state and an action dispatcher.
3126
+ * @param reducer Reducer function from downshift.
3127
+ * @param props The hook props, also passed to createInitialState.
3128
+ * @param createInitialState Function that returns the initial state.
3129
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
3130
+ * @returns An array with the state and an action dispatcher.
3188
3131
  */
3189
3132
  function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
3190
- var previousSelectedItemRef = React.useRef();
3133
+ var previousSelectedItemRef = React.useRef(null);
3191
3134
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
3192
3135
  state = _useEnhancedReducer[0],
3193
3136
  dispatch = _useEnhancedReducer[1];
3194
3137
  var isInitialMount = useIsInitialMount();
3195
3138
  React.useEffect(function () {
3196
- if (!isControlledProp(props, 'selectedItem')) {
3139
+ if (props.selectedItem === undefined) {
3197
3140
  return;
3198
3141
  }
3199
3142
  if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
@@ -3211,23 +3154,27 @@
3211
3154
  }, [state.selectedItem, props.selectedItem]);
3212
3155
  return [getState(state, props), dispatch];
3213
3156
  }
3214
- var defaultProps$1 = _extends({}, defaultProps$3, {
3215
- isItemDisabled: function isItemDisabled() {
3216
- return false;
3217
- }
3157
+
3158
+ var propTypes$2 = _extends({}, dropdownPropTypes, {
3159
+ items: PropTypes.array.isRequired,
3160
+ isItemDisabled: PropTypes.func,
3161
+ inputValue: PropTypes.string,
3162
+ defaultInputValue: PropTypes.string,
3163
+ initialInputValue: PropTypes.string,
3164
+ inputId: PropTypes.string,
3165
+ onInputValueChange: PropTypes.func
3218
3166
  });
3219
3167
 
3220
3168
  /* eslint-disable complexity */
3221
- function downshiftUseComboboxReducer(state, props, action) {
3222
- var _props$items;
3169
+ function downshiftUseComboboxReducer(state, action) {
3223
3170
  var type = action.type,
3224
- altKey = action.altKey;
3171
+ props = action.props;
3225
3172
  var changes;
3226
3173
  switch (type) {
3227
3174
  case ItemClick:
3228
3175
  changes = {
3229
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
3230
- highlightedIndex: getDefaultHighlightedIndex(props),
3176
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
3177
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3231
3178
  selectedItem: props.items[action.index],
3232
3179
  inputValue: props.itemToString(props.items[action.index])
3233
3180
  };
@@ -3239,15 +3186,15 @@
3239
3186
  };
3240
3187
  } else {
3241
3188
  changes = {
3242
- highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
3189
+ highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
3243
3190
  isOpen: props.items.length >= 0
3244
3191
  };
3245
3192
  }
3246
3193
  break;
3247
3194
  case InputKeyDownArrowUp:
3248
3195
  if (state.isOpen) {
3249
- if (altKey) {
3250
- changes = getChangesOnSelection(props, state.highlightedIndex);
3196
+ if (action.altKey) {
3197
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
3251
3198
  } else {
3252
3199
  changes = {
3253
3200
  highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
@@ -3255,13 +3202,13 @@
3255
3202
  }
3256
3203
  } else {
3257
3204
  changes = {
3258
- highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
3205
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
3259
3206
  isOpen: props.items.length >= 0
3260
3207
  };
3261
3208
  }
3262
3209
  break;
3263
3210
  case InputKeyDownEnter:
3264
- changes = getChangesOnSelection(props, state.highlightedIndex);
3211
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
3265
3212
  break;
3266
3213
  case InputKeyDownEscape:
3267
3214
  changes = _extends({
@@ -3296,7 +3243,7 @@
3296
3243
  changes = _extends({
3297
3244
  isOpen: false,
3298
3245
  highlightedIndex: -1
3299
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
3246
+ }, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
3300
3247
  selectedItem: props.items[state.highlightedIndex],
3301
3248
  inputValue: props.itemToString(props.items[state.highlightedIndex])
3302
3249
  });
@@ -3304,14 +3251,14 @@
3304
3251
  case InputChange:
3305
3252
  changes = {
3306
3253
  isOpen: true,
3307
- highlightedIndex: getDefaultHighlightedIndex(props),
3254
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3308
3255
  inputValue: action.inputValue
3309
3256
  };
3310
3257
  break;
3311
3258
  case InputClick:
3312
3259
  changes = {
3313
3260
  isOpen: !state.isOpen,
3314
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
3261
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
3315
3262
  };
3316
3263
  break;
3317
3264
  case FunctionSelectItem:
@@ -3332,10 +3279,10 @@
3332
3279
  }
3333
3280
  /* eslint-enable complexity */
3334
3281
 
3335
- var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
3282
+ var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
3336
3283
  _excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
3337
- _excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
3338
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3284
+ _excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
3285
+ _excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3339
3286
  useCombobox.stateChangeTypes = stateChangeTypes$2;
3340
3287
  function useCombobox(userProps) {
3341
3288
  if (userProps === void 0) {
@@ -3343,13 +3290,13 @@
3343
3290
  }
3344
3291
  validatePropTypes$1(userProps, useCombobox, propTypes$2);
3345
3292
  // Props defaults and destructuring.
3346
- var props = _extends({}, defaultProps$1, userProps);
3293
+ var props = _extends({}, dropdownDefaultProps, userProps);
3347
3294
  var items = props.items,
3348
3295
  scrollIntoView = props.scrollIntoView,
3349
3296
  environment = props.environment,
3350
3297
  getA11yStatusMessage = props.getA11yStatusMessage;
3351
3298
  // Initial state depending on controlled props.
3352
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownsStateEqual),
3299
+ var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
3353
3300
  state = _useControlledReducer[0],
3354
3301
  dispatch = _useControlledReducer[1];
3355
3302
  var isOpen = state.isOpen,
@@ -3359,7 +3306,7 @@
3359
3306
 
3360
3307
  // Element refs.
3361
3308
  var menuRef = React.useRef(null);
3362
- var itemRefs = React.useRef({});
3309
+ var itemsRef = React.useRef({});
3363
3310
  var inputRef = React.useRef(null);
3364
3311
  var toggleButtonRef = React.useRef(null);
3365
3312
  var isInitialMount = useIsInitialMount();
@@ -3373,29 +3320,19 @@
3373
3320
  state: state,
3374
3321
  props: props
3375
3322
  });
3376
- var getItemNodeFromIndex = React.useCallback(function (index) {
3377
- return itemRefs.current[elementIds.getItemId(index)];
3378
- }, [elementIds]);
3379
3323
 
3380
3324
  // Effects.
3381
3325
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
3382
3326
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
3383
3327
  // Scroll on highlighted item if change comes from keyboard.
3384
- var shouldScrollRef = useScrollIntoView({
3385
- menuElement: menuRef.current,
3386
- highlightedIndex: highlightedIndex,
3387
- isOpen: isOpen,
3388
- itemRefs: itemRefs,
3389
- scrollIntoView: scrollIntoView,
3390
- getItemNodeFromIndex: getItemNodeFromIndex
3391
- });
3328
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
3392
3329
  useControlPropsValidator({
3393
- props: props,
3394
- state: state
3330
+ state: state,
3331
+ props: props
3395
3332
  });
3396
3333
  // Focus the input on first render if required.
3397
3334
  React.useEffect(function () {
3398
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
3335
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
3399
3336
  if (focusOnOpen && inputRef.current) {
3400
3337
  inputRef.current.focus();
3401
3338
  }
@@ -3421,13 +3358,13 @@
3421
3358
  // Reset itemRefs on close.
3422
3359
  React.useEffect(function () {
3423
3360
  if (!isOpen) {
3424
- itemRefs.current = {};
3361
+ itemsRef.current = {};
3425
3362
  }
3426
3363
  }, [isOpen]);
3427
3364
  // Reset itemRefs on close.
3428
3365
  React.useEffect(function () {
3429
3366
  var _inputRef$current;
3430
- if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3367
+ if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3431
3368
  return;
3432
3369
  }
3433
3370
  if (environment.document.activeElement !== inputRef.current) {
@@ -3517,29 +3454,30 @@
3517
3454
  htmlFor: elementIds.inputId
3518
3455
  }, labelProps);
3519
3456
  }, [elementIds]);
3520
- var getMenuProps = React.useCallback(function (_temp, _temp2) {
3457
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
3521
3458
  var _extends2;
3522
- var _ref = _temp === void 0 ? {} : _temp,
3459
+ var _ref = menuProps != null ? menuProps : {},
3523
3460
  onMouseLeave = _ref.onMouseLeave,
3524
3461
  _ref$refKey = _ref.refKey,
3525
3462
  refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3526
3463
  ref = _ref.ref,
3464
+ ariaLabel = _ref['aria-label'],
3527
3465
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3528
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3466
+ var _ref2 = otherProps != null ? otherProps : {},
3529
3467
  _ref2$suppressRefErro = _ref2.suppressRefError,
3530
3468
  suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3531
3469
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3532
3470
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3533
3471
  menuRef.current = menuNode;
3534
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3472
+ }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3535
3473
  dispatch({
3536
3474
  type: MenuMouseLeave
3537
3475
  });
3538
3476
  }), _extends2), rest);
3539
3477
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3540
- var getItemProps = React.useCallback(function (_temp3) {
3478
+ var getItemProps = React.useCallback(function (itemProps) {
3541
3479
  var _extends3, _ref4;
3542
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3480
+ var _ref3 = itemProps != null ? itemProps : {},
3543
3481
  itemProp = _ref3.item,
3544
3482
  indexProp = _ref3.index,
3545
3483
  _ref3$refKey = _ref3.refKey,
@@ -3567,7 +3505,7 @@
3567
3505
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
3568
3506
  return;
3569
3507
  }
3570
- shouldScrollRef.current = false;
3508
+ preventScroll();
3571
3509
  dispatch({
3572
3510
  type: ItemMouseMove,
3573
3511
  index: index,
@@ -3586,21 +3524,22 @@
3586
3524
 
3587
3525
  return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3588
3526
  if (itemNode) {
3589
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
3527
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
3590
3528
  }
3591
3529
  }), _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), {
3592
3530
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3593
3531
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3594
3532
  }, rest);
3595
- }, [dispatch, elementIds, latest, mouseAndTouchTrackers, shouldScrollRef]);
3596
- var getToggleButtonProps = React.useCallback(function (_temp4) {
3533
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
3534
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
3597
3535
  var _extends4;
3598
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3536
+ var _ref5 = toggleButtonProps != null ? toggleButtonProps : {},
3599
3537
  onClick = _ref5.onClick;
3600
3538
  _ref5.onPress;
3601
3539
  var _ref5$refKey = _ref5.refKey,
3602
3540
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3603
3541
  ref = _ref5.ref,
3542
+ disabled = _ref5.disabled,
3604
3543
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
3605
3544
  var latestState = latest.current.state;
3606
3545
  var toggleButtonHandleClick = function toggleButtonHandleClick() {
@@ -3610,13 +3549,17 @@
3610
3549
  };
3611
3550
  return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3612
3551
  toggleButtonRef.current = toggleButtonNode;
3613
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
3552
+ }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, {
3614
3553
  onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3615
- }), rest);
3554
+ }), {
3555
+ disabled: disabled
3556
+ }, rest);
3616
3557
  }, [dispatch, latest, elementIds]);
3617
- var getInputProps = React.useCallback(function (_temp5, _temp6) {
3558
+ var getInputProps = React.useCallback(function (inputProps, otherProps) {
3618
3559
  var _extends5;
3619
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3560
+ var _ref6 = inputProps != null ? inputProps : {},
3561
+ ariaLabel = _ref6['aria-label'],
3562
+ disabled = _ref6.disabled,
3620
3563
  onKeyDown = _ref6.onKeyDown,
3621
3564
  onChange = _ref6.onChange,
3622
3565
  onInput = _ref6.onInput,
@@ -3627,15 +3570,16 @@
3627
3570
  refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3628
3571
  ref = _ref6.ref,
3629
3572
  rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
3630
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3573
+ var _ref7 = otherProps != null ? otherProps : {},
3631
3574
  _ref7$suppressRefErro = _ref7.suppressRefError,
3632
3575
  suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3633
3576
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3634
3577
  var latestState = latest.current.state;
3635
3578
  var inputHandleKeyDown = function inputHandleKeyDown(event) {
3636
3579
  var key = normalizeArrowKey(event);
3637
- if (key && inputKeyDownHandlers[key]) {
3638
- inputKeyDownHandlers[key](event);
3580
+ if (key && key in inputKeyDownHandlers) {
3581
+ var validKey = key;
3582
+ inputKeyDownHandlers[validKey](event);
3639
3583
  }
3640
3584
  };
3641
3585
  var inputHandleChange = function inputHandleChange(event) {
@@ -3663,13 +3607,13 @@
3663
3607
  /* istanbul ignore next (preact) */
3664
3608
  var onChangeKey = 'onInput' ;
3665
3609
  var eventHandlers = {};
3666
- if (!rest.disabled) {
3610
+ if (!disabled) {
3667
3611
  var _eventHandlers;
3668
3612
  eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
3669
3613
  }
3670
3614
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3671
3615
  inputRef.current = inputNode;
3672
- }), _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);
3616
+ }), _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);
3673
3617
  }, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
3674
3618
 
3675
3619
  // returns
@@ -3739,31 +3683,6 @@
3739
3683
  selectedItems: []
3740
3684
  };
3741
3685
 
3742
- /**
3743
- * Returns the initial value for a state key in the following order:
3744
- * 1. controlled prop, 2. initial prop, 3. default prop, 4. default
3745
- * value from Downshift.
3746
- *
3747
- * @param {Object} props Props passed to the hook.
3748
- * @param {string} propKey Props key to generate the value for.
3749
- * @returns {any} The initial value for that prop.
3750
- */
3751
- function getInitialValue(props, propKey) {
3752
- return getInitialValue$1(props, propKey, defaultStateValues);
3753
- }
3754
-
3755
- /**
3756
- * Returns the default value for a state key in the following order:
3757
- * 1. controlled prop, 2. default prop, 3. default value from Downshift.
3758
- *
3759
- * @param {Object} props Props passed to the hook.
3760
- * @param {string} propKey Props key to generate the value for.
3761
- * @returns {any} The initial value for that prop.
3762
- */
3763
- function getDefaultValue(props, propKey) {
3764
- return getDefaultValue$1(props, propKey, defaultStateValues);
3765
- }
3766
-
3767
3686
  /**
3768
3687
  * Gets the initial state based on the provided props. It uses initial, default
3769
3688
  * and controlled props related to state in order to compute the initial value.
@@ -3772,8 +3691,8 @@
3772
3691
  * @returns {Object} The initial state.
3773
3692
  */
3774
3693
  function getInitialState$1(props) {
3775
- var activeIndex = getInitialValue(props, 'activeIndex');
3776
- var selectedItems = getInitialValue(props, 'selectedItems');
3694
+ var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
3695
+ var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
3777
3696
  return {
3778
3697
  activeIndex: activeIndex,
3779
3698
  selectedItems: selectedItems
@@ -3817,9 +3736,9 @@
3817
3736
  return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
3818
3737
  }
3819
3738
  var propTypes$1 = {
3820
- stateReducer: propTypes$4.stateReducer,
3821
- itemToKey: propTypes$4.itemToKey,
3822
- environment: propTypes$4.environment,
3739
+ stateReducer: dropdownPropTypes.stateReducer,
3740
+ itemToKey: dropdownPropTypes.itemToKey,
3741
+ environment: dropdownPropTypes.environment,
3823
3742
  selectedItems: PropTypes.array,
3824
3743
  initialSelectedItems: PropTypes.array,
3825
3744
  defaultSelectedItems: PropTypes.array,
@@ -3833,9 +3752,9 @@
3833
3752
  keyNavigationPrevious: PropTypes.string
3834
3753
  };
3835
3754
  var defaultProps = {
3836
- itemToKey: defaultProps$3.itemToKey,
3837
- stateReducer: defaultProps$3.stateReducer,
3838
- environment: defaultProps$3.environment,
3755
+ itemToKey: dropdownDefaultProps.itemToKey,
3756
+ stateReducer: dropdownDefaultProps.stateReducer,
3757
+ environment: dropdownDefaultProps.environment,
3839
3758
  keyNavigationNext: 'ArrowRight',
3840
3759
  keyNavigationPrevious: 'ArrowLeft'
3841
3760
  };
@@ -3881,10 +3800,11 @@
3881
3800
  });
3882
3801
 
3883
3802
  /* eslint-disable complexity */
3884
- function downshiftMultipleSelectionReducer(state, props, action) {
3803
+ function downshiftMultipleSelectionReducer(state, action) {
3885
3804
  var type = action.type,
3886
3805
  index = action.index,
3887
- selectedItem = action.selectedItem;
3806
+ selectedItem = action.selectedItem,
3807
+ props = action.props;
3888
3808
  var activeIndex = state.activeIndex,
3889
3809
  selectedItems = state.selectedItems;
3890
3810
  var changes;
@@ -3981,8 +3901,8 @@
3981
3901
  }
3982
3902
  case FunctionReset:
3983
3903
  changes = {
3984
- activeIndex: getDefaultValue(props, 'activeIndex'),
3985
- selectedItems: getDefaultValue(props, 'selectedItems')
3904
+ activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
3905
+ selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
3986
3906
  };
3987
3907
  break;
3988
3908
  default:
@@ -4214,7 +4134,7 @@
4214
4134
  TagRemoveClick: TagRemoveClick
4215
4135
  });
4216
4136
 
4217
- function useTagGroupReducer(state, _props, action) {
4137
+ function useTagGroupReducer(state, action) {
4218
4138
  var type = action.type;
4219
4139
  var changes;
4220
4140
  switch (type) {
@@ -4275,8 +4195,9 @@
4275
4195
  return _extends({}, state, changes);
4276
4196
  }
4277
4197
 
4278
- // eslint-disable-next-line @typescript-eslint/dot-notation
4279
- var reactUseId = React__namespace['useId'];
4198
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
4199
+ var SafeReact = _extends({}, React__namespace);
4200
+ var reactUseId = SafeReact.useId;
4280
4201
 
4281
4202
  // istanbul ignore next
4282
4203
  var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
@@ -4451,7 +4372,7 @@
4451
4372
  'aria-atomic': 'false',
4452
4373
  'aria-relevant': 'additions',
4453
4374
  role: 'listbox',
4454
- onKeyDown: callAllEventHandlers$1(onKeyDown, handleKeyDown)
4375
+ onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
4455
4376
  }, rest);
4456
4377
  return tagGroupProps;
4457
4378
  }, [dispatch, elementIds.tagGroupId]);
@@ -4476,11 +4397,11 @@
4476
4397
  var tagId = elementIds.getTagId(index);
4477
4398
  return _extends((_extends2 = {
4478
4399
  'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
4479
- }, _extends2[refKey] = handleRefs$1(ref, function (itemNode) {
4400
+ }, _extends2[refKey] = handleRefs(ref, function (itemNode) {
4480
4401
  if (itemNode) {
4481
4402
  itemRefs.current[tagId] = itemNode;
4482
4403
  }
4483
- }), _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);
4404
+ }), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
4484
4405
  }, [dispatch, elementIds, latest, itemRefs]);
4485
4406
  var getTagRemoveProps = React.useCallback(function (options) {
4486
4407
  var index = options.index,
@@ -4502,7 +4423,7 @@
4502
4423
  id: tagRemoveId,
4503
4424
  tabIndex: -1,
4504
4425
  'aria-labelledby': tagRemoveId + " " + tagId,
4505
- onClick: callAllEventHandlers$1(onClick, handleClick)
4426
+ onClick: callAllEventHandlers(onClick, handleClick)
4506
4427
  }, rest);
4507
4428
  }, [elementIds, dispatch]);
4508
4429