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
@@ -101,7 +101,7 @@ function useLatestRef(val) {
101
101
  return ref;
102
102
  }
103
103
 
104
- function handleRefs$1() {
104
+ function handleRefs() {
105
105
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
106
106
  refs[_key] = arguments[_key];
107
107
  }
@@ -123,7 +123,7 @@ function handleRefs$1() {
123
123
  * @param fns the event handler functions
124
124
  * @return the event handler to add to an element
125
125
  */
126
- function callAllEventHandlers$1() {
126
+ function callAllEventHandlers() {
127
127
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
128
128
  fns[_key] = arguments[_key];
129
129
  }
@@ -145,7 +145,7 @@ function callAllEventHandlers$1() {
145
145
  * function once after the time given has passed since
146
146
  * it was last called.
147
147
  */
148
- function debounce$1(fn, time) {
148
+ function debounce(fn, time) {
149
149
  var timeoutId;
150
150
  function cancel() {
151
151
  if (timeoutId) {
@@ -166,7 +166,7 @@ function debounce$1(fn, time) {
166
166
  return wrapper;
167
167
  }
168
168
 
169
- var cleanupStatus = debounce$1(function (document) {
169
+ var cleanupStatus = debounce(function (document) {
170
170
  getStatusDiv(document).textContent = '';
171
171
  }, 500);
172
172
 
@@ -247,6 +247,8 @@ function getState(state, props) {
247
247
  }
248
248
  var keys = Object.keys(state);
249
249
  return keys.reduce(function (newState, key) {
250
+ // state keys could be in props, but with value undefined, which means they should be ignored.
251
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
250
252
  if (props[key] !== undefined) {
251
253
  newState[key] = props[key];
252
254
  }
@@ -278,93 +280,149 @@ function scrollIntoView(node, menuNode) {
278
280
  }
279
281
 
280
282
  /**
281
- * Accepts a parameter and returns it if it's a function
282
- * or a noop function if it's not. This allows us to
283
- * accept a callback, but not worry about it if it's not
284
- * passed.
285
- * @param {Function} cb the callback
286
- * @return {Function} a function
287
- */
288
- function cbToCb(cb) {
289
- return typeof cb === 'function' ? cb : noop;
290
- }
291
-
292
- /**
293
- * @param {HTMLElement} parent the parent node
294
- * @param {HTMLElement} child the child node
295
- * @param {Window} environment The window context where downshift renders.
296
- * @return {Boolean} whether the parent is the child or the child is in the parent
283
+ * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
284
+ * @param event a keyboardEvent object
285
+ * @return keyboard key
297
286
  */
298
- function isOrContainsNode(parent, child, environment) {
299
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
300
- return result;
287
+ function normalizeArrowKey(event) {
288
+ var key = event.key,
289
+ keyCode = event.keyCode;
290
+ /* istanbul ignore next (ie) */
291
+ if (keyCode >= 37 && keyCode <= 40 && !key.startsWith('Arrow')) {
292
+ return "Arrow" + key;
293
+ }
294
+ return key;
301
295
  }
302
296
 
303
297
  /**
304
- * Simple debounce implementation. Will call the given
305
- * function once after the time given has passed since
306
- * it was last called.
307
- * @param {Function} fn the function to call after the time
308
- * @param {Number} time the time to wait
309
- * @return {Function} the debounced function
298
+ * Returns the next non-disabled highlightedIndex value.
299
+ *
300
+ * @param start The current highlightedIndex.
301
+ * @param backwards If true, it will search backwards from the start.
302
+ * @param items The items array.
303
+ * @param isItemDisabled Function that tells if an item is disabled or not.
304
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
305
+ * @returns The next non-disabled index.
310
306
  */
311
- function debounce(fn, time) {
312
- var timeoutId;
313
- function cancel() {
314
- if (timeoutId) {
315
- clearTimeout(timeoutId);
316
- }
307
+ function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
308
+ if (circular === void 0) {
309
+ circular = false;
317
310
  }
318
- function wrapper() {
319
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
320
- args[_key] = arguments[_key];
311
+ var count = items.length;
312
+ if (backwards) {
313
+ for (var index = start; index >= 0; index--) {
314
+ if (!isItemDisabled(items[index], index)) {
315
+ return index;
316
+ }
317
+ }
318
+ } else {
319
+ for (var _index = start; _index < count; _index++) {
320
+ if (!isItemDisabled(items[_index], _index)) {
321
+ return _index;
322
+ }
321
323
  }
322
- cancel();
323
- timeoutId = setTimeout(function () {
324
- timeoutId = null;
325
- fn.apply(void 0, args);
326
- }, time);
327
324
  }
328
- wrapper.cancel = cancel;
329
- return wrapper;
325
+ if (circular) {
326
+ return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
327
+ }
328
+ return -1;
330
329
  }
331
330
 
332
331
  /**
333
- * This is intended to be used to compose event handlers.
334
- * They are executed in order until one of them sets
335
- * `event.preventDownshiftDefault = true`.
336
- * @param {...Function} fns the event handler functions
337
- * @return {Function} the event handler to add to an element
332
+ * Returns the next non-disabled highlightedIndex value.
333
+ *
334
+ * @param start The current highlightedIndex.
335
+ * @param offset The offset from the current highlightedIndex to start searching.
336
+ * @param items The items array.
337
+ * @param isItemDisabled Function that tells if an item is disabled or not.
338
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
339
+ * @returns The next highlightedIndex.
338
340
  */
339
- function callAllEventHandlers() {
340
- for (var _len2 = arguments.length, fns = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
341
- fns[_key2] = arguments[_key2];
341
+ function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
342
+ if (circular === void 0) {
343
+ circular = false;
342
344
  }
343
- return function (event) {
344
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
345
- args[_key3 - 1] = arguments[_key3];
346
- }
347
- return fns.some(function (fn) {
348
- if (fn) {
349
- fn.apply(void 0, [event].concat(args));
345
+ var count = items.length;
346
+ if (count === 0) {
347
+ return -1;
348
+ }
349
+ var itemsLastIndex = count - 1;
350
+ if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
351
+ start = offset > 0 ? -1 : itemsLastIndex + 1;
352
+ }
353
+ var current = start + offset;
354
+ if (current < 0) {
355
+ current = circular ? itemsLastIndex : 0;
356
+ } else if (current > itemsLastIndex) {
357
+ current = circular ? 0 : itemsLastIndex;
358
+ }
359
+ var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
360
+ if (highlightedIndex === -1) {
361
+ return start >= count ? -1 : start;
362
+ }
363
+ return highlightedIndex;
364
+ }
365
+
366
+ /* eslint-disable @typescript-eslint/no-explicit-any */
367
+
368
+ // eslint-disable-next-line import/no-mutable-exports
369
+ var validateControlledUnchanged = noop;
370
+ /* istanbul ignore next */
371
+ if (process.env.NODE_ENV !== 'production') {
372
+ validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
373
+ 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";
374
+ Object.keys(state).forEach(function (propKey) {
375
+ if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
376
+ // eslint-disable-next-line no-console
377
+ console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
378
+ } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
379
+ // eslint-disable-next-line no-console
380
+ console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
350
381
  }
351
- return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
352
382
  });
353
383
  };
354
384
  }
355
- function handleRefs() {
356
- for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
357
- refs[_key4] = arguments[_key4];
385
+
386
+ /**
387
+ * Checks if event target is within the downshift elements.
388
+ *
389
+ * @param target Target to check.
390
+ * @param downshiftElements The elements that form downshift (list, toggle button etc).
391
+ * @param environment The window context where downshift renders.
392
+ * @param checkActiveElement Whether to also check activeElement.
393
+ *
394
+ * @returns Whether or not the target is within downshift elements.
395
+ */
396
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
397
+ if (checkActiveElement === void 0) {
398
+ checkActiveElement = true;
358
399
  }
359
- return function (node) {
360
- refs.forEach(function (ref) {
361
- if (typeof ref === 'function') {
362
- ref(node);
363
- } else if (ref) {
364
- ref.current = node;
365
- }
366
- });
367
- };
400
+ return !!environment && downshiftElements.some(function (contextNode) {
401
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
402
+ });
403
+ }
404
+
405
+ /**
406
+ * @param parent the parent node
407
+ * @param child the child node
408
+ * @param environment The window context where downshift renders.
409
+ * @return Whether the parent is the child or the child is in the parent
410
+ */
411
+ function isOrContainsNode(parent, child, environment) {
412
+ var result = parent === child || child instanceof environment.Node && parent.contains(child);
413
+ return result;
414
+ }
415
+
416
+ /**
417
+ * Accepts a parameter and returns it if it's a function
418
+ * or a noop function if it's not. This allows us to
419
+ * accept a callback, but not worry about it if it's not
420
+ * passed.
421
+ * @param {Function} cb the callback
422
+ * @return {Function} a function
423
+ */
424
+ function cbToCb(cb) {
425
+ return typeof cb === 'function' ? cb : noop;
368
426
  }
369
427
 
370
428
  /**
@@ -453,34 +511,6 @@ function pickState(state) {
453
511
  return result;
454
512
  }
455
513
 
456
- /**
457
- * This determines whether a prop is a "controlled prop" meaning it is
458
- * state which is controlled by the outside of this component rather
459
- * than within this component.
460
- *
461
- * @param {Object} props The props that may contain controlled values.
462
- * @param {String} key the key to check
463
- * @return {Boolean} whether it is a controlled controlled prop
464
- */
465
- function isControlledProp(props, key) {
466
- return props[key] !== undefined;
467
- }
468
-
469
- /**
470
- * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
471
- * @param {Object} event a keyboardEvent object
472
- * @return {String} keyboard key
473
- */
474
- function normalizeArrowKey(event) {
475
- var key = event.key,
476
- keyCode = event.keyCode;
477
- /* istanbul ignore next (ie) */
478
- if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
479
- return "Arrow" + key;
480
- }
481
- return key;
482
- }
483
-
484
514
  /**
485
515
  * Simple check if the value passed is object literal
486
516
  * @param {*} obj any things
@@ -490,112 +520,6 @@ function isPlainObject(obj) {
490
520
  return Object.prototype.toString.call(obj) === '[object Object]';
491
521
  }
492
522
 
493
- /**
494
- * Returns the next non-disabled highlightedIndex value.
495
- *
496
- * @param {number} start The current highlightedIndex.
497
- * @param {number} offset The offset from the current highlightedIndex to start searching.
498
- * @param {unknown[]} items The items array.
499
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
500
- * @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
501
- * @returns {number} The next highlightedIndex.
502
- */
503
- function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
504
- if (circular === void 0) {
505
- circular = false;
506
- }
507
- var count = items.length;
508
- if (count === 0) {
509
- return -1;
510
- }
511
- var itemsLastIndex = count - 1;
512
- if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
513
- start = offset > 0 ? -1 : itemsLastIndex + 1;
514
- }
515
- var current = start + offset;
516
- if (current < 0) {
517
- current = circular ? itemsLastIndex : 0;
518
- } else if (current > itemsLastIndex) {
519
- current = circular ? 0 : itemsLastIndex;
520
- }
521
- var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
522
- if (highlightedIndex === -1) {
523
- return start >= count ? -1 : start;
524
- }
525
- return highlightedIndex;
526
- }
527
-
528
- /**
529
- * Returns the next non-disabled highlightedIndex value.
530
- *
531
- * @param {number} start The current highlightedIndex.
532
- * @param {boolean} backwards If true, it will search backwards from the start.
533
- * @param {unknown[]} items The items array.
534
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
535
- * @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
536
- * @returns {number} The next non-disabled index.
537
- */
538
- function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
539
- if (circular === void 0) {
540
- circular = false;
541
- }
542
- var count = items.length;
543
- if (backwards) {
544
- for (var index = start; index >= 0; index--) {
545
- if (!isItemDisabled(items[index], index)) {
546
- return index;
547
- }
548
- }
549
- } else {
550
- for (var _index = start; _index < count; _index++) {
551
- if (!isItemDisabled(items[_index], _index)) {
552
- return _index;
553
- }
554
- }
555
- }
556
- if (circular) {
557
- return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
558
- }
559
- return -1;
560
- }
561
-
562
- /**
563
- * Checks if event target is within the downshift elements.
564
- *
565
- * @param {EventTarget} target Target to check.
566
- * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
567
- * @param {Window} environment The window context where downshift renders.
568
- * @param {boolean} checkActiveElement Whether to also check activeElement.
569
- *
570
- * @returns {boolean} Whether or not the target is within downshift elements.
571
- */
572
- function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
573
- if (checkActiveElement === void 0) {
574
- checkActiveElement = true;
575
- }
576
- return environment && downshiftElements.some(function (contextNode) {
577
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
578
- });
579
- }
580
-
581
- // eslint-disable-next-line import/no-mutable-exports
582
- var validateControlledUnchanged = noop;
583
- /* istanbul ignore next */
584
- if (process.env.NODE_ENV !== 'production') {
585
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
586
- 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";
587
- Object.keys(state).forEach(function (propKey) {
588
- if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
589
- // eslint-disable-next-line no-console
590
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
591
- } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
592
- // eslint-disable-next-line no-console
593
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
594
- }
595
- });
596
- };
597
- }
598
-
599
523
  var _excluded$4 = ["refKey", "ref"],
600
524
  _excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
601
525
  _excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
@@ -746,7 +670,7 @@ var Downshift = /*#__PURE__*/function () {
746
670
  }
747
671
  newStateToSet[key];
748
672
  // if it's coming from props, then we don't care to set it internally
749
- if (!isControlledProp(_this.props, key)) {
673
+ if (_this.props[key] === undefined) {
750
674
  nextState[key] = newStateToSet[key];
751
675
  }
752
676
  });
@@ -1480,7 +1404,7 @@ var Downshift = /*#__PURE__*/function () {
1480
1404
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1481
1405
  }
1482
1406
  }
1483
- if (isControlledProp(this.props, 'selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1407
+ if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1484
1408
  this.internalSetState({
1485
1409
  type: controlledPropUpdatedSelectedItem,
1486
1410
  inputValue: this.props.itemToString(this.props.selectedItem)
@@ -1666,7 +1590,7 @@ function callOnChangeProps(action, props, state, newState) {
1666
1590
  changes[key] = newState[key];
1667
1591
  }
1668
1592
  }
1669
- if (props.onStateChange && Object.keys(changes).length) {
1593
+ if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
1670
1594
  props.onStateChange(_extends({
1671
1595
  type: type
1672
1596
  }, changes));
@@ -1692,50 +1616,53 @@ function invokeOnChangeHandler(key, action, props, state, newState) {
1692
1616
  * two reducers, one from downshift and an optional one from the user.
1693
1617
  * Also calls the onChange handlers for state values that have changed.
1694
1618
  *
1695
- * @param {Function} reducer Reducer function from downshift.
1696
- * @param {Object} props The hook props, also passed to createInitialState.
1697
- * @param {Function} createInitialState Function that returns the initial state.
1698
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1699
- * @returns {Array} An array with the state and an action dispatcher.
1619
+ * @param reducer Reducer function from downshift.
1620
+ * @param props The hook props, also passed to createInitialState.
1621
+ * @param createInitialState Function that returns the initial state.
1622
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1623
+ * @returns An array with the state and an action dispatcher.
1700
1624
  */
1701
1625
  function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
1702
- var prevStateRef = React__namespace.useRef(null);
1703
- var actionRef = React__namespace.useRef(undefined);
1704
- var propsRef = useLatestRef(props);
1626
+ var prevStateRef = React__namespace.useRef({});
1627
+ var actionRef = React__namespace.useRef();
1705
1628
  var enhancedReducer = React__namespace.useCallback(function (state, action) {
1706
1629
  actionRef.current = action;
1707
- state = getState(state, propsRef.current);
1708
- var changes = reducer(state, propsRef.current, action);
1709
- var newState = propsRef.current.stateReducer(state, _extends({}, action, {
1630
+ state = getState(state, action.props);
1631
+ var changes = reducer(state, action);
1632
+ var newState = action.props.stateReducer(state, _extends({}, action, {
1710
1633
  changes: changes
1711
1634
  }));
1712
1635
  return _extends({}, state, newState);
1713
- }, [propsRef, reducer]);
1636
+ }, [reducer]);
1714
1637
  var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
1715
1638
  state = _React$useReducer[0],
1716
1639
  dispatch = _React$useReducer[1];
1640
+ var propsRef = useLatestRef(props);
1641
+ var dispatchWithProps = React__namespace.useCallback(function (action) {
1642
+ return dispatch(_extends({}, action, {
1643
+ props: propsRef.current
1644
+ }));
1645
+ }, [propsRef]);
1717
1646
  var action = actionRef.current;
1718
1647
  React__namespace.useEffect(function () {
1719
- var _prevStateRef$current;
1720
- var prevState = getState((_prevStateRef$current = prevStateRef.current) != null ? _prevStateRef$current : {}, propsRef.current);
1721
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
1648
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
1649
+ var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
1722
1650
  if (shouldCallOnChangeProps) {
1723
- callOnChangeProps(action, propsRef.current, prevState, state);
1651
+ callOnChangeProps(action, action.props, prevState, state);
1724
1652
  }
1725
1653
  prevStateRef.current = state;
1726
- }, [state, action, isStateEqual, propsRef]);
1727
- return [state, dispatch];
1654
+ }, [state, action, isStateEqual]);
1655
+ return [state, dispatchWithProps];
1728
1656
  }
1729
1657
 
1730
1658
  /**
1731
1659
  * Wraps the useEnhancedReducer and applies the controlled prop values before
1732
1660
  * returning the new state.
1733
- *
1734
- * @param {Function} reducer Reducer function from downshift.
1735
- * @param {Object} props The hook props, also passed to createInitialState.
1736
- * @param {Function} createInitialState Function that returns the initial state.
1737
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1738
- * @returns {Array} An array with the state and an action dispatcher.
1661
+ * @param reducer Reducer function from downshift.
1662
+ * @param props The hook props, also passed to createInitialState.
1663
+ * @param createInitialState Function that returns the initial state.
1664
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1665
+ * @returns An array with the state and an action dispatcher.
1739
1666
  */
1740
1667
  function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
1741
1668
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
@@ -1788,16 +1715,8 @@ function useIsInitialMount() {
1788
1715
  return isInitialMountRef.current;
1789
1716
  }
1790
1717
 
1791
- /**
1792
- * Default state reducer that returns the changes.
1793
- *
1794
- */
1795
- function stateReducer(_s, a) {
1796
- return a.changes;
1797
- }
1798
-
1799
1718
  // Shared between all exports.
1800
- var propTypes$5 = {
1719
+ var propTypes$4 = {
1801
1720
  environment: PropTypes.shape({
1802
1721
  addEventListener: PropTypes.func.isRequired,
1803
1722
  removeEventListener: PropTypes.func.isRequired,
@@ -1813,30 +1732,47 @@ var propTypes$5 = {
1813
1732
  stateReducer: PropTypes.func
1814
1733
  };
1815
1734
 
1816
- function getDefaultValue$1(props, propKey, defaultStateValues) {
1817
- var defaultValue = props["default" + capitalizeString(propKey)];
1818
- if (defaultValue !== undefined) {
1819
- return defaultValue;
1820
- }
1821
- return defaultStateValues[propKey];
1735
+ /**
1736
+ * Returns the default value based on the defaultProp and defaultStateValue.
1737
+ *
1738
+ * @param defaultProp The default prop value.
1739
+ * @param defaultStateValue The default state value.
1740
+ * @returns The resolved default value.
1741
+ */
1742
+ function getDefaultValue(defaultProp, defaultStateValue) {
1743
+ return defaultProp === undefined ? defaultStateValue : defaultProp;
1822
1744
  }
1823
1745
 
1824
- function getInitialValue$1(props, propKey, defaultStateValues) {
1825
- var value = props[propKey];
1746
+ /**
1747
+ * Returns the initial value for a state variable, based on the following precedence:
1748
+ * 1. The controlled value (if it's not undefined)
1749
+ * 2. The initialValue (if it's not undefined)
1750
+ * 3. The defaultValue (if it's not undefined)
1751
+ * 4. The defaultStateValue
1752
+ *
1753
+ * @param value The controlled value of the state variable.
1754
+ * @param initialValue The initial value of the state variable.
1755
+ * @param defaultValue The default value of the state variable.
1756
+ * @param defaultStateValue The default state value to use if all other values are undefined.
1757
+ * @returns The initial value for the state variable.
1758
+ */
1759
+ function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
1826
1760
  if (value !== undefined) {
1827
1761
  return value;
1828
1762
  }
1829
- var initialValue = props["initial" + capitalizeString(propKey)];
1830
1763
  if (initialValue !== undefined) {
1831
1764
  return initialValue;
1832
1765
  }
1833
- return getDefaultValue$1(props, propKey, defaultStateValues);
1766
+ if (defaultValue !== undefined) {
1767
+ return defaultValue;
1768
+ }
1769
+ return defaultStateValue;
1834
1770
  }
1835
1771
 
1836
1772
  /**
1837
1773
  * Debounced call for updating the a11y message.
1838
1774
  */
1839
- var updateA11yStatus = debounce$1(function (status, document) {
1775
+ var updateA11yStatus = debounce(function (status, document) {
1840
1776
  setStatus(status, document);
1841
1777
  }, 200);
1842
1778
 
@@ -1872,7 +1808,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
1872
1808
  }
1873
1809
 
1874
1810
  // Shared between useSelect, useCombobox, Downshift.
1875
- var propTypes$4 = _extends({}, propTypes$5, {
1811
+ var dropdownPropTypes = _extends({}, propTypes$4, {
1876
1812
  getA11yStatusMessage: PropTypes.func,
1877
1813
  highlightedIndex: PropTypes.number,
1878
1814
  defaultHighlightedIndex: PropTypes.number,
@@ -1895,62 +1831,145 @@ var propTypes$4 = _extends({}, propTypes$5, {
1895
1831
  scrollIntoView: PropTypes.func
1896
1832
  });
1897
1833
 
1898
- var defaultProps$3 = {
1834
+ var dropdownDefaultProps = {
1899
1835
  itemToString: function itemToString(item) {
1900
1836
  return item ? String(item) : '';
1901
1837
  },
1902
1838
  itemToKey: function itemToKey(item) {
1903
1839
  return item;
1904
1840
  },
1905
- stateReducer: stateReducer,
1841
+ isItemDisabled: function isItemDisabled(_item) {
1842
+ return false;
1843
+ },
1844
+ stateReducer: function stateReducer(_state, actionAndChanges) {
1845
+ return actionAndChanges.changes;
1846
+ },
1906
1847
  scrollIntoView: scrollIntoView,
1907
1848
  environment: /* istanbul ignore next (ssr) */
1908
1849
  typeof window === 'undefined' || false ? undefined : window
1909
1850
  };
1910
1851
 
1911
- var defaultStateValues$1 = {
1852
+ var dropdownDefaultStateValues = {
1912
1853
  highlightedIndex: -1,
1913
1854
  isOpen: false,
1914
1855
  selectedItem: null,
1915
1856
  inputValue: ''
1916
1857
  };
1917
1858
 
1918
- // istanbul ignore next
1919
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
1920
- function isAcceptedCharacterKey(key) {
1921
- return /^\S{1}$/.test(key);
1859
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
1860
+ var SafeReact$1 = _extends({}, React__namespace);
1861
+ var reactUseId$1 = SafeReact$1.useId;
1862
+ var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
1863
+ function useElementIdsR18$1(_ref) {
1864
+ var id = _ref.id,
1865
+ labelId = _ref.labelId,
1866
+ menuId = _ref.menuId,
1867
+ getItemId = _ref.getItemId,
1868
+ toggleButtonId = _ref.toggleButtonId,
1869
+ inputId = _ref.inputId;
1870
+ var reactId = "downshift-" + reactUseId$1();
1871
+ if (!id) {
1872
+ id = reactId;
1873
+ }
1874
+ var elementIds = React__namespace.useMemo(function () {
1875
+ return {
1876
+ labelId: labelId != null ? labelId : id + "-label",
1877
+ menuId: menuId != null ? menuId : id + "-menu",
1878
+ getItemId: getItemId != null ? getItemId : function (index) {
1879
+ return id + "-item-" + index;
1880
+ },
1881
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
1882
+ inputId: inputId != null ? inputId : id + "-input"
1883
+ };
1884
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1885
+ return elementIds;
1922
1886
  }
1923
- function getInitialState$3(props) {
1924
- var selectedItem = getInitialValue$1(props, 'selectedItem', defaultStateValues$1);
1925
- var isOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
1926
- var highlightedIndex = getInitialHighlightedIndex(props);
1927
- var inputValue = getInitialValue$1(props, 'inputValue', defaultStateValues$1);
1928
- return {
1929
- highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1930
- return props.itemToKey(item) === props.itemToKey(selectedItem);
1931
- }) : highlightedIndex,
1932
- isOpen: isOpen,
1933
- selectedItem: selectedItem,
1934
- inputValue: inputValue
1935
- };
1887
+ function useElementIdsLegacy$1(_ref2) {
1888
+ var id = _ref2.id,
1889
+ labelId = _ref2.labelId,
1890
+ menuId = _ref2.menuId,
1891
+ getItemId = _ref2.getItemId,
1892
+ toggleButtonId = _ref2.toggleButtonId,
1893
+ inputId = _ref2.inputId;
1894
+ var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
1895
+ var baseId = baseIdRef.current;
1896
+ var elementIds = React__namespace.useMemo(function () {
1897
+ return {
1898
+ labelId: labelId != null ? labelId : baseId + "-label",
1899
+ menuId: menuId != null ? menuId : baseId + "-menu",
1900
+ getItemId: getItemId != null ? getItemId : function (index) {
1901
+ return baseId + "-item-" + index;
1902
+ },
1903
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
1904
+ inputId: inputId != null ? inputId : baseId + "-input"
1905
+ };
1906
+ }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
1907
+ return elementIds;
1936
1908
  }
1937
- function getHighlightedIndexOnOpen(props, state, offset) {
1938
- var items = props.items,
1939
- initialHighlightedIndex = props.initialHighlightedIndex,
1940
- defaultHighlightedIndex = props.defaultHighlightedIndex,
1941
- isItemDisabled = props.isItemDisabled,
1942
- itemToKey = props.itemToKey;
1943
- var selectedItem = state.selectedItem,
1944
- highlightedIndex = state.highlightedIndex;
1909
+
1910
+ /**
1911
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
1912
+ *
1913
+ * @param props Props passed to the hook.
1914
+ * @returns The highlighted index.
1915
+ */
1916
+ function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
1917
+ var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
1918
+ if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
1919
+ return -1;
1920
+ }
1921
+ return highlightedIndex;
1922
+ }
1923
+
1924
+ /**
1925
+ * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
1926
+ * In that case, selects the item and resets to defaults for open state and highlighted idex.
1927
+ *
1928
+ * @param props The Dropdown props.
1929
+ * @param highlightedIndex The index from the state.
1930
+ * @param inputValue Also return the input value for state.
1931
+ * @returns The changes for the state.
1932
+ */
1933
+ function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
1934
+ var shouldSelect = items.length && highlightedIndex >= 0;
1935
+ return _extends({
1936
+ isOpen: false,
1937
+ highlightedIndex: -1
1938
+ }, shouldSelect && _extends({
1939
+ selectedItem: items[highlightedIndex],
1940
+ isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
1941
+ highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
1942
+ }, inputValue && {
1943
+ inputValue: itemToString(items[highlightedIndex])
1944
+ }));
1945
+ }
1946
+
1947
+ /* eslint-disable max-params */
1948
+ /**
1949
+ * Returns the highlighted index when the menu is opened.
1950
+ * Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
1951
+ * selectedItem, and the open direction offset.
1952
+ *
1953
+ * @param items The list of items.
1954
+ * @param initialHighlightedIndex The initial highlighted index prop.
1955
+ * @param defaultHighlightedIndex The default highlighted index prop.
1956
+ * @param isItemDisabled Callback to determine if an item is disabled.
1957
+ * @param itemToKey Callback to get a unique key from an item.
1958
+ * @param selectedItem The currently selected item.
1959
+ * @param highlightedIndex The current highlighted index from state.
1960
+ * @param offset The direction of navigation: positive opens downward, negative opens upward.
1961
+ * @returns The new highlighted index.
1962
+ */
1963
+ function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
1945
1964
  if (items.length === 0) {
1946
1965
  return -1;
1947
1966
  }
1948
1967
 
1949
1968
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
1950
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1969
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1951
1970
  return initialHighlightedIndex;
1952
1971
  }
1953
- if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1972
+ if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1954
1973
  return defaultHighlightedIndex;
1955
1974
  }
1956
1975
  if (selectedItem) {
@@ -1958,21 +1977,71 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1958
1977
  return itemToKey(selectedItem) === itemToKey(item);
1959
1978
  });
1960
1979
  }
1961
- if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1980
+ if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1962
1981
  return items.length - 1;
1963
1982
  }
1964
- if (offset > 0 && !isItemDisabled(items[0], 0)) {
1983
+ if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
1965
1984
  return 0;
1966
1985
  }
1967
1986
  return -1;
1968
1987
  }
1988
+
1989
+ function getInitialState$3(props) {
1990
+ var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
1991
+ var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
1992
+ var highlightedIndex = getInitialHighlightedIndex(props);
1993
+ var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
1994
+ return {
1995
+ highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1996
+ return props.itemToKey(item) === props.itemToKey(selectedItem);
1997
+ }) : highlightedIndex,
1998
+ isOpen: isOpen,
1999
+ selectedItem: selectedItem,
2000
+ inputValue: inputValue
2001
+ };
2002
+ }
2003
+
2004
+ /**
2005
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2006
+ * @param props Props from useCombobox or useSelect.
2007
+ * @returns The highlighted index.
2008
+ */
2009
+ function getInitialHighlightedIndex(props) {
2010
+ var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
2011
+ if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2012
+ return -1;
2013
+ }
2014
+ return highlightedIndex;
2015
+ }
2016
+
2017
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2018
+ // eslint-disable-next-line import/no-mutable-exports
2019
+ var useControlPropsValidator = noop;
2020
+ /* istanbul ignore next */
2021
+ if (process.env.NODE_ENV !== 'production') {
2022
+ useControlPropsValidator = function useControlPropsValidator(_ref) {
2023
+ var props = _ref.props,
2024
+ state = _ref.state;
2025
+ // used for checking when props are moving from controlled to uncontrolled.
2026
+ var prevPropsRef = React__namespace.useRef(props);
2027
+ var isInitialMount = useIsInitialMount();
2028
+ React__namespace.useEffect(function () {
2029
+ if (isInitialMount) {
2030
+ return;
2031
+ }
2032
+ validateControlledUnchanged(state, prevPropsRef.current, props);
2033
+ prevPropsRef.current = props;
2034
+ }, [state, props, isInitialMount]);
2035
+ };
2036
+ }
2037
+
1969
2038
  /**
1970
2039
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
1971
2040
  *
1972
- * @param {Window} environment The environment to add the event listeners to, for instance window.
1973
- * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1974
- * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
1975
- * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
2041
+ * @param environment The environment to add the event listeners to, for instance window.
2042
+ * @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
2043
+ * @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
2044
+ * @returns The mouse and touch events information.
1976
2045
  */
1977
2046
  function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
1978
2047
  var mouseAndTouchTrackersRef = React__namespace.useRef({
@@ -2036,8 +2105,8 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2036
2105
  /**
2037
2106
  * Custom hook that checks if getter props are called correctly.
2038
2107
  *
2039
- * @param {...any} propKeys Getter prop names to be handled.
2040
- * @returns {Function} Setter function called inside getter props to set call information.
2108
+ * @param propKeys Getter prop names to be handled.
2109
+ * @returns Setter function called inside getter props to set call information.
2041
2110
  */
2042
2111
  /* istanbul ignore next */
2043
2112
  if (process.env.NODE_ENV !== 'production') {
@@ -2073,120 +2142,58 @@ if (process.env.NODE_ENV !== 'production') {
2073
2142
  getterPropsCalledRef.current[propKey] = {
2074
2143
  suppressRefError: suppressRefError,
2075
2144
  refKey: refKey,
2076
- elementRef: elementRef
2077
- };
2078
- }, []);
2079
- return setGetterPropCallInfo;
2080
- };
2081
- }
2082
- function useScrollIntoView(_ref) {
2083
- var highlightedIndex = _ref.highlightedIndex,
2084
- isOpen = _ref.isOpen,
2085
- itemRefs = _ref.itemRefs,
2086
- getItemNodeFromIndex = _ref.getItemNodeFromIndex,
2087
- menuElement = _ref.menuElement,
2088
- scrollIntoViewProp = _ref.scrollIntoView;
2089
- // used not to scroll on highlight by mouse.
2090
- var shouldScrollRef = React__namespace.useRef(true);
2091
- // Scroll on highlighted item if change comes from keyboard.
2092
- useIsomorphicLayoutEffect(function () {
2093
- if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2094
- return;
2095
- }
2096
- if (shouldScrollRef.current === false) {
2097
- shouldScrollRef.current = true;
2098
- } else {
2099
- scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
2100
- }
2101
- // eslint-disable-next-line react-hooks/exhaustive-deps
2102
- }, [highlightedIndex]);
2103
- return shouldScrollRef;
2104
- }
2105
-
2106
- // eslint-disable-next-line import/no-mutable-exports
2107
- var useControlPropsValidator = noop;
2108
- /* istanbul ignore next */
2109
- if (process.env.NODE_ENV !== 'production') {
2110
- useControlPropsValidator = function useControlPropsValidator(_ref2) {
2111
- var props = _ref2.props,
2112
- state = _ref2.state;
2113
- // used for checking when props are moving from controlled to uncontrolled.
2114
- var prevPropsRef = React__namespace.useRef(props);
2115
- var isInitialMount = useIsInitialMount();
2116
- React__namespace.useEffect(function () {
2117
- if (isInitialMount) {
2118
- return;
2119
- }
2120
- validateControlledUnchanged(state, prevPropsRef.current, props);
2121
- prevPropsRef.current = props;
2122
- }, [state, props, isInitialMount]);
2123
- };
2124
- }
2125
-
2126
- /**
2127
- * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
2128
- * In that case, selects the item and resets to defaults for open state and highlighted idex.
2129
- * @param {Object} props The useCombobox props.
2130
- * @param {number} highlightedIndex The index from the state.
2131
- * @param {boolean} inputValue Also return the input value for state.
2132
- * @returns The changes for the state.
2133
- */
2134
- function getChangesOnSelection(props, highlightedIndex, inputValue) {
2135
- var _props$items;
2136
- if (inputValue === void 0) {
2137
- inputValue = true;
2138
- }
2139
- var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
2140
- return _extends({
2141
- isOpen: false,
2142
- highlightedIndex: -1
2143
- }, shouldSelect && _extends({
2144
- selectedItem: props.items[highlightedIndex],
2145
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2146
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
2147
- }, inputValue && {
2148
- inputValue: props.itemToString(props.items[highlightedIndex])
2149
- }));
2150
- }
2151
-
2152
- /**
2153
- * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2154
- * Used by useSelect and useCombobox.
2155
- *
2156
- * @param {Object} prevState
2157
- * @param {Object} newState
2158
- * @returns {boolean} Wheather the states are deeply equal.
2159
- */
2160
- function isDropdownsStateEqual(prevState, newState) {
2161
- return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2145
+ elementRef: elementRef
2146
+ };
2147
+ }, []);
2148
+ return setGetterPropCallInfo;
2149
+ };
2162
2150
  }
2163
2151
 
2152
+ // istanbul ignore next
2153
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2154
+
2164
2155
  /**
2165
- * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2166
- *
2167
- * @param {Object} props Props from useCombobox or useSelect.
2168
- * @returns {number} The highlighted index.
2156
+ * Utility hook that scrolls an item from a menu into view.
2157
+ * @param scrollIntoView The function that does the scroll.
2158
+ * @param highlightedIndex The index of the item that should be scrolled.
2159
+ * @param isOpen If the menu is open or not.
2160
+ * @param menuElement The menu element.
2161
+ * @param itemElements The object containing item elements.
2162
+ * @param getItemId The function to get the item id from index.
2163
+ * @returns Function that when called prevents the scroll.
2169
2164
  */
2170
- function getDefaultHighlightedIndex(props) {
2171
- var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
2172
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2173
- return -1;
2174
- }
2175
- return highlightedIndex;
2165
+ function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
2166
+ // used not to scroll on highlight by mouse.
2167
+ var shouldScrollRef = React__namespace.useRef(true);
2168
+ // Scroll on highlighted item if change comes from keyboard.
2169
+ useIsomorphicLayoutEffect(function () {
2170
+ if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
2171
+ return;
2172
+ }
2173
+ if (shouldScrollRef.current) {
2174
+ var itemElement = itemElements[getItemId(highlightedIndex)];
2175
+ if (itemElement && menuElement) {
2176
+ scrollIntoView(itemElement, menuElement);
2177
+ }
2178
+ } else {
2179
+ shouldScrollRef.current = true;
2180
+ }
2181
+ }, [highlightedIndex]);
2182
+ return React__namespace.useCallback(function preventScroll() {
2183
+ shouldScrollRef.current = false;
2184
+ }, []);
2176
2185
  }
2177
2186
 
2178
2187
  /**
2179
- * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2188
+ * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2189
+ * Used by useSelect and useCombobox.
2180
2190
  *
2181
- * @param {Object} props Props from useCombobox or useSelect.
2182
- * @returns {number} The highlighted index.
2191
+ * @param prevState The previous dropdown state.
2192
+ * @param newState The new dropdown state.
2193
+ * @returns Wheather the states are deeply equal.
2183
2194
  */
2184
- function getInitialHighlightedIndex(props) {
2185
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
2186
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2187
- return -1;
2188
- }
2189
- return highlightedIndex;
2195
+ function isDropdownStateEqual(prevState, newState) {
2196
+ return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2190
2197
  }
2191
2198
 
2192
2199
  function downshiftCommonReducer(state, props, action, stateChangeTypes) {
@@ -2207,13 +2214,13 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2207
2214
  case stateChangeTypes.FunctionToggleMenu:
2208
2215
  changes = {
2209
2216
  isOpen: !state.isOpen,
2210
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
2217
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2211
2218
  };
2212
2219
  break;
2213
2220
  case stateChangeTypes.FunctionOpenMenu:
2214
2221
  changes = {
2215
2222
  isOpen: true,
2216
- highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
2223
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2217
2224
  };
2218
2225
  break;
2219
2226
  case stateChangeTypes.FunctionCloseMenu:
@@ -2222,9 +2229,12 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2222
2229
  };
2223
2230
  break;
2224
2231
  case stateChangeTypes.FunctionSetHighlightedIndex:
2225
- changes = {
2226
- highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
2227
- };
2232
+ {
2233
+ var highlightedIndex = action.highlightedIndex;
2234
+ changes = {
2235
+ highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
2236
+ };
2237
+ }
2228
2238
  break;
2229
2239
  case stateChangeTypes.FunctionSetInputValue:
2230
2240
  changes = {
@@ -2233,10 +2243,10 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2233
2243
  break;
2234
2244
  case stateChangeTypes.FunctionReset:
2235
2245
  changes = {
2236
- highlightedIndex: getDefaultHighlightedIndex(props),
2237
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2238
- selectedItem: getDefaultValue$1(props, 'selectedItem', defaultStateValues$1),
2239
- inputValue: getDefaultValue$1(props, 'inputValue', defaultStateValues$1)
2246
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2247
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2248
+ selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
2249
+ inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
2240
2250
  };
2241
2251
  break;
2242
2252
  default:
@@ -2246,17 +2256,11 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2246
2256
  }
2247
2257
  /* eslint-enable complexity */
2248
2258
 
2249
- var propTypes$3 = _extends({}, propTypes$4, {
2259
+ var propTypes$3 = _extends({}, dropdownPropTypes, {
2250
2260
  items: PropTypes.array.isRequired,
2251
2261
  isItemDisabled: PropTypes.func
2252
2262
  });
2253
2263
 
2254
- var defaultProps$2 = _extends({}, defaultProps$3, {
2255
- isItemDisabled: function isItemDisabled() {
2256
- return false;
2257
- }
2258
- });
2259
-
2260
2264
  function getItemIndexByCharacterKey(_ref) {
2261
2265
  var keysSoFar = _ref.keysSoFar,
2262
2266
  highlightedIndex = _ref.highlightedIndex,
@@ -2325,16 +2329,15 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
2325
2329
  });
2326
2330
 
2327
2331
  /* eslint-disable complexity */
2328
- function downshiftSelectReducer(state, props, action) {
2329
- var _props$items;
2332
+ function downshiftSelectReducer(state, action) {
2330
2333
  var type = action.type,
2331
- altKey = action.altKey;
2334
+ props = action.props;
2332
2335
  var changes;
2333
2336
  switch (type) {
2334
2337
  case ItemClick$1:
2335
2338
  changes = {
2336
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2337
- highlightedIndex: getDefaultHighlightedIndex(props),
2339
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2340
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2338
2341
  selectedItem: props.items[action.index]
2339
2342
  };
2340
2343
  break;
@@ -2361,7 +2364,8 @@ function downshiftSelectReducer(state, props, action) {
2361
2364
  break;
2362
2365
  case ToggleButtonKeyDownArrowDown:
2363
2366
  {
2364
- var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2367
+ var altKey = action.altKey;
2368
+ 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);
2365
2369
  changes = {
2366
2370
  highlightedIndex: _highlightedIndex,
2367
2371
  isOpen: true
@@ -2369,20 +2373,23 @@ function downshiftSelectReducer(state, props, action) {
2369
2373
  }
2370
2374
  break;
2371
2375
  case ToggleButtonKeyDownArrowUp:
2372
- if (state.isOpen && altKey) {
2373
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2374
- } else {
2375
- var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props, state, -1);
2376
- changes = {
2377
- highlightedIndex: _highlightedIndex2,
2378
- isOpen: true
2379
- };
2376
+ {
2377
+ var _altKey = action.altKey;
2378
+ if (state.isOpen && _altKey) {
2379
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2380
+ } else {
2381
+ 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);
2382
+ changes = {
2383
+ highlightedIndex: _highlightedIndex2,
2384
+ isOpen: true
2385
+ };
2386
+ }
2380
2387
  }
2381
2388
  break;
2382
2389
  // only triggered when menu is open.
2383
2390
  case ToggleButtonKeyDownEnter:
2384
2391
  case ToggleButtonKeyDownSpaceButton:
2385
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2392
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2386
2393
  break;
2387
2394
  case ToggleButtonKeyDownHome:
2388
2395
  changes = {
@@ -2416,7 +2423,7 @@ function downshiftSelectReducer(state, props, action) {
2416
2423
  changes = _extends({
2417
2424
  isOpen: false,
2418
2425
  highlightedIndex: -1
2419
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
2426
+ }, state.highlightedIndex >= 0 && props.items.length && {
2420
2427
  selectedItem: props.items[state.highlightedIndex]
2421
2428
  });
2422
2429
  break;
@@ -2432,59 +2439,9 @@ function downshiftSelectReducer(state, props, action) {
2432
2439
  }
2433
2440
  /* eslint-enable complexity */
2434
2441
 
2435
- // eslint-disable-next-line @typescript-eslint/dot-notation
2436
- var reactUseId$1 = React__namespace['useId'];
2437
- var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
2438
- function useElementIdsR18$1(_ref) {
2439
- var id = _ref.id,
2440
- labelId = _ref.labelId,
2441
- menuId = _ref.menuId,
2442
- getItemId = _ref.getItemId,
2443
- toggleButtonId = _ref.toggleButtonId,
2444
- inputId = _ref.inputId;
2445
- var reactId = "downshift-" + reactUseId$1();
2446
- if (!id) {
2447
- id = reactId;
2448
- }
2449
- var elementIds = React__namespace.useMemo(function () {
2450
- return {
2451
- labelId: labelId != null ? labelId : id + "-label",
2452
- menuId: menuId != null ? menuId : id + "-menu",
2453
- getItemId: getItemId != null ? getItemId : function (index) {
2454
- return id + "-item-" + index;
2455
- },
2456
- toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
2457
- inputId: inputId != null ? inputId : id + "-input"
2458
- };
2459
- }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2460
- return elementIds;
2461
- }
2462
- function useElementIdsLegacy$1(_ref2) {
2463
- var id = _ref2.id,
2464
- labelId = _ref2.labelId,
2465
- menuId = _ref2.menuId,
2466
- getItemId = _ref2.getItemId,
2467
- toggleButtonId = _ref2.toggleButtonId,
2468
- inputId = _ref2.inputId;
2469
- var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
2470
- var baseId = baseIdRef.current;
2471
- var elementIds = React__namespace.useMemo(function () {
2472
- return {
2473
- labelId: labelId != null ? labelId : baseId + "-label",
2474
- menuId: menuId != null ? menuId : baseId + "-menu",
2475
- getItemId: getItemId != null ? getItemId : function (index) {
2476
- return baseId + "-item-" + index;
2477
- },
2478
- toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
2479
- inputId: inputId != null ? inputId : baseId + "-input"
2480
- };
2481
- }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
2482
- return elementIds;
2483
- }
2484
-
2485
2442
  var _excluded$3 = ["onClick"],
2486
- _excluded2$3 = ["onMouseLeave", "refKey", "ref"],
2487
- _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
2443
+ _excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
2444
+ _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
2488
2445
  _excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
2489
2446
  useSelect.stateChangeTypes = stateChangeTypes$3;
2490
2447
  function useSelect(userProps) {
@@ -2493,22 +2450,23 @@ function useSelect(userProps) {
2493
2450
  }
2494
2451
  validatePropTypes$1(userProps, useSelect, propTypes$3);
2495
2452
  // Props defaults and destructuring.
2496
- var props = _extends({}, defaultProps$2, userProps);
2453
+ var props = _extends({}, dropdownDefaultProps, userProps);
2497
2454
  var scrollIntoView = props.scrollIntoView,
2498
2455
  environment = props.environment,
2499
2456
  getA11yStatusMessage = props.getA11yStatusMessage;
2500
2457
  // Initial state depending on controlled props.
2501
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownsStateEqual),
2458
+ var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
2502
2459
  state = _useControlledReducer[0],
2503
2460
  dispatch = _useControlledReducer[1];
2504
2461
  var isOpen = state.isOpen,
2505
2462
  highlightedIndex = state.highlightedIndex,
2506
2463
  selectedItem = state.selectedItem,
2507
2464
  inputValue = state.inputValue;
2508
- // Element efs.
2465
+
2466
+ // Element refs.
2509
2467
  var toggleButtonRef = React.useRef(null);
2510
2468
  var menuRef = React.useRef(null);
2511
- var itemRefs = React.useRef({});
2469
+ var itemsRef = React.useRef({});
2512
2470
 
2513
2471
  // used to keep the inputValue clearTimeout object between renders.
2514
2472
  var clearTimeoutRef = React.useRef(null);
@@ -2520,24 +2478,12 @@ function useSelect(userProps) {
2520
2478
  props: props
2521
2479
  });
2522
2480
 
2523
- // Some utils.
2524
- var getItemNodeFromIndex = React.useCallback(function (index) {
2525
- return itemRefs.current[elementIds.getItemId(index)];
2526
- }, [elementIds]);
2527
-
2528
2481
  // Effects.
2529
2482
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
2530
2483
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
2531
2484
  // Scroll on highlighted item if change comes from keyboard.
2532
- var shouldScrollRef = useScrollIntoView({
2533
- menuElement: menuRef.current,
2534
- highlightedIndex: highlightedIndex,
2535
- isOpen: isOpen,
2536
- itemRefs: itemRefs,
2537
- scrollIntoView: scrollIntoView,
2538
- getItemNodeFromIndex: getItemNodeFromIndex
2539
- });
2540
- // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2485
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
2486
+ // Sets cleanup for the keysSoFar callback, debounced after 500ms.
2541
2487
  React.useEffect(function () {
2542
2488
  // init the clean function here as we need access to dispatch.
2543
2489
  clearTimeoutRef.current = debounce(function (outerDispatch) {
@@ -2549,7 +2495,8 @@ function useSelect(userProps) {
2549
2495
 
2550
2496
  // Cancel any pending debounced calls on mount
2551
2497
  return function () {
2552
- clearTimeoutRef.current.cancel();
2498
+ var _clearTimeoutRef$curr;
2499
+ (_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
2553
2500
  };
2554
2501
  }, []);
2555
2502
  // Invokes the keysSoFar callback set up above.
@@ -2557,7 +2504,7 @@ function useSelect(userProps) {
2557
2504
  if (!inputValue) {
2558
2505
  return;
2559
2506
  }
2560
- clearTimeoutRef.current(dispatch);
2507
+ clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
2561
2508
  }, [dispatch, inputValue]);
2562
2509
  useControlPropsValidator({
2563
2510
  props: props,
@@ -2565,7 +2512,7 @@ function useSelect(userProps) {
2565
2512
  });
2566
2513
  // Focus the toggle button on first render if required.
2567
2514
  React.useEffect(function () {
2568
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
2515
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
2569
2516
  if (focusOnOpen && toggleButtonRef.current) {
2570
2517
  toggleButtonRef.current.focus();
2571
2518
  }
@@ -2586,7 +2533,7 @@ function useSelect(userProps) {
2586
2533
  // Reset itemRefs on close.
2587
2534
  React.useEffect(function () {
2588
2535
  if (!isOpen) {
2589
- itemRefs.current = {};
2536
+ itemsRef.current = {};
2590
2537
  }
2591
2538
  }, [isOpen]);
2592
2539
 
@@ -2671,50 +2618,11 @@ function useSelect(userProps) {
2671
2618
  };
2672
2619
  }, [dispatch, latest]);
2673
2620
 
2674
- // Action functions.
2675
- var toggleMenu = React.useCallback(function () {
2676
- dispatch({
2677
- type: FunctionToggleMenu$1
2678
- });
2679
- }, [dispatch]);
2680
- var closeMenu = React.useCallback(function () {
2681
- dispatch({
2682
- type: FunctionCloseMenu$1
2683
- });
2684
- }, [dispatch]);
2685
- var openMenu = React.useCallback(function () {
2686
- dispatch({
2687
- type: FunctionOpenMenu$1
2688
- });
2689
- }, [dispatch]);
2690
- var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
2691
- dispatch({
2692
- type: FunctionSetHighlightedIndex$1,
2693
- highlightedIndex: newHighlightedIndex
2694
- });
2695
- }, [dispatch]);
2696
- var selectItem = React.useCallback(function (newSelectedItem) {
2697
- dispatch({
2698
- type: FunctionSelectItem$1,
2699
- selectedItem: newSelectedItem
2700
- });
2701
- }, [dispatch]);
2702
- var reset = React.useCallback(function () {
2703
- dispatch({
2704
- type: FunctionReset$2
2705
- });
2706
- }, [dispatch]);
2707
- var setInputValue = React.useCallback(function (newInputValue) {
2708
- dispatch({
2709
- type: FunctionSetInputValue$1,
2710
- inputValue: newInputValue
2711
- });
2712
- }, [dispatch]);
2713
2621
  // Getter functions.
2714
- var getLabelProps = React.useCallback(function (_temp) {
2715
- var _ref = _temp === void 0 ? {} : _temp,
2622
+ var getLabelProps = React.useCallback(function (labelProps) {
2623
+ var _ref = labelProps != null ? labelProps : {},
2716
2624
  onClick = _ref.onClick,
2717
- labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2625
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2718
2626
  var labelHandleClick = function labelHandleClick() {
2719
2627
  var _toggleButtonRef$curr;
2720
2628
  (_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
@@ -2723,17 +2631,18 @@ function useSelect(userProps) {
2723
2631
  id: elementIds.labelId,
2724
2632
  htmlFor: elementIds.toggleButtonId,
2725
2633
  onClick: callAllEventHandlers(onClick, labelHandleClick)
2726
- }, labelProps);
2634
+ }, rest);
2727
2635
  }, [elementIds]);
2728
- var getMenuProps = React.useCallback(function (_temp2, _temp3) {
2636
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
2729
2637
  var _extends2;
2730
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2638
+ var _ref2 = menuProps != null ? menuProps : {},
2731
2639
  onMouseLeave = _ref2.onMouseLeave,
2732
2640
  _ref2$refKey = _ref2.refKey,
2733
2641
  refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
2734
2642
  ref = _ref2.ref,
2643
+ ariaLabel = _ref2['aria-label'],
2735
2644
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
2736
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2645
+ var _ref3 = otherProps != null ? otherProps : {},
2737
2646
  _ref3$suppressRefErro = _ref3.suppressRefError,
2738
2647
  suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
2739
2648
  var menuHandleMouseLeave = function menuHandleMouseLeave() {
@@ -2744,11 +2653,11 @@ function useSelect(userProps) {
2744
2653
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2745
2654
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2746
2655
  menuRef.current = menuNode;
2747
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
2656
+ }), _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);
2748
2657
  }, [dispatch, setGetterPropCallInfo, elementIds]);
2749
- var getToggleButtonProps = React.useCallback(function (_temp4, _temp5) {
2658
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
2750
2659
  var _extends3;
2751
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2660
+ var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
2752
2661
  onBlur = _ref4.onBlur,
2753
2662
  onClick = _ref4.onClick;
2754
2663
  _ref4.onPress;
@@ -2756,8 +2665,9 @@ function useSelect(userProps) {
2756
2665
  _ref4$refKey = _ref4.refKey,
2757
2666
  refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
2758
2667
  ref = _ref4.ref,
2668
+ disabled = _ref4.disabled,
2759
2669
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
2760
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2670
+ var _ref5 = otherProps != null ? otherProps : {},
2761
2671
  _ref5$suppressRefErro = _ref5.suppressRefError,
2762
2672
  suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
2763
2673
  var latestState = latest.current.state;
@@ -2775,9 +2685,9 @@ function useSelect(userProps) {
2775
2685
  };
2776
2686
  var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2777
2687
  var key = normalizeArrowKey(event);
2778
- if (key && toggleButtonKeyDownHandlers[key]) {
2688
+ if (key && key in toggleButtonKeyDownHandlers) {
2779
2689
  toggleButtonKeyDownHandlers[key](event);
2780
- } else if (isAcceptedCharacterKey(key)) {
2690
+ } else if (/^\S{1}$/.test(key)) {
2781
2691
  dispatch({
2782
2692
  type: ToggleButtonKeyDownCharacter,
2783
2693
  key: key
@@ -2786,20 +2696,22 @@ function useSelect(userProps) {
2786
2696
  };
2787
2697
  var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2788
2698
  toggleButtonRef.current = toggleButtonNode;
2789
- }), _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);
2790
- if (!rest.disabled) {
2699
+ }), _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);
2700
+ if (!disabled) {
2791
2701
  /* istanbul ignore if (react-native) */
2792
2702
  {
2793
- toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
2794
- toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
2703
+ Object.assign(toggleProps, {
2704
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick),
2705
+ onKeyDown: callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown)
2706
+ });
2795
2707
  }
2796
2708
  }
2797
2709
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2798
2710
  return toggleProps;
2799
2711
  }, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
2800
- var getItemProps = React.useCallback(function (_temp6) {
2712
+ var getItemProps = React.useCallback(function (itemProps) {
2801
2713
  var _extends4;
2802
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
2714
+ var _ref6 = itemProps != null ? itemProps : {},
2803
2715
  itemProp = _ref6.item,
2804
2716
  indexProp = _ref6.index,
2805
2717
  onMouseMove = _ref6.onMouseMove,
@@ -2825,7 +2737,7 @@ function useSelect(userProps) {
2825
2737
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
2826
2738
  return;
2827
2739
  }
2828
- shouldScrollRef.current = false;
2740
+ preventScroll();
2829
2741
  dispatch({
2830
2742
  type: ItemMouseMove$1,
2831
2743
  index: index,
@@ -2842,21 +2754,61 @@ function useSelect(userProps) {
2842
2754
  return e.preventDefault();
2843
2755
  }; // keep focus on the toggle after item click select.
2844
2756
 
2845
- var itemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2757
+ var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2846
2758
  if (itemNode) {
2847
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
2759
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
2848
2760
  }
2849
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2761
+ }), _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);
2850
2762
  if (!disabled) {
2851
2763
  /* istanbul ignore next (react-native) */
2852
2764
  {
2853
- itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2765
+ Object.assign(resultItemProps, {
2766
+ onClick: callAllEventHandlers(onClick, itemHandleClick)
2767
+ });
2854
2768
  }
2855
2769
  }
2856
- itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
2857
- itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
2858
- return itemProps;
2859
- }, [latest, elementIds, mouseAndTouchTrackers, shouldScrollRef, dispatch]);
2770
+ return resultItemProps;
2771
+ }, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
2772
+
2773
+ // Action functions.
2774
+ var toggleMenu = React.useCallback(function () {
2775
+ dispatch({
2776
+ type: FunctionToggleMenu$1
2777
+ });
2778
+ }, [dispatch]);
2779
+ var closeMenu = React.useCallback(function () {
2780
+ dispatch({
2781
+ type: FunctionCloseMenu$1
2782
+ });
2783
+ }, [dispatch]);
2784
+ var openMenu = React.useCallback(function () {
2785
+ dispatch({
2786
+ type: FunctionOpenMenu$1
2787
+ });
2788
+ }, [dispatch]);
2789
+ var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
2790
+ dispatch({
2791
+ type: FunctionSetHighlightedIndex$1,
2792
+ highlightedIndex: newHighlightedIndex
2793
+ });
2794
+ }, [dispatch]);
2795
+ var selectItem = React.useCallback(function (newSelectedItem) {
2796
+ dispatch({
2797
+ type: FunctionSelectItem$1,
2798
+ selectedItem: newSelectedItem
2799
+ });
2800
+ }, [dispatch]);
2801
+ var reset = React.useCallback(function () {
2802
+ dispatch({
2803
+ type: FunctionReset$2
2804
+ });
2805
+ }, [dispatch]);
2806
+ var setInputValue = React.useCallback(function (newInputValue) {
2807
+ dispatch({
2808
+ type: FunctionSetInputValue$1,
2809
+ inputValue: newInputValue
2810
+ });
2811
+ }, [dispatch]);
2860
2812
  return {
2861
2813
  // prop getters.
2862
2814
  getToggleButtonProps: getToggleButtonProps,
@@ -2879,6 +2831,18 @@ function useSelect(userProps) {
2879
2831
  };
2880
2832
  }
2881
2833
 
2834
+ function getInitialState$2(props) {
2835
+ var initialState = getInitialState$3(props);
2836
+ var selectedItem = initialState.selectedItem;
2837
+ var inputValue = initialState.inputValue;
2838
+ if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2839
+ inputValue = props.itemToString(selectedItem);
2840
+ }
2841
+ return _extends({}, initialState, {
2842
+ inputValue: inputValue
2843
+ });
2844
+ }
2845
+
2882
2846
  var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2883
2847
  var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2884
2848
  var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
@@ -2930,27 +2894,6 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2930
2894
  ToggleButtonClick: ToggleButtonClick
2931
2895
  });
2932
2896
 
2933
- function getInitialState$2(props) {
2934
- var initialState = getInitialState$3(props);
2935
- var selectedItem = initialState.selectedItem;
2936
- var inputValue = initialState.inputValue;
2937
- if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2938
- inputValue = props.itemToString(selectedItem);
2939
- }
2940
- return _extends({}, initialState, {
2941
- inputValue: inputValue
2942
- });
2943
- }
2944
- var propTypes$2 = _extends({}, propTypes$4, {
2945
- items: PropTypes.array.isRequired,
2946
- isItemDisabled: PropTypes.func,
2947
- inputValue: PropTypes.string,
2948
- defaultInputValue: PropTypes.string,
2949
- initialInputValue: PropTypes.string,
2950
- inputId: PropTypes.string,
2951
- onInputValueChange: PropTypes.func
2952
- });
2953
-
2954
2897
  /**
2955
2898
  * The useCombobox version of useControlledReducer, which also
2956
2899
  * checks if the controlled prop selectedItem changed between
@@ -2958,20 +2901,20 @@ var propTypes$2 = _extends({}, propTypes$4, {
2958
2901
  * string equivalent. It uses the common useEnhancedReducer to
2959
2902
  * compute the rest of the state.
2960
2903
  *
2961
- * @param {Function} reducer Reducer function from downshift.
2962
- * @param {Object} props The hook props, also passed to createInitialState.
2963
- * @param {Function} createInitialState Function that returns the initial state.
2964
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
2965
- * @returns {Array} An array with the state and an action dispatcher.
2904
+ * @param reducer Reducer function from downshift.
2905
+ * @param props The hook props, also passed to createInitialState.
2906
+ * @param createInitialState Function that returns the initial state.
2907
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
2908
+ * @returns An array with the state and an action dispatcher.
2966
2909
  */
2967
2910
  function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
2968
- var previousSelectedItemRef = React.useRef();
2911
+ var previousSelectedItemRef = React.useRef(null);
2969
2912
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
2970
2913
  state = _useEnhancedReducer[0],
2971
2914
  dispatch = _useEnhancedReducer[1];
2972
2915
  var isInitialMount = useIsInitialMount();
2973
2916
  React.useEffect(function () {
2974
- if (!isControlledProp(props, 'selectedItem')) {
2917
+ if (props.selectedItem === undefined) {
2975
2918
  return;
2976
2919
  }
2977
2920
  if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
@@ -2989,23 +2932,27 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
2989
2932
  }, [state.selectedItem, props.selectedItem]);
2990
2933
  return [getState(state, props), dispatch];
2991
2934
  }
2992
- var defaultProps$1 = _extends({}, defaultProps$3, {
2993
- isItemDisabled: function isItemDisabled() {
2994
- return false;
2995
- }
2935
+
2936
+ var propTypes$2 = _extends({}, dropdownPropTypes, {
2937
+ items: PropTypes.array.isRequired,
2938
+ isItemDisabled: PropTypes.func,
2939
+ inputValue: PropTypes.string,
2940
+ defaultInputValue: PropTypes.string,
2941
+ initialInputValue: PropTypes.string,
2942
+ inputId: PropTypes.string,
2943
+ onInputValueChange: PropTypes.func
2996
2944
  });
2997
2945
 
2998
2946
  /* eslint-disable complexity */
2999
- function downshiftUseComboboxReducer(state, props, action) {
3000
- var _props$items;
2947
+ function downshiftUseComboboxReducer(state, action) {
3001
2948
  var type = action.type,
3002
- altKey = action.altKey;
2949
+ props = action.props;
3003
2950
  var changes;
3004
2951
  switch (type) {
3005
2952
  case ItemClick:
3006
2953
  changes = {
3007
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
3008
- highlightedIndex: getDefaultHighlightedIndex(props),
2954
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2955
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3009
2956
  selectedItem: props.items[action.index],
3010
2957
  inputValue: props.itemToString(props.items[action.index])
3011
2958
  };
@@ -3017,15 +2964,15 @@ function downshiftUseComboboxReducer(state, props, action) {
3017
2964
  };
3018
2965
  } else {
3019
2966
  changes = {
3020
- highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
2967
+ highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
3021
2968
  isOpen: props.items.length >= 0
3022
2969
  };
3023
2970
  }
3024
2971
  break;
3025
2972
  case InputKeyDownArrowUp:
3026
2973
  if (state.isOpen) {
3027
- if (altKey) {
3028
- changes = getChangesOnSelection(props, state.highlightedIndex);
2974
+ if (action.altKey) {
2975
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
3029
2976
  } else {
3030
2977
  changes = {
3031
2978
  highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
@@ -3033,13 +2980,13 @@ function downshiftUseComboboxReducer(state, props, action) {
3033
2980
  }
3034
2981
  } else {
3035
2982
  changes = {
3036
- highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
2983
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
3037
2984
  isOpen: props.items.length >= 0
3038
2985
  };
3039
2986
  }
3040
2987
  break;
3041
2988
  case InputKeyDownEnter:
3042
- changes = getChangesOnSelection(props, state.highlightedIndex);
2989
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
3043
2990
  break;
3044
2991
  case InputKeyDownEscape:
3045
2992
  changes = _extends({
@@ -3074,7 +3021,7 @@ function downshiftUseComboboxReducer(state, props, action) {
3074
3021
  changes = _extends({
3075
3022
  isOpen: false,
3076
3023
  highlightedIndex: -1
3077
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
3024
+ }, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
3078
3025
  selectedItem: props.items[state.highlightedIndex],
3079
3026
  inputValue: props.itemToString(props.items[state.highlightedIndex])
3080
3027
  });
@@ -3082,14 +3029,14 @@ function downshiftUseComboboxReducer(state, props, action) {
3082
3029
  case InputChange:
3083
3030
  changes = {
3084
3031
  isOpen: true,
3085
- highlightedIndex: getDefaultHighlightedIndex(props),
3032
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3086
3033
  inputValue: action.inputValue
3087
3034
  };
3088
3035
  break;
3089
3036
  case InputClick:
3090
3037
  changes = {
3091
3038
  isOpen: !state.isOpen,
3092
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
3039
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
3093
3040
  };
3094
3041
  break;
3095
3042
  case FunctionSelectItem:
@@ -3110,10 +3057,10 @@ function downshiftUseComboboxReducer(state, props, action) {
3110
3057
  }
3111
3058
  /* eslint-enable complexity */
3112
3059
 
3113
- var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
3060
+ var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
3114
3061
  _excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
3115
- _excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
3116
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3062
+ _excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
3063
+ _excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3117
3064
  useCombobox.stateChangeTypes = stateChangeTypes$2;
3118
3065
  function useCombobox(userProps) {
3119
3066
  if (userProps === void 0) {
@@ -3121,13 +3068,13 @@ function useCombobox(userProps) {
3121
3068
  }
3122
3069
  validatePropTypes$1(userProps, useCombobox, propTypes$2);
3123
3070
  // Props defaults and destructuring.
3124
- var props = _extends({}, defaultProps$1, userProps);
3071
+ var props = _extends({}, dropdownDefaultProps, userProps);
3125
3072
  var items = props.items,
3126
3073
  scrollIntoView = props.scrollIntoView,
3127
3074
  environment = props.environment,
3128
3075
  getA11yStatusMessage = props.getA11yStatusMessage;
3129
3076
  // Initial state depending on controlled props.
3130
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownsStateEqual),
3077
+ var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
3131
3078
  state = _useControlledReducer[0],
3132
3079
  dispatch = _useControlledReducer[1];
3133
3080
  var isOpen = state.isOpen,
@@ -3137,7 +3084,7 @@ function useCombobox(userProps) {
3137
3084
 
3138
3085
  // Element refs.
3139
3086
  var menuRef = React.useRef(null);
3140
- var itemRefs = React.useRef({});
3087
+ var itemsRef = React.useRef({});
3141
3088
  var inputRef = React.useRef(null);
3142
3089
  var toggleButtonRef = React.useRef(null);
3143
3090
  var isInitialMount = useIsInitialMount();
@@ -3151,29 +3098,19 @@ function useCombobox(userProps) {
3151
3098
  state: state,
3152
3099
  props: props
3153
3100
  });
3154
- var getItemNodeFromIndex = React.useCallback(function (index) {
3155
- return itemRefs.current[elementIds.getItemId(index)];
3156
- }, [elementIds]);
3157
3101
 
3158
3102
  // Effects.
3159
3103
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
3160
3104
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
3161
3105
  // Scroll on highlighted item if change comes from keyboard.
3162
- var shouldScrollRef = useScrollIntoView({
3163
- menuElement: menuRef.current,
3164
- highlightedIndex: highlightedIndex,
3165
- isOpen: isOpen,
3166
- itemRefs: itemRefs,
3167
- scrollIntoView: scrollIntoView,
3168
- getItemNodeFromIndex: getItemNodeFromIndex
3169
- });
3106
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
3170
3107
  useControlPropsValidator({
3171
- props: props,
3172
- state: state
3108
+ state: state,
3109
+ props: props
3173
3110
  });
3174
3111
  // Focus the input on first render if required.
3175
3112
  React.useEffect(function () {
3176
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
3113
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
3177
3114
  if (focusOnOpen && inputRef.current) {
3178
3115
  inputRef.current.focus();
3179
3116
  }
@@ -3199,13 +3136,13 @@ function useCombobox(userProps) {
3199
3136
  // Reset itemRefs on close.
3200
3137
  React.useEffect(function () {
3201
3138
  if (!isOpen) {
3202
- itemRefs.current = {};
3139
+ itemsRef.current = {};
3203
3140
  }
3204
3141
  }, [isOpen]);
3205
3142
  // Reset itemRefs on close.
3206
3143
  React.useEffect(function () {
3207
3144
  var _inputRef$current;
3208
- if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3145
+ if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3209
3146
  return;
3210
3147
  }
3211
3148
  if (environment.document.activeElement !== inputRef.current) {
@@ -3295,29 +3232,30 @@ function useCombobox(userProps) {
3295
3232
  htmlFor: elementIds.inputId
3296
3233
  }, labelProps);
3297
3234
  }, [elementIds]);
3298
- var getMenuProps = React.useCallback(function (_temp, _temp2) {
3235
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
3299
3236
  var _extends2;
3300
- var _ref = _temp === void 0 ? {} : _temp,
3237
+ var _ref = menuProps != null ? menuProps : {},
3301
3238
  onMouseLeave = _ref.onMouseLeave,
3302
3239
  _ref$refKey = _ref.refKey,
3303
3240
  refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3304
3241
  ref = _ref.ref,
3242
+ ariaLabel = _ref['aria-label'],
3305
3243
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3306
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3244
+ var _ref2 = otherProps != null ? otherProps : {},
3307
3245
  _ref2$suppressRefErro = _ref2.suppressRefError,
3308
3246
  suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3309
3247
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3310
3248
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3311
3249
  menuRef.current = menuNode;
3312
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3250
+ }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3313
3251
  dispatch({
3314
3252
  type: MenuMouseLeave
3315
3253
  });
3316
3254
  }), _extends2), rest);
3317
3255
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3318
- var getItemProps = React.useCallback(function (_temp3) {
3256
+ var getItemProps = React.useCallback(function (itemProps) {
3319
3257
  var _extends3, _ref4;
3320
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3258
+ var _ref3 = itemProps != null ? itemProps : {},
3321
3259
  itemProp = _ref3.item,
3322
3260
  indexProp = _ref3.index,
3323
3261
  _ref3$refKey = _ref3.refKey,
@@ -3345,7 +3283,7 @@ function useCombobox(userProps) {
3345
3283
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
3346
3284
  return;
3347
3285
  }
3348
- shouldScrollRef.current = false;
3286
+ preventScroll();
3349
3287
  dispatch({
3350
3288
  type: ItemMouseMove,
3351
3289
  index: index,
@@ -3364,21 +3302,22 @@ function useCombobox(userProps) {
3364
3302
 
3365
3303
  return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3366
3304
  if (itemNode) {
3367
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
3305
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
3368
3306
  }
3369
3307
  }), _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), {
3370
3308
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3371
3309
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3372
3310
  }, rest);
3373
- }, [dispatch, elementIds, latest, mouseAndTouchTrackers, shouldScrollRef]);
3374
- var getToggleButtonProps = React.useCallback(function (_temp4) {
3311
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
3312
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
3375
3313
  var _extends4;
3376
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3314
+ var _ref5 = toggleButtonProps != null ? toggleButtonProps : {},
3377
3315
  onClick = _ref5.onClick;
3378
3316
  _ref5.onPress;
3379
3317
  var _ref5$refKey = _ref5.refKey,
3380
3318
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3381
3319
  ref = _ref5.ref,
3320
+ disabled = _ref5.disabled,
3382
3321
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
3383
3322
  var latestState = latest.current.state;
3384
3323
  var toggleButtonHandleClick = function toggleButtonHandleClick() {
@@ -3388,13 +3327,17 @@ function useCombobox(userProps) {
3388
3327
  };
3389
3328
  return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3390
3329
  toggleButtonRef.current = toggleButtonNode;
3391
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
3330
+ }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, {
3392
3331
  onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3393
- }), rest);
3332
+ }), {
3333
+ disabled: disabled
3334
+ }, rest);
3394
3335
  }, [dispatch, latest, elementIds]);
3395
- var getInputProps = React.useCallback(function (_temp5, _temp6) {
3336
+ var getInputProps = React.useCallback(function (inputProps, otherProps) {
3396
3337
  var _extends5;
3397
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3338
+ var _ref6 = inputProps != null ? inputProps : {},
3339
+ ariaLabel = _ref6['aria-label'],
3340
+ disabled = _ref6.disabled,
3398
3341
  onKeyDown = _ref6.onKeyDown,
3399
3342
  onChange = _ref6.onChange,
3400
3343
  onInput = _ref6.onInput,
@@ -3405,15 +3348,16 @@ function useCombobox(userProps) {
3405
3348
  refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3406
3349
  ref = _ref6.ref,
3407
3350
  rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
3408
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3351
+ var _ref7 = otherProps != null ? otherProps : {},
3409
3352
  _ref7$suppressRefErro = _ref7.suppressRefError,
3410
3353
  suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3411
3354
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3412
3355
  var latestState = latest.current.state;
3413
3356
  var inputHandleKeyDown = function inputHandleKeyDown(event) {
3414
3357
  var key = normalizeArrowKey(event);
3415
- if (key && inputKeyDownHandlers[key]) {
3416
- inputKeyDownHandlers[key](event);
3358
+ if (key && key in inputKeyDownHandlers) {
3359
+ var validKey = key;
3360
+ inputKeyDownHandlers[validKey](event);
3417
3361
  }
3418
3362
  };
3419
3363
  var inputHandleChange = function inputHandleChange(event) {
@@ -3441,13 +3385,13 @@ function useCombobox(userProps) {
3441
3385
  /* istanbul ignore next (preact) */
3442
3386
  var onChangeKey = 'onChange';
3443
3387
  var eventHandlers = {};
3444
- if (!rest.disabled) {
3388
+ if (!disabled) {
3445
3389
  var _eventHandlers;
3446
3390
  eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
3447
3391
  }
3448
3392
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3449
3393
  inputRef.current = inputNode;
3450
- }), _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);
3394
+ }), _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);
3451
3395
  }, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
3452
3396
 
3453
3397
  // returns
@@ -3517,31 +3461,6 @@ var defaultStateValues = {
3517
3461
  selectedItems: []
3518
3462
  };
3519
3463
 
3520
- /**
3521
- * Returns the initial value for a state key in the following order:
3522
- * 1. controlled prop, 2. initial prop, 3. default prop, 4. default
3523
- * value from Downshift.
3524
- *
3525
- * @param {Object} props Props passed to the hook.
3526
- * @param {string} propKey Props key to generate the value for.
3527
- * @returns {any} The initial value for that prop.
3528
- */
3529
- function getInitialValue(props, propKey) {
3530
- return getInitialValue$1(props, propKey, defaultStateValues);
3531
- }
3532
-
3533
- /**
3534
- * Returns the default value for a state key in the following order:
3535
- * 1. controlled prop, 2. default prop, 3. default value from Downshift.
3536
- *
3537
- * @param {Object} props Props passed to the hook.
3538
- * @param {string} propKey Props key to generate the value for.
3539
- * @returns {any} The initial value for that prop.
3540
- */
3541
- function getDefaultValue(props, propKey) {
3542
- return getDefaultValue$1(props, propKey, defaultStateValues);
3543
- }
3544
-
3545
3464
  /**
3546
3465
  * Gets the initial state based on the provided props. It uses initial, default
3547
3466
  * and controlled props related to state in order to compute the initial value.
@@ -3550,8 +3469,8 @@ function getDefaultValue(props, propKey) {
3550
3469
  * @returns {Object} The initial state.
3551
3470
  */
3552
3471
  function getInitialState$1(props) {
3553
- var activeIndex = getInitialValue(props, 'activeIndex');
3554
- var selectedItems = getInitialValue(props, 'selectedItems');
3472
+ var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
3473
+ var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
3555
3474
  return {
3556
3475
  activeIndex: activeIndex,
3557
3476
  selectedItems: selectedItems
@@ -3595,9 +3514,9 @@ function isStateEqual$1(prevState, newState) {
3595
3514
  return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
3596
3515
  }
3597
3516
  var propTypes$1 = {
3598
- stateReducer: propTypes$4.stateReducer,
3599
- itemToKey: propTypes$4.itemToKey,
3600
- environment: propTypes$4.environment,
3517
+ stateReducer: dropdownPropTypes.stateReducer,
3518
+ itemToKey: dropdownPropTypes.itemToKey,
3519
+ environment: dropdownPropTypes.environment,
3601
3520
  selectedItems: PropTypes.array,
3602
3521
  initialSelectedItems: PropTypes.array,
3603
3522
  defaultSelectedItems: PropTypes.array,
@@ -3611,9 +3530,9 @@ var propTypes$1 = {
3611
3530
  keyNavigationPrevious: PropTypes.string
3612
3531
  };
3613
3532
  var defaultProps = {
3614
- itemToKey: defaultProps$3.itemToKey,
3615
- stateReducer: defaultProps$3.stateReducer,
3616
- environment: defaultProps$3.environment,
3533
+ itemToKey: dropdownDefaultProps.itemToKey,
3534
+ stateReducer: dropdownDefaultProps.stateReducer,
3535
+ environment: dropdownDefaultProps.environment,
3617
3536
  keyNavigationNext: 'ArrowRight',
3618
3537
  keyNavigationPrevious: 'ArrowLeft'
3619
3538
  };
@@ -3659,10 +3578,11 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
3659
3578
  });
3660
3579
 
3661
3580
  /* eslint-disable complexity */
3662
- function downshiftMultipleSelectionReducer(state, props, action) {
3581
+ function downshiftMultipleSelectionReducer(state, action) {
3663
3582
  var type = action.type,
3664
3583
  index = action.index,
3665
- selectedItem = action.selectedItem;
3584
+ selectedItem = action.selectedItem,
3585
+ props = action.props;
3666
3586
  var activeIndex = state.activeIndex,
3667
3587
  selectedItems = state.selectedItems;
3668
3588
  var changes;
@@ -3759,8 +3679,8 @@ function downshiftMultipleSelectionReducer(state, props, action) {
3759
3679
  }
3760
3680
  case FunctionReset:
3761
3681
  changes = {
3762
- activeIndex: getDefaultValue(props, 'activeIndex'),
3763
- selectedItems: getDefaultValue(props, 'selectedItems')
3682
+ activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
3683
+ selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
3764
3684
  };
3765
3685
  break;
3766
3686
  default:
@@ -3992,7 +3912,7 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3992
3912
  TagRemoveClick: TagRemoveClick
3993
3913
  });
3994
3914
 
3995
- function useTagGroupReducer(state, _props, action) {
3915
+ function useTagGroupReducer(state, action) {
3996
3916
  var type = action.type;
3997
3917
  var changes;
3998
3918
  switch (type) {
@@ -4053,8 +3973,9 @@ function useTagGroupReducer(state, _props, action) {
4053
3973
  return _extends({}, state, changes);
4054
3974
  }
4055
3975
 
4056
- // eslint-disable-next-line @typescript-eslint/dot-notation
4057
- var reactUseId = React__namespace['useId'];
3976
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
3977
+ var SafeReact = _extends({}, React__namespace);
3978
+ var reactUseId = SafeReact.useId;
4058
3979
 
4059
3980
  // istanbul ignore next
4060
3981
  var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
@@ -4229,7 +4150,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4229
4150
  'aria-atomic': 'false',
4230
4151
  'aria-relevant': 'additions',
4231
4152
  role: 'listbox',
4232
- onKeyDown: callAllEventHandlers$1(onKeyDown, handleKeyDown)
4153
+ onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
4233
4154
  }, rest);
4234
4155
  return tagGroupProps;
4235
4156
  }, [dispatch, elementIds.tagGroupId]);
@@ -4254,11 +4175,11 @@ var _useTagGroup = function useTagGroup(userProps) {
4254
4175
  var tagId = elementIds.getTagId(index);
4255
4176
  return _extends((_extends2 = {
4256
4177
  'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
4257
- }, _extends2[refKey] = handleRefs$1(ref, function (itemNode) {
4178
+ }, _extends2[refKey] = handleRefs(ref, function (itemNode) {
4258
4179
  if (itemNode) {
4259
4180
  itemRefs.current[tagId] = itemNode;
4260
4181
  }
4261
- }), _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);
4182
+ }), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
4262
4183
  }, [dispatch, elementIds, latest, itemRefs]);
4263
4184
  var getTagRemoveProps = React.useCallback(function (options) {
4264
4185
  var index = options.index,
@@ -4280,7 +4201,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4280
4201
  id: tagRemoveId,
4281
4202
  tabIndex: -1,
4282
4203
  'aria-labelledby': tagRemoveId + " " + tagId,
4283
- onClick: callAllEventHandlers$1(onClick, handleClick)
4204
+ onClick: callAllEventHandlers(onClick, handleClick)
4284
4205
  }, rest);
4285
4206
  }, [elementIds, dispatch]);
4286
4207