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
  /**
@@ -460,34 +518,6 @@ function pickState(state) {
460
518
  return result;
461
519
  }
462
520
 
463
- /**
464
- * This determines whether a prop is a "controlled prop" meaning it is
465
- * state which is controlled by the outside of this component rather
466
- * than within this component.
467
- *
468
- * @param {Object} props The props that may contain controlled values.
469
- * @param {String} key the key to check
470
- * @return {Boolean} whether it is a controlled controlled prop
471
- */
472
- function isControlledProp(props, key) {
473
- return props[key] !== undefined;
474
- }
475
-
476
- /**
477
- * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
478
- * @param {Object} event a keyboardEvent object
479
- * @return {String} keyboard key
480
- */
481
- function normalizeArrowKey(event) {
482
- var key = event.key,
483
- keyCode = event.keyCode;
484
- /* istanbul ignore next (ie) */
485
- if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
486
- return "Arrow" + key;
487
- }
488
- return key;
489
- }
490
-
491
521
  /**
492
522
  * Simple check if the value passed is object literal
493
523
  * @param {*} obj any things
@@ -497,112 +527,6 @@ function isPlainObject(obj) {
497
527
  return Object.prototype.toString.call(obj) === '[object Object]';
498
528
  }
499
529
 
500
- /**
501
- * Returns the next non-disabled highlightedIndex value.
502
- *
503
- * @param {number} start The current highlightedIndex.
504
- * @param {number} offset The offset from the current highlightedIndex to start searching.
505
- * @param {unknown[]} items The items array.
506
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
507
- * @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
508
- * @returns {number} The next highlightedIndex.
509
- */
510
- function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
511
- if (circular === void 0) {
512
- circular = false;
513
- }
514
- var count = items.length;
515
- if (count === 0) {
516
- return -1;
517
- }
518
- var itemsLastIndex = count - 1;
519
- if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
520
- start = offset > 0 ? -1 : itemsLastIndex + 1;
521
- }
522
- var current = start + offset;
523
- if (current < 0) {
524
- current = circular ? itemsLastIndex : 0;
525
- } else if (current > itemsLastIndex) {
526
- current = circular ? 0 : itemsLastIndex;
527
- }
528
- var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
529
- if (highlightedIndex === -1) {
530
- return start >= count ? -1 : start;
531
- }
532
- return highlightedIndex;
533
- }
534
-
535
- /**
536
- * Returns the next non-disabled highlightedIndex value.
537
- *
538
- * @param {number} start The current highlightedIndex.
539
- * @param {boolean} backwards If true, it will search backwards from the start.
540
- * @param {unknown[]} items The items array.
541
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
542
- * @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
543
- * @returns {number} The next non-disabled index.
544
- */
545
- function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
546
- if (circular === void 0) {
547
- circular = false;
548
- }
549
- var count = items.length;
550
- if (backwards) {
551
- for (var index = start; index >= 0; index--) {
552
- if (!isItemDisabled(items[index], index)) {
553
- return index;
554
- }
555
- }
556
- } else {
557
- for (var _index = start; _index < count; _index++) {
558
- if (!isItemDisabled(items[_index], _index)) {
559
- return _index;
560
- }
561
- }
562
- }
563
- if (circular) {
564
- return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
565
- }
566
- return -1;
567
- }
568
-
569
- /**
570
- * Checks if event target is within the downshift elements.
571
- *
572
- * @param {EventTarget} target Target to check.
573
- * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
574
- * @param {Window} environment The window context where downshift renders.
575
- * @param {boolean} checkActiveElement Whether to also check activeElement.
576
- *
577
- * @returns {boolean} Whether or not the target is within downshift elements.
578
- */
579
- function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
580
- if (checkActiveElement === void 0) {
581
- checkActiveElement = true;
582
- }
583
- return environment && downshiftElements.some(function (contextNode) {
584
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
585
- });
586
- }
587
-
588
- // eslint-disable-next-line import/no-mutable-exports
589
- var validateControlledUnchanged = noop;
590
- /* istanbul ignore next */
591
- if (process.env.NODE_ENV !== 'production') {
592
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
593
- 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";
594
- Object.keys(state).forEach(function (propKey) {
595
- if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
596
- // eslint-disable-next-line no-console
597
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
598
- } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
599
- // eslint-disable-next-line no-console
600
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
601
- }
602
- });
603
- };
604
- }
605
-
606
530
  var _excluded$4 = ["refKey", "ref"],
607
531
  _excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
608
532
  _excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
@@ -753,7 +677,7 @@ var Downshift = /*#__PURE__*/function () {
753
677
  }
754
678
  newStateToSet[key];
755
679
  // if it's coming from props, then we don't care to set it internally
756
- if (!isControlledProp(_this.props, key)) {
680
+ if (_this.props[key] === undefined) {
757
681
  nextState[key] = newStateToSet[key];
758
682
  }
759
683
  });
@@ -1487,7 +1411,7 @@ var Downshift = /*#__PURE__*/function () {
1487
1411
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1488
1412
  }
1489
1413
  }
1490
- if (isControlledProp(this.props, 'selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1414
+ if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1491
1415
  this.internalSetState({
1492
1416
  type: controlledPropUpdatedSelectedItem,
1493
1417
  inputValue: this.props.itemToString(this.props.selectedItem)
@@ -1627,7 +1551,7 @@ function callOnChangeProps(action, props, state, newState) {
1627
1551
  changes[key] = newState[key];
1628
1552
  }
1629
1553
  }
1630
- if (props.onStateChange && Object.keys(changes).length) {
1554
+ if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
1631
1555
  props.onStateChange(_extends({
1632
1556
  type: type
1633
1557
  }, changes));
@@ -1653,50 +1577,53 @@ function invokeOnChangeHandler(key, action, props, state, newState) {
1653
1577
  * two reducers, one from downshift and an optional one from the user.
1654
1578
  * Also calls the onChange handlers for state values that have changed.
1655
1579
  *
1656
- * @param {Function} reducer Reducer function from downshift.
1657
- * @param {Object} props The hook props, also passed to createInitialState.
1658
- * @param {Function} createInitialState Function that returns the initial state.
1659
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1660
- * @returns {Array} An array with the state and an action dispatcher.
1580
+ * @param reducer Reducer function from downshift.
1581
+ * @param props The hook props, also passed to createInitialState.
1582
+ * @param createInitialState Function that returns the initial state.
1583
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1584
+ * @returns An array with the state and an action dispatcher.
1661
1585
  */
1662
1586
  function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
1663
- var prevStateRef = React__namespace.useRef(null);
1664
- var actionRef = React__namespace.useRef(undefined);
1665
- var propsRef = useLatestRef(props);
1587
+ var prevStateRef = React__namespace.useRef({});
1588
+ var actionRef = React__namespace.useRef();
1666
1589
  var enhancedReducer = React__namespace.useCallback(function (state, action) {
1667
1590
  actionRef.current = action;
1668
- state = getState(state, propsRef.current);
1669
- var changes = reducer(state, propsRef.current, action);
1670
- var newState = propsRef.current.stateReducer(state, _extends({}, action, {
1591
+ state = getState(state, action.props);
1592
+ var changes = reducer(state, action);
1593
+ var newState = action.props.stateReducer(state, _extends({}, action, {
1671
1594
  changes: changes
1672
1595
  }));
1673
1596
  return _extends({}, state, newState);
1674
- }, [propsRef, reducer]);
1597
+ }, [reducer]);
1675
1598
  var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
1676
1599
  state = _React$useReducer[0],
1677
1600
  dispatch = _React$useReducer[1];
1601
+ var propsRef = useLatestRef(props);
1602
+ var dispatchWithProps = React__namespace.useCallback(function (action) {
1603
+ return dispatch(_extends({}, action, {
1604
+ props: propsRef.current
1605
+ }));
1606
+ }, [propsRef]);
1678
1607
  var action = actionRef.current;
1679
1608
  React__namespace.useEffect(function () {
1680
- var _prevStateRef$current;
1681
- var prevState = getState((_prevStateRef$current = prevStateRef.current) != null ? _prevStateRef$current : {}, propsRef.current);
1682
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
1609
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
1610
+ var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
1683
1611
  if (shouldCallOnChangeProps) {
1684
- callOnChangeProps(action, propsRef.current, prevState, state);
1612
+ callOnChangeProps(action, action.props, prevState, state);
1685
1613
  }
1686
1614
  prevStateRef.current = state;
1687
- }, [state, action, isStateEqual, propsRef]);
1688
- return [state, dispatch];
1615
+ }, [state, action, isStateEqual]);
1616
+ return [state, dispatchWithProps];
1689
1617
  }
1690
1618
 
1691
1619
  /**
1692
1620
  * Wraps the useEnhancedReducer and applies the controlled prop values before
1693
1621
  * returning the new state.
1694
- *
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.
1622
+ * @param reducer Reducer function from downshift.
1623
+ * @param props The hook props, also passed to createInitialState.
1624
+ * @param createInitialState Function that returns the initial state.
1625
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1626
+ * @returns An array with the state and an action dispatcher.
1700
1627
  */
1701
1628
  function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
1702
1629
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
@@ -1749,16 +1676,8 @@ function useIsInitialMount() {
1749
1676
  return isInitialMountRef.current;
1750
1677
  }
1751
1678
 
1752
- /**
1753
- * Default state reducer that returns the changes.
1754
- *
1755
- */
1756
- function stateReducer(_s, a) {
1757
- return a.changes;
1758
- }
1759
-
1760
1679
  // Shared between all exports.
1761
- var propTypes$5 = {
1680
+ var propTypes$4 = {
1762
1681
  environment: PropTypes.shape({
1763
1682
  addEventListener: PropTypes.func.isRequired,
1764
1683
  removeEventListener: PropTypes.func.isRequired,
@@ -1774,30 +1693,47 @@ var propTypes$5 = {
1774
1693
  stateReducer: PropTypes.func
1775
1694
  };
1776
1695
 
1777
- function getDefaultValue$1(props, propKey, defaultStateValues) {
1778
- var defaultValue = props["default" + capitalizeString(propKey)];
1779
- if (defaultValue !== undefined) {
1780
- return defaultValue;
1781
- }
1782
- return defaultStateValues[propKey];
1696
+ /**
1697
+ * Returns the default value based on the defaultProp and defaultStateValue.
1698
+ *
1699
+ * @param defaultProp The default prop value.
1700
+ * @param defaultStateValue The default state value.
1701
+ * @returns The resolved default value.
1702
+ */
1703
+ function getDefaultValue(defaultProp, defaultStateValue) {
1704
+ return defaultProp === undefined ? defaultStateValue : defaultProp;
1783
1705
  }
1784
1706
 
1785
- function getInitialValue$1(props, propKey, defaultStateValues) {
1786
- var value = props[propKey];
1707
+ /**
1708
+ * Returns the initial value for a state variable, based on the following precedence:
1709
+ * 1. The controlled value (if it's not undefined)
1710
+ * 2. The initialValue (if it's not undefined)
1711
+ * 3. The defaultValue (if it's not undefined)
1712
+ * 4. The defaultStateValue
1713
+ *
1714
+ * @param value The controlled value of the state variable.
1715
+ * @param initialValue The initial value of the state variable.
1716
+ * @param defaultValue The default value of the state variable.
1717
+ * @param defaultStateValue The default state value to use if all other values are undefined.
1718
+ * @returns The initial value for the state variable.
1719
+ */
1720
+ function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
1787
1721
  if (value !== undefined) {
1788
1722
  return value;
1789
1723
  }
1790
- var initialValue = props["initial" + capitalizeString(propKey)];
1791
1724
  if (initialValue !== undefined) {
1792
1725
  return initialValue;
1793
1726
  }
1794
- return getDefaultValue$1(props, propKey, defaultStateValues);
1727
+ if (defaultValue !== undefined) {
1728
+ return defaultValue;
1729
+ }
1730
+ return defaultStateValue;
1795
1731
  }
1796
1732
 
1797
1733
  /**
1798
1734
  * Debounced call for updating the a11y message.
1799
1735
  */
1800
- var updateA11yStatus = debounce$1(function (status, document) {
1736
+ var updateA11yStatus = debounce(function (status, document) {
1801
1737
  setStatus(status, document);
1802
1738
  }, 200);
1803
1739
 
@@ -1833,7 +1769,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
1833
1769
  }
1834
1770
 
1835
1771
  // Shared between useSelect, useCombobox, Downshift.
1836
- var propTypes$4 = _extends({}, propTypes$5, {
1772
+ var dropdownPropTypes = _extends({}, propTypes$4, {
1837
1773
  getA11yStatusMessage: PropTypes.func,
1838
1774
  highlightedIndex: PropTypes.number,
1839
1775
  defaultHighlightedIndex: PropTypes.number,
@@ -1856,62 +1792,145 @@ var propTypes$4 = _extends({}, propTypes$5, {
1856
1792
  scrollIntoView: PropTypes.func
1857
1793
  });
1858
1794
 
1859
- var defaultProps$3 = {
1795
+ var dropdownDefaultProps = {
1860
1796
  itemToString: function itemToString(item) {
1861
1797
  return item ? String(item) : '';
1862
1798
  },
1863
1799
  itemToKey: function itemToKey(item) {
1864
1800
  return item;
1865
1801
  },
1866
- stateReducer: stateReducer,
1802
+ isItemDisabled: function isItemDisabled(_item) {
1803
+ return false;
1804
+ },
1805
+ stateReducer: function stateReducer(_state, actionAndChanges) {
1806
+ return actionAndChanges.changes;
1807
+ },
1867
1808
  scrollIntoView: scrollIntoView,
1868
1809
  environment: /* istanbul ignore next (ssr) */
1869
1810
  typeof window === 'undefined' || false ? undefined : window
1870
1811
  };
1871
1812
 
1872
- var defaultStateValues$1 = {
1813
+ var dropdownDefaultStateValues = {
1873
1814
  highlightedIndex: -1,
1874
1815
  isOpen: false,
1875
1816
  selectedItem: null,
1876
1817
  inputValue: ''
1877
1818
  };
1878
1819
 
1879
- // istanbul ignore next
1880
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
1881
- function isAcceptedCharacterKey(key) {
1882
- return /^\S{1}$/.test(key);
1820
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
1821
+ var SafeReact$1 = _extends({}, React__namespace);
1822
+ var reactUseId$1 = SafeReact$1.useId;
1823
+ var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
1824
+ function useElementIdsR18$1(_ref) {
1825
+ var id = _ref.id,
1826
+ labelId = _ref.labelId,
1827
+ menuId = _ref.menuId,
1828
+ getItemId = _ref.getItemId,
1829
+ toggleButtonId = _ref.toggleButtonId,
1830
+ inputId = _ref.inputId;
1831
+ var reactId = "downshift-" + reactUseId$1();
1832
+ if (!id) {
1833
+ id = reactId;
1834
+ }
1835
+ var elementIds = React__namespace.useMemo(function () {
1836
+ return {
1837
+ labelId: labelId != null ? labelId : id + "-label",
1838
+ menuId: menuId != null ? menuId : id + "-menu",
1839
+ getItemId: getItemId != null ? getItemId : function (index) {
1840
+ return id + "-item-" + index;
1841
+ },
1842
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
1843
+ inputId: inputId != null ? inputId : id + "-input"
1844
+ };
1845
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1846
+ return elementIds;
1883
1847
  }
1884
- function getInitialState$3(props) {
1885
- var selectedItem = getInitialValue$1(props, 'selectedItem', defaultStateValues$1);
1886
- var isOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
1887
- var highlightedIndex = getInitialHighlightedIndex(props);
1888
- var inputValue = getInitialValue$1(props, 'inputValue', defaultStateValues$1);
1889
- return {
1890
- highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1891
- return props.itemToKey(item) === props.itemToKey(selectedItem);
1892
- }) : highlightedIndex,
1893
- isOpen: isOpen,
1894
- selectedItem: selectedItem,
1895
- inputValue: inputValue
1896
- };
1848
+ function useElementIdsLegacy$1(_ref2) {
1849
+ var id = _ref2.id,
1850
+ labelId = _ref2.labelId,
1851
+ menuId = _ref2.menuId,
1852
+ getItemId = _ref2.getItemId,
1853
+ toggleButtonId = _ref2.toggleButtonId,
1854
+ inputId = _ref2.inputId;
1855
+ var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
1856
+ var baseId = baseIdRef.current;
1857
+ var elementIds = React__namespace.useMemo(function () {
1858
+ return {
1859
+ labelId: labelId != null ? labelId : baseId + "-label",
1860
+ menuId: menuId != null ? menuId : baseId + "-menu",
1861
+ getItemId: getItemId != null ? getItemId : function (index) {
1862
+ return baseId + "-item-" + index;
1863
+ },
1864
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
1865
+ inputId: inputId != null ? inputId : baseId + "-input"
1866
+ };
1867
+ }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
1868
+ return elementIds;
1897
1869
  }
1898
- function getHighlightedIndexOnOpen(props, state, offset) {
1899
- var items = props.items,
1900
- initialHighlightedIndex = props.initialHighlightedIndex,
1901
- defaultHighlightedIndex = props.defaultHighlightedIndex,
1902
- isItemDisabled = props.isItemDisabled,
1903
- itemToKey = props.itemToKey;
1904
- var selectedItem = state.selectedItem,
1905
- highlightedIndex = state.highlightedIndex;
1870
+
1871
+ /**
1872
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
1873
+ *
1874
+ * @param props Props passed to the hook.
1875
+ * @returns The highlighted index.
1876
+ */
1877
+ function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
1878
+ var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
1879
+ if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
1880
+ return -1;
1881
+ }
1882
+ return highlightedIndex;
1883
+ }
1884
+
1885
+ /**
1886
+ * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
1887
+ * In that case, selects the item and resets to defaults for open state and highlighted idex.
1888
+ *
1889
+ * @param props The Dropdown props.
1890
+ * @param highlightedIndex The index from the state.
1891
+ * @param inputValue Also return the input value for state.
1892
+ * @returns The changes for the state.
1893
+ */
1894
+ function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
1895
+ var shouldSelect = items.length && highlightedIndex >= 0;
1896
+ return _extends({
1897
+ isOpen: false,
1898
+ highlightedIndex: -1
1899
+ }, shouldSelect && _extends({
1900
+ selectedItem: items[highlightedIndex],
1901
+ isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
1902
+ highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
1903
+ }, inputValue && {
1904
+ inputValue: itemToString(items[highlightedIndex])
1905
+ }));
1906
+ }
1907
+
1908
+ /* eslint-disable max-params */
1909
+ /**
1910
+ * Returns the highlighted index when the menu is opened.
1911
+ * Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
1912
+ * selectedItem, and the open direction offset.
1913
+ *
1914
+ * @param items The list of items.
1915
+ * @param initialHighlightedIndex The initial highlighted index prop.
1916
+ * @param defaultHighlightedIndex The default highlighted index prop.
1917
+ * @param isItemDisabled Callback to determine if an item is disabled.
1918
+ * @param itemToKey Callback to get a unique key from an item.
1919
+ * @param selectedItem The currently selected item.
1920
+ * @param highlightedIndex The current highlighted index from state.
1921
+ * @param offset The direction of navigation: positive opens downward, negative opens upward.
1922
+ * @returns The new highlighted index.
1923
+ */
1924
+ function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
1906
1925
  if (items.length === 0) {
1907
1926
  return -1;
1908
1927
  }
1909
1928
 
1910
1929
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
1911
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1930
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1912
1931
  return initialHighlightedIndex;
1913
1932
  }
1914
- if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1933
+ if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1915
1934
  return defaultHighlightedIndex;
1916
1935
  }
1917
1936
  if (selectedItem) {
@@ -1919,21 +1938,71 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1919
1938
  return itemToKey(selectedItem) === itemToKey(item);
1920
1939
  });
1921
1940
  }
1922
- if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1941
+ if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1923
1942
  return items.length - 1;
1924
1943
  }
1925
- if (offset > 0 && !isItemDisabled(items[0], 0)) {
1944
+ if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
1926
1945
  return 0;
1927
1946
  }
1928
1947
  return -1;
1929
1948
  }
1949
+
1950
+ function getInitialState$3(props) {
1951
+ var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
1952
+ var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
1953
+ var highlightedIndex = getInitialHighlightedIndex(props);
1954
+ var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
1955
+ return {
1956
+ highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1957
+ return props.itemToKey(item) === props.itemToKey(selectedItem);
1958
+ }) : highlightedIndex,
1959
+ isOpen: isOpen,
1960
+ selectedItem: selectedItem,
1961
+ inputValue: inputValue
1962
+ };
1963
+ }
1964
+
1965
+ /**
1966
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
1967
+ * @param props Props from useCombobox or useSelect.
1968
+ * @returns The highlighted index.
1969
+ */
1970
+ function getInitialHighlightedIndex(props) {
1971
+ var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
1972
+ if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
1973
+ return -1;
1974
+ }
1975
+ return highlightedIndex;
1976
+ }
1977
+
1978
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1979
+ // eslint-disable-next-line import/no-mutable-exports
1980
+ var useControlPropsValidator = noop;
1981
+ /* istanbul ignore next */
1982
+ if (process.env.NODE_ENV !== 'production') {
1983
+ useControlPropsValidator = function useControlPropsValidator(_ref) {
1984
+ var props = _ref.props,
1985
+ state = _ref.state;
1986
+ // used for checking when props are moving from controlled to uncontrolled.
1987
+ var prevPropsRef = React__namespace.useRef(props);
1988
+ var isInitialMount = useIsInitialMount();
1989
+ React__namespace.useEffect(function () {
1990
+ if (isInitialMount) {
1991
+ return;
1992
+ }
1993
+ validateControlledUnchanged(state, prevPropsRef.current, props);
1994
+ prevPropsRef.current = props;
1995
+ }, [state, props, isInitialMount]);
1996
+ };
1997
+ }
1998
+
1930
1999
  /**
1931
2000
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
1932
2001
  *
1933
- * @param {Window} environment The environment to add the event listeners to, for instance window.
1934
- * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1935
- * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
1936
- * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
2002
+ * @param environment The environment to add the event listeners to, for instance window.
2003
+ * @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
2004
+ * @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
2005
+ * @returns The mouse and touch events information.
1937
2006
  */
1938
2007
  function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
1939
2008
  var mouseAndTouchTrackersRef = React__namespace.useRef({
@@ -1997,8 +2066,8 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1997
2066
  /**
1998
2067
  * Custom hook that checks if getter props are called correctly.
1999
2068
  *
2000
- * @param {...any} propKeys Getter prop names to be handled.
2001
- * @returns {Function} Setter function called inside getter props to set call information.
2069
+ * @param propKeys Getter prop names to be handled.
2070
+ * @returns Setter function called inside getter props to set call information.
2002
2071
  */
2003
2072
  /* istanbul ignore next */
2004
2073
  if (process.env.NODE_ENV !== 'production') {
@@ -2034,120 +2103,58 @@ if (process.env.NODE_ENV !== 'production') {
2034
2103
  getterPropsCalledRef.current[propKey] = {
2035
2104
  suppressRefError: suppressRefError,
2036
2105
  refKey: refKey,
2037
- elementRef: elementRef
2038
- };
2039
- }, []);
2040
- return setGetterPropCallInfo;
2041
- };
2042
- }
2043
- function useScrollIntoView(_ref) {
2044
- var highlightedIndex = _ref.highlightedIndex,
2045
- isOpen = _ref.isOpen,
2046
- itemRefs = _ref.itemRefs,
2047
- getItemNodeFromIndex = _ref.getItemNodeFromIndex,
2048
- menuElement = _ref.menuElement,
2049
- scrollIntoViewProp = _ref.scrollIntoView;
2050
- // used not to scroll on highlight by mouse.
2051
- var shouldScrollRef = React__namespace.useRef(true);
2052
- // Scroll on highlighted item if change comes from keyboard.
2053
- useIsomorphicLayoutEffect(function () {
2054
- if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2055
- return;
2056
- }
2057
- if (shouldScrollRef.current === false) {
2058
- shouldScrollRef.current = true;
2059
- } else {
2060
- scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
2061
- }
2062
- // eslint-disable-next-line react-hooks/exhaustive-deps
2063
- }, [highlightedIndex]);
2064
- return shouldScrollRef;
2065
- }
2066
-
2067
- // eslint-disable-next-line import/no-mutable-exports
2068
- var useControlPropsValidator = noop;
2069
- /* istanbul ignore next */
2070
- if (process.env.NODE_ENV !== 'production') {
2071
- useControlPropsValidator = function useControlPropsValidator(_ref2) {
2072
- var props = _ref2.props,
2073
- state = _ref2.state;
2074
- // used for checking when props are moving from controlled to uncontrolled.
2075
- var prevPropsRef = React__namespace.useRef(props);
2076
- var isInitialMount = useIsInitialMount();
2077
- React__namespace.useEffect(function () {
2078
- if (isInitialMount) {
2079
- return;
2080
- }
2081
- validateControlledUnchanged(state, prevPropsRef.current, props);
2082
- prevPropsRef.current = props;
2083
- }, [state, props, isInitialMount]);
2084
- };
2085
- }
2086
-
2087
- /**
2088
- * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
2089
- * In that case, selects the item and resets to defaults for open state and highlighted idex.
2090
- * @param {Object} props The useCombobox props.
2091
- * @param {number} highlightedIndex The index from the state.
2092
- * @param {boolean} inputValue Also return the input value for state.
2093
- * @returns The changes for the state.
2094
- */
2095
- function getChangesOnSelection(props, highlightedIndex, inputValue) {
2096
- var _props$items;
2097
- if (inputValue === void 0) {
2098
- inputValue = true;
2099
- }
2100
- var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
2101
- return _extends({
2102
- isOpen: false,
2103
- highlightedIndex: -1
2104
- }, shouldSelect && _extends({
2105
- selectedItem: props.items[highlightedIndex],
2106
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2107
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
2108
- }, inputValue && {
2109
- inputValue: props.itemToString(props.items[highlightedIndex])
2110
- }));
2111
- }
2112
-
2113
- /**
2114
- * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2115
- * Used by useSelect and useCombobox.
2116
- *
2117
- * @param {Object} prevState
2118
- * @param {Object} newState
2119
- * @returns {boolean} Wheather the states are deeply equal.
2120
- */
2121
- function isDropdownsStateEqual(prevState, newState) {
2122
- return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2106
+ elementRef: elementRef
2107
+ };
2108
+ }, []);
2109
+ return setGetterPropCallInfo;
2110
+ };
2123
2111
  }
2124
2112
 
2113
+ // istanbul ignore next
2114
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2115
+
2125
2116
  /**
2126
- * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2127
- *
2128
- * @param {Object} props Props from useCombobox or useSelect.
2129
- * @returns {number} The highlighted index.
2117
+ * Utility hook that scrolls an item from a menu into view.
2118
+ * @param scrollIntoView The function that does the scroll.
2119
+ * @param highlightedIndex The index of the item that should be scrolled.
2120
+ * @param isOpen If the menu is open or not.
2121
+ * @param menuElement The menu element.
2122
+ * @param itemElements The object containing item elements.
2123
+ * @param getItemId The function to get the item id from index.
2124
+ * @returns Function that when called prevents the scroll.
2130
2125
  */
2131
- function getDefaultHighlightedIndex(props) {
2132
- var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
2133
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2134
- return -1;
2135
- }
2136
- return highlightedIndex;
2126
+ function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
2127
+ // used not to scroll on highlight by mouse.
2128
+ var shouldScrollRef = React__namespace.useRef(true);
2129
+ // Scroll on highlighted item if change comes from keyboard.
2130
+ useIsomorphicLayoutEffect(function () {
2131
+ if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
2132
+ return;
2133
+ }
2134
+ if (shouldScrollRef.current) {
2135
+ var itemElement = itemElements[getItemId(highlightedIndex)];
2136
+ if (itemElement && menuElement) {
2137
+ scrollIntoView(itemElement, menuElement);
2138
+ }
2139
+ } else {
2140
+ shouldScrollRef.current = true;
2141
+ }
2142
+ }, [highlightedIndex]);
2143
+ return React__namespace.useCallback(function preventScroll() {
2144
+ shouldScrollRef.current = false;
2145
+ }, []);
2137
2146
  }
2138
2147
 
2139
2148
  /**
2140
- * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2149
+ * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2150
+ * Used by useSelect and useCombobox.
2141
2151
  *
2142
- * @param {Object} props Props from useCombobox or useSelect.
2143
- * @returns {number} The highlighted index.
2152
+ * @param prevState The previous dropdown state.
2153
+ * @param newState The new dropdown state.
2154
+ * @returns Wheather the states are deeply equal.
2144
2155
  */
2145
- function getInitialHighlightedIndex(props) {
2146
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
2147
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2148
- return -1;
2149
- }
2150
- return highlightedIndex;
2156
+ function isDropdownStateEqual(prevState, newState) {
2157
+ return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2151
2158
  }
2152
2159
 
2153
2160
  function downshiftCommonReducer(state, props, action, stateChangeTypes) {
@@ -2168,13 +2175,13 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2168
2175
  case stateChangeTypes.FunctionToggleMenu:
2169
2176
  changes = {
2170
2177
  isOpen: !state.isOpen,
2171
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
2178
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2172
2179
  };
2173
2180
  break;
2174
2181
  case stateChangeTypes.FunctionOpenMenu:
2175
2182
  changes = {
2176
2183
  isOpen: true,
2177
- highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
2184
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2178
2185
  };
2179
2186
  break;
2180
2187
  case stateChangeTypes.FunctionCloseMenu:
@@ -2183,9 +2190,12 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2183
2190
  };
2184
2191
  break;
2185
2192
  case stateChangeTypes.FunctionSetHighlightedIndex:
2186
- changes = {
2187
- highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
2188
- };
2193
+ {
2194
+ var highlightedIndex = action.highlightedIndex;
2195
+ changes = {
2196
+ highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
2197
+ };
2198
+ }
2189
2199
  break;
2190
2200
  case stateChangeTypes.FunctionSetInputValue:
2191
2201
  changes = {
@@ -2194,10 +2204,10 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2194
2204
  break;
2195
2205
  case stateChangeTypes.FunctionReset:
2196
2206
  changes = {
2197
- highlightedIndex: getDefaultHighlightedIndex(props),
2198
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2199
- selectedItem: getDefaultValue$1(props, 'selectedItem', defaultStateValues$1),
2200
- inputValue: getDefaultValue$1(props, 'inputValue', defaultStateValues$1)
2207
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2208
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2209
+ selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
2210
+ inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
2201
2211
  };
2202
2212
  break;
2203
2213
  default:
@@ -2207,17 +2217,11 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2207
2217
  }
2208
2218
  /* eslint-enable complexity */
2209
2219
 
2210
- var propTypes$3 = _extends({}, propTypes$4, {
2220
+ var propTypes$3 = _extends({}, dropdownPropTypes, {
2211
2221
  items: PropTypes.array.isRequired,
2212
2222
  isItemDisabled: PropTypes.func
2213
2223
  });
2214
2224
 
2215
- var defaultProps$2 = _extends({}, defaultProps$3, {
2216
- isItemDisabled: function isItemDisabled() {
2217
- return false;
2218
- }
2219
- });
2220
-
2221
2225
  function getItemIndexByCharacterKey(_ref) {
2222
2226
  var keysSoFar = _ref.keysSoFar,
2223
2227
  highlightedIndex = _ref.highlightedIndex,
@@ -2286,16 +2290,15 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
2286
2290
  });
2287
2291
 
2288
2292
  /* eslint-disable complexity */
2289
- function downshiftSelectReducer(state, props, action) {
2290
- var _props$items;
2293
+ function downshiftSelectReducer(state, action) {
2291
2294
  var type = action.type,
2292
- altKey = action.altKey;
2295
+ props = action.props;
2293
2296
  var changes;
2294
2297
  switch (type) {
2295
2298
  case ItemClick$1:
2296
2299
  changes = {
2297
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2298
- highlightedIndex: getDefaultHighlightedIndex(props),
2300
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2301
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2299
2302
  selectedItem: props.items[action.index]
2300
2303
  };
2301
2304
  break;
@@ -2322,7 +2325,8 @@ function downshiftSelectReducer(state, props, action) {
2322
2325
  break;
2323
2326
  case ToggleButtonKeyDownArrowDown:
2324
2327
  {
2325
- var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2328
+ var altKey = action.altKey;
2329
+ 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);
2326
2330
  changes = {
2327
2331
  highlightedIndex: _highlightedIndex,
2328
2332
  isOpen: true
@@ -2330,20 +2334,23 @@ function downshiftSelectReducer(state, props, action) {
2330
2334
  }
2331
2335
  break;
2332
2336
  case ToggleButtonKeyDownArrowUp:
2333
- if (state.isOpen && altKey) {
2334
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2335
- } else {
2336
- var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props, state, -1);
2337
- changes = {
2338
- highlightedIndex: _highlightedIndex2,
2339
- isOpen: true
2340
- };
2337
+ {
2338
+ var _altKey = action.altKey;
2339
+ if (state.isOpen && _altKey) {
2340
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2341
+ } else {
2342
+ 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);
2343
+ changes = {
2344
+ highlightedIndex: _highlightedIndex2,
2345
+ isOpen: true
2346
+ };
2347
+ }
2341
2348
  }
2342
2349
  break;
2343
2350
  // only triggered when menu is open.
2344
2351
  case ToggleButtonKeyDownEnter:
2345
2352
  case ToggleButtonKeyDownSpaceButton:
2346
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2353
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2347
2354
  break;
2348
2355
  case ToggleButtonKeyDownHome:
2349
2356
  changes = {
@@ -2377,7 +2384,7 @@ function downshiftSelectReducer(state, props, action) {
2377
2384
  changes = _extends({
2378
2385
  isOpen: false,
2379
2386
  highlightedIndex: -1
2380
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
2387
+ }, state.highlightedIndex >= 0 && props.items.length && {
2381
2388
  selectedItem: props.items[state.highlightedIndex]
2382
2389
  });
2383
2390
  break;
@@ -2393,59 +2400,9 @@ function downshiftSelectReducer(state, props, action) {
2393
2400
  }
2394
2401
  /* eslint-enable complexity */
2395
2402
 
2396
- // eslint-disable-next-line @typescript-eslint/dot-notation
2397
- var reactUseId$1 = React__namespace['useId'];
2398
- var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
2399
- function useElementIdsR18$1(_ref) {
2400
- var id = _ref.id,
2401
- labelId = _ref.labelId,
2402
- menuId = _ref.menuId,
2403
- getItemId = _ref.getItemId,
2404
- toggleButtonId = _ref.toggleButtonId,
2405
- inputId = _ref.inputId;
2406
- var reactId = "downshift-" + reactUseId$1();
2407
- if (!id) {
2408
- id = reactId;
2409
- }
2410
- var elementIds = React__namespace.useMemo(function () {
2411
- return {
2412
- labelId: labelId != null ? labelId : id + "-label",
2413
- menuId: menuId != null ? menuId : id + "-menu",
2414
- getItemId: getItemId != null ? getItemId : function (index) {
2415
- return id + "-item-" + index;
2416
- },
2417
- toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
2418
- inputId: inputId != null ? inputId : id + "-input"
2419
- };
2420
- }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2421
- return elementIds;
2422
- }
2423
- function useElementIdsLegacy$1(_ref2) {
2424
- var id = _ref2.id,
2425
- labelId = _ref2.labelId,
2426
- menuId = _ref2.menuId,
2427
- getItemId = _ref2.getItemId,
2428
- toggleButtonId = _ref2.toggleButtonId,
2429
- inputId = _ref2.inputId;
2430
- var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
2431
- var baseId = baseIdRef.current;
2432
- var elementIds = React__namespace.useMemo(function () {
2433
- return {
2434
- labelId: labelId != null ? labelId : baseId + "-label",
2435
- menuId: menuId != null ? menuId : baseId + "-menu",
2436
- getItemId: getItemId != null ? getItemId : function (index) {
2437
- return baseId + "-item-" + index;
2438
- },
2439
- toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
2440
- inputId: inputId != null ? inputId : baseId + "-input"
2441
- };
2442
- }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
2443
- return elementIds;
2444
- }
2445
-
2446
2403
  var _excluded$3 = ["onClick"],
2447
- _excluded2$3 = ["onMouseLeave", "refKey", "ref"],
2448
- _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
2404
+ _excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
2405
+ _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
2449
2406
  _excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
2450
2407
  useSelect.stateChangeTypes = stateChangeTypes$3;
2451
2408
  function useSelect(userProps) {
@@ -2454,22 +2411,23 @@ function useSelect(userProps) {
2454
2411
  }
2455
2412
  validatePropTypes$1(userProps, useSelect, propTypes$3);
2456
2413
  // Props defaults and destructuring.
2457
- var props = _extends({}, defaultProps$2, userProps);
2414
+ var props = _extends({}, dropdownDefaultProps, userProps);
2458
2415
  var scrollIntoView = props.scrollIntoView,
2459
2416
  environment = props.environment,
2460
2417
  getA11yStatusMessage = props.getA11yStatusMessage;
2461
2418
  // Initial state depending on controlled props.
2462
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownsStateEqual),
2419
+ var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
2463
2420
  state = _useControlledReducer[0],
2464
2421
  dispatch = _useControlledReducer[1];
2465
2422
  var isOpen = state.isOpen,
2466
2423
  highlightedIndex = state.highlightedIndex,
2467
2424
  selectedItem = state.selectedItem,
2468
2425
  inputValue = state.inputValue;
2469
- // Element efs.
2426
+
2427
+ // Element refs.
2470
2428
  var toggleButtonRef = React.useRef(null);
2471
2429
  var menuRef = React.useRef(null);
2472
- var itemRefs = React.useRef({});
2430
+ var itemsRef = React.useRef({});
2473
2431
 
2474
2432
  // used to keep the inputValue clearTimeout object between renders.
2475
2433
  var clearTimeoutRef = React.useRef(null);
@@ -2481,24 +2439,12 @@ function useSelect(userProps) {
2481
2439
  props: props
2482
2440
  });
2483
2441
 
2484
- // Some utils.
2485
- var getItemNodeFromIndex = React.useCallback(function (index) {
2486
- return itemRefs.current[elementIds.getItemId(index)];
2487
- }, [elementIds]);
2488
-
2489
2442
  // Effects.
2490
2443
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
2491
2444
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
2492
2445
  // Scroll on highlighted item if change comes from keyboard.
2493
- var shouldScrollRef = useScrollIntoView({
2494
- menuElement: menuRef.current,
2495
- highlightedIndex: highlightedIndex,
2496
- isOpen: isOpen,
2497
- itemRefs: itemRefs,
2498
- scrollIntoView: scrollIntoView,
2499
- getItemNodeFromIndex: getItemNodeFromIndex
2500
- });
2501
- // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2446
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
2447
+ // Sets cleanup for the keysSoFar callback, debounced after 500ms.
2502
2448
  React.useEffect(function () {
2503
2449
  // init the clean function here as we need access to dispatch.
2504
2450
  clearTimeoutRef.current = debounce(function (outerDispatch) {
@@ -2510,7 +2456,8 @@ function useSelect(userProps) {
2510
2456
 
2511
2457
  // Cancel any pending debounced calls on mount
2512
2458
  return function () {
2513
- clearTimeoutRef.current.cancel();
2459
+ var _clearTimeoutRef$curr;
2460
+ (_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
2514
2461
  };
2515
2462
  }, []);
2516
2463
  // Invokes the keysSoFar callback set up above.
@@ -2518,7 +2465,7 @@ function useSelect(userProps) {
2518
2465
  if (!inputValue) {
2519
2466
  return;
2520
2467
  }
2521
- clearTimeoutRef.current(dispatch);
2468
+ clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
2522
2469
  }, [dispatch, inputValue]);
2523
2470
  useControlPropsValidator({
2524
2471
  props: props,
@@ -2526,7 +2473,7 @@ function useSelect(userProps) {
2526
2473
  });
2527
2474
  // Focus the toggle button on first render if required.
2528
2475
  React.useEffect(function () {
2529
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
2476
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
2530
2477
  if (focusOnOpen && toggleButtonRef.current) {
2531
2478
  toggleButtonRef.current.focus();
2532
2479
  }
@@ -2547,7 +2494,7 @@ function useSelect(userProps) {
2547
2494
  // Reset itemRefs on close.
2548
2495
  React.useEffect(function () {
2549
2496
  if (!isOpen) {
2550
- itemRefs.current = {};
2497
+ itemsRef.current = {};
2551
2498
  }
2552
2499
  }, [isOpen]);
2553
2500
 
@@ -2632,50 +2579,11 @@ function useSelect(userProps) {
2632
2579
  };
2633
2580
  }, [dispatch, latest]);
2634
2581
 
2635
- // Action functions.
2636
- var toggleMenu = React.useCallback(function () {
2637
- dispatch({
2638
- type: FunctionToggleMenu$1
2639
- });
2640
- }, [dispatch]);
2641
- var closeMenu = React.useCallback(function () {
2642
- dispatch({
2643
- type: FunctionCloseMenu$1
2644
- });
2645
- }, [dispatch]);
2646
- var openMenu = React.useCallback(function () {
2647
- dispatch({
2648
- type: FunctionOpenMenu$1
2649
- });
2650
- }, [dispatch]);
2651
- var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
2652
- dispatch({
2653
- type: FunctionSetHighlightedIndex$1,
2654
- highlightedIndex: newHighlightedIndex
2655
- });
2656
- }, [dispatch]);
2657
- var selectItem = React.useCallback(function (newSelectedItem) {
2658
- dispatch({
2659
- type: FunctionSelectItem$1,
2660
- selectedItem: newSelectedItem
2661
- });
2662
- }, [dispatch]);
2663
- var reset = React.useCallback(function () {
2664
- dispatch({
2665
- type: FunctionReset$2
2666
- });
2667
- }, [dispatch]);
2668
- var setInputValue = React.useCallback(function (newInputValue) {
2669
- dispatch({
2670
- type: FunctionSetInputValue$1,
2671
- inputValue: newInputValue
2672
- });
2673
- }, [dispatch]);
2674
2582
  // Getter functions.
2675
- var getLabelProps = React.useCallback(function (_temp) {
2676
- var _ref = _temp === void 0 ? {} : _temp,
2583
+ var getLabelProps = React.useCallback(function (labelProps) {
2584
+ var _ref = labelProps != null ? labelProps : {},
2677
2585
  onClick = _ref.onClick,
2678
- labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2586
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2679
2587
  var labelHandleClick = function labelHandleClick() {
2680
2588
  var _toggleButtonRef$curr;
2681
2589
  (_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
@@ -2684,17 +2592,18 @@ function useSelect(userProps) {
2684
2592
  id: elementIds.labelId,
2685
2593
  htmlFor: elementIds.toggleButtonId,
2686
2594
  onClick: callAllEventHandlers(onClick, labelHandleClick)
2687
- }, labelProps);
2595
+ }, rest);
2688
2596
  }, [elementIds]);
2689
- var getMenuProps = React.useCallback(function (_temp2, _temp3) {
2597
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
2690
2598
  var _extends2;
2691
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2599
+ var _ref2 = menuProps != null ? menuProps : {},
2692
2600
  onMouseLeave = _ref2.onMouseLeave,
2693
2601
  _ref2$refKey = _ref2.refKey,
2694
2602
  refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
2695
2603
  ref = _ref2.ref,
2604
+ ariaLabel = _ref2['aria-label'],
2696
2605
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
2697
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2606
+ var _ref3 = otherProps != null ? otherProps : {},
2698
2607
  _ref3$suppressRefErro = _ref3.suppressRefError,
2699
2608
  suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
2700
2609
  var menuHandleMouseLeave = function menuHandleMouseLeave() {
@@ -2705,11 +2614,11 @@ function useSelect(userProps) {
2705
2614
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2706
2615
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2707
2616
  menuRef.current = menuNode;
2708
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
2617
+ }), _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);
2709
2618
  }, [dispatch, setGetterPropCallInfo, elementIds]);
2710
- var getToggleButtonProps = React.useCallback(function (_temp4, _temp5) {
2619
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
2711
2620
  var _extends3;
2712
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2621
+ var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
2713
2622
  onBlur = _ref4.onBlur,
2714
2623
  onClick = _ref4.onClick;
2715
2624
  _ref4.onPress;
@@ -2717,8 +2626,9 @@ function useSelect(userProps) {
2717
2626
  _ref4$refKey = _ref4.refKey,
2718
2627
  refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
2719
2628
  ref = _ref4.ref,
2629
+ disabled = _ref4.disabled,
2720
2630
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
2721
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2631
+ var _ref5 = otherProps != null ? otherProps : {},
2722
2632
  _ref5$suppressRefErro = _ref5.suppressRefError,
2723
2633
  suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
2724
2634
  var latestState = latest.current.state;
@@ -2736,9 +2646,9 @@ function useSelect(userProps) {
2736
2646
  };
2737
2647
  var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2738
2648
  var key = normalizeArrowKey(event);
2739
- if (key && toggleButtonKeyDownHandlers[key]) {
2649
+ if (key && key in toggleButtonKeyDownHandlers) {
2740
2650
  toggleButtonKeyDownHandlers[key](event);
2741
- } else if (isAcceptedCharacterKey(key)) {
2651
+ } else if (/^\S{1}$/.test(key)) {
2742
2652
  dispatch({
2743
2653
  type: ToggleButtonKeyDownCharacter,
2744
2654
  key: key
@@ -2747,20 +2657,22 @@ function useSelect(userProps) {
2747
2657
  };
2748
2658
  var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2749
2659
  toggleButtonRef.current = toggleButtonNode;
2750
- }), _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);
2751
- if (!rest.disabled) {
2660
+ }), _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);
2661
+ if (!disabled) {
2752
2662
  /* istanbul ignore if (react-native) */
2753
2663
  {
2754
- toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
2755
- toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
2664
+ Object.assign(toggleProps, {
2665
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick),
2666
+ onKeyDown: callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown)
2667
+ });
2756
2668
  }
2757
2669
  }
2758
2670
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2759
2671
  return toggleProps;
2760
2672
  }, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
2761
- var getItemProps = React.useCallback(function (_temp6) {
2673
+ var getItemProps = React.useCallback(function (itemProps) {
2762
2674
  var _extends4;
2763
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
2675
+ var _ref6 = itemProps != null ? itemProps : {},
2764
2676
  itemProp = _ref6.item,
2765
2677
  indexProp = _ref6.index,
2766
2678
  onMouseMove = _ref6.onMouseMove,
@@ -2786,7 +2698,7 @@ function useSelect(userProps) {
2786
2698
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
2787
2699
  return;
2788
2700
  }
2789
- shouldScrollRef.current = false;
2701
+ preventScroll();
2790
2702
  dispatch({
2791
2703
  type: ItemMouseMove$1,
2792
2704
  index: index,
@@ -2803,21 +2715,61 @@ function useSelect(userProps) {
2803
2715
  return e.preventDefault();
2804
2716
  }; // keep focus on the toggle after item click select.
2805
2717
 
2806
- var itemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2718
+ var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2807
2719
  if (itemNode) {
2808
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
2720
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
2809
2721
  }
2810
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2722
+ }), _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);
2811
2723
  if (!disabled) {
2812
2724
  /* istanbul ignore next (react-native) */
2813
2725
  {
2814
- itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2726
+ Object.assign(resultItemProps, {
2727
+ onClick: callAllEventHandlers(onClick, itemHandleClick)
2728
+ });
2815
2729
  }
2816
2730
  }
2817
- itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
2818
- itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
2819
- return itemProps;
2820
- }, [latest, elementIds, mouseAndTouchTrackers, shouldScrollRef, dispatch]);
2731
+ return resultItemProps;
2732
+ }, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
2733
+
2734
+ // Action functions.
2735
+ var toggleMenu = React.useCallback(function () {
2736
+ dispatch({
2737
+ type: FunctionToggleMenu$1
2738
+ });
2739
+ }, [dispatch]);
2740
+ var closeMenu = React.useCallback(function () {
2741
+ dispatch({
2742
+ type: FunctionCloseMenu$1
2743
+ });
2744
+ }, [dispatch]);
2745
+ var openMenu = React.useCallback(function () {
2746
+ dispatch({
2747
+ type: FunctionOpenMenu$1
2748
+ });
2749
+ }, [dispatch]);
2750
+ var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
2751
+ dispatch({
2752
+ type: FunctionSetHighlightedIndex$1,
2753
+ highlightedIndex: newHighlightedIndex
2754
+ });
2755
+ }, [dispatch]);
2756
+ var selectItem = React.useCallback(function (newSelectedItem) {
2757
+ dispatch({
2758
+ type: FunctionSelectItem$1,
2759
+ selectedItem: newSelectedItem
2760
+ });
2761
+ }, [dispatch]);
2762
+ var reset = React.useCallback(function () {
2763
+ dispatch({
2764
+ type: FunctionReset$2
2765
+ });
2766
+ }, [dispatch]);
2767
+ var setInputValue = React.useCallback(function (newInputValue) {
2768
+ dispatch({
2769
+ type: FunctionSetInputValue$1,
2770
+ inputValue: newInputValue
2771
+ });
2772
+ }, [dispatch]);
2821
2773
  return {
2822
2774
  // prop getters.
2823
2775
  getToggleButtonProps: getToggleButtonProps,
@@ -2840,6 +2792,18 @@ function useSelect(userProps) {
2840
2792
  };
2841
2793
  }
2842
2794
 
2795
+ function getInitialState$2(props) {
2796
+ var initialState = getInitialState$3(props);
2797
+ var selectedItem = initialState.selectedItem;
2798
+ var inputValue = initialState.inputValue;
2799
+ if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2800
+ inputValue = props.itemToString(selectedItem);
2801
+ }
2802
+ return _extends({}, initialState, {
2803
+ inputValue: inputValue
2804
+ });
2805
+ }
2806
+
2843
2807
  var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2844
2808
  var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2845
2809
  var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
@@ -2891,27 +2855,6 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2891
2855
  ToggleButtonClick: ToggleButtonClick
2892
2856
  });
2893
2857
 
2894
- function getInitialState$2(props) {
2895
- var initialState = getInitialState$3(props);
2896
- var selectedItem = initialState.selectedItem;
2897
- var inputValue = initialState.inputValue;
2898
- if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2899
- inputValue = props.itemToString(selectedItem);
2900
- }
2901
- return _extends({}, initialState, {
2902
- inputValue: inputValue
2903
- });
2904
- }
2905
- var propTypes$2 = _extends({}, propTypes$4, {
2906
- items: PropTypes.array.isRequired,
2907
- isItemDisabled: PropTypes.func,
2908
- inputValue: PropTypes.string,
2909
- defaultInputValue: PropTypes.string,
2910
- initialInputValue: PropTypes.string,
2911
- inputId: PropTypes.string,
2912
- onInputValueChange: PropTypes.func
2913
- });
2914
-
2915
2858
  /**
2916
2859
  * The useCombobox version of useControlledReducer, which also
2917
2860
  * checks if the controlled prop selectedItem changed between
@@ -2919,20 +2862,20 @@ var propTypes$2 = _extends({}, propTypes$4, {
2919
2862
  * string equivalent. It uses the common useEnhancedReducer to
2920
2863
  * compute the rest of the state.
2921
2864
  *
2922
- * @param {Function} reducer Reducer function from downshift.
2923
- * @param {Object} props The hook props, also passed to createInitialState.
2924
- * @param {Function} createInitialState Function that returns the initial state.
2925
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
2926
- * @returns {Array} An array with the state and an action dispatcher.
2865
+ * @param reducer Reducer function from downshift.
2866
+ * @param props The hook props, also passed to createInitialState.
2867
+ * @param createInitialState Function that returns the initial state.
2868
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
2869
+ * @returns An array with the state and an action dispatcher.
2927
2870
  */
2928
2871
  function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
2929
- var previousSelectedItemRef = React.useRef();
2872
+ var previousSelectedItemRef = React.useRef(null);
2930
2873
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
2931
2874
  state = _useEnhancedReducer[0],
2932
2875
  dispatch = _useEnhancedReducer[1];
2933
2876
  var isInitialMount = useIsInitialMount();
2934
2877
  React.useEffect(function () {
2935
- if (!isControlledProp(props, 'selectedItem')) {
2878
+ if (props.selectedItem === undefined) {
2936
2879
  return;
2937
2880
  }
2938
2881
  if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
@@ -2950,23 +2893,27 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
2950
2893
  }, [state.selectedItem, props.selectedItem]);
2951
2894
  return [getState(state, props), dispatch];
2952
2895
  }
2953
- var defaultProps$1 = _extends({}, defaultProps$3, {
2954
- isItemDisabled: function isItemDisabled() {
2955
- return false;
2956
- }
2896
+
2897
+ var propTypes$2 = _extends({}, dropdownPropTypes, {
2898
+ items: PropTypes.array.isRequired,
2899
+ isItemDisabled: PropTypes.func,
2900
+ inputValue: PropTypes.string,
2901
+ defaultInputValue: PropTypes.string,
2902
+ initialInputValue: PropTypes.string,
2903
+ inputId: PropTypes.string,
2904
+ onInputValueChange: PropTypes.func
2957
2905
  });
2958
2906
 
2959
2907
  /* eslint-disable complexity */
2960
- function downshiftUseComboboxReducer(state, props, action) {
2961
- var _props$items;
2908
+ function downshiftUseComboboxReducer(state, action) {
2962
2909
  var type = action.type,
2963
- altKey = action.altKey;
2910
+ props = action.props;
2964
2911
  var changes;
2965
2912
  switch (type) {
2966
2913
  case ItemClick:
2967
2914
  changes = {
2968
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2969
- highlightedIndex: getDefaultHighlightedIndex(props),
2915
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2916
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2970
2917
  selectedItem: props.items[action.index],
2971
2918
  inputValue: props.itemToString(props.items[action.index])
2972
2919
  };
@@ -2978,15 +2925,15 @@ function downshiftUseComboboxReducer(state, props, action) {
2978
2925
  };
2979
2926
  } else {
2980
2927
  changes = {
2981
- highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
2928
+ highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
2982
2929
  isOpen: props.items.length >= 0
2983
2930
  };
2984
2931
  }
2985
2932
  break;
2986
2933
  case InputKeyDownArrowUp:
2987
2934
  if (state.isOpen) {
2988
- if (altKey) {
2989
- changes = getChangesOnSelection(props, state.highlightedIndex);
2935
+ if (action.altKey) {
2936
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
2990
2937
  } else {
2991
2938
  changes = {
2992
2939
  highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
@@ -2994,13 +2941,13 @@ function downshiftUseComboboxReducer(state, props, action) {
2994
2941
  }
2995
2942
  } else {
2996
2943
  changes = {
2997
- highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
2944
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
2998
2945
  isOpen: props.items.length >= 0
2999
2946
  };
3000
2947
  }
3001
2948
  break;
3002
2949
  case InputKeyDownEnter:
3003
- changes = getChangesOnSelection(props, state.highlightedIndex);
2950
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
3004
2951
  break;
3005
2952
  case InputKeyDownEscape:
3006
2953
  changes = _extends({
@@ -3035,7 +2982,7 @@ function downshiftUseComboboxReducer(state, props, action) {
3035
2982
  changes = _extends({
3036
2983
  isOpen: false,
3037
2984
  highlightedIndex: -1
3038
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
2985
+ }, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
3039
2986
  selectedItem: props.items[state.highlightedIndex],
3040
2987
  inputValue: props.itemToString(props.items[state.highlightedIndex])
3041
2988
  });
@@ -3043,14 +2990,14 @@ function downshiftUseComboboxReducer(state, props, action) {
3043
2990
  case InputChange:
3044
2991
  changes = {
3045
2992
  isOpen: true,
3046
- highlightedIndex: getDefaultHighlightedIndex(props),
2993
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3047
2994
  inputValue: action.inputValue
3048
2995
  };
3049
2996
  break;
3050
2997
  case InputClick:
3051
2998
  changes = {
3052
2999
  isOpen: !state.isOpen,
3053
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
3000
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
3054
3001
  };
3055
3002
  break;
3056
3003
  case FunctionSelectItem:
@@ -3071,10 +3018,10 @@ function downshiftUseComboboxReducer(state, props, action) {
3071
3018
  }
3072
3019
  /* eslint-enable complexity */
3073
3020
 
3074
- var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
3021
+ var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
3075
3022
  _excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
3076
- _excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
3077
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3023
+ _excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
3024
+ _excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3078
3025
  useCombobox.stateChangeTypes = stateChangeTypes$2;
3079
3026
  function useCombobox(userProps) {
3080
3027
  if (userProps === void 0) {
@@ -3082,13 +3029,13 @@ function useCombobox(userProps) {
3082
3029
  }
3083
3030
  validatePropTypes$1(userProps, useCombobox, propTypes$2);
3084
3031
  // Props defaults and destructuring.
3085
- var props = _extends({}, defaultProps$1, userProps);
3032
+ var props = _extends({}, dropdownDefaultProps, userProps);
3086
3033
  var items = props.items,
3087
3034
  scrollIntoView = props.scrollIntoView,
3088
3035
  environment = props.environment,
3089
3036
  getA11yStatusMessage = props.getA11yStatusMessage;
3090
3037
  // Initial state depending on controlled props.
3091
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownsStateEqual),
3038
+ var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
3092
3039
  state = _useControlledReducer[0],
3093
3040
  dispatch = _useControlledReducer[1];
3094
3041
  var isOpen = state.isOpen,
@@ -3098,7 +3045,7 @@ function useCombobox(userProps) {
3098
3045
 
3099
3046
  // Element refs.
3100
3047
  var menuRef = React.useRef(null);
3101
- var itemRefs = React.useRef({});
3048
+ var itemsRef = React.useRef({});
3102
3049
  var inputRef = React.useRef(null);
3103
3050
  var toggleButtonRef = React.useRef(null);
3104
3051
  var isInitialMount = useIsInitialMount();
@@ -3112,29 +3059,19 @@ function useCombobox(userProps) {
3112
3059
  state: state,
3113
3060
  props: props
3114
3061
  });
3115
- var getItemNodeFromIndex = React.useCallback(function (index) {
3116
- return itemRefs.current[elementIds.getItemId(index)];
3117
- }, [elementIds]);
3118
3062
 
3119
3063
  // Effects.
3120
3064
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
3121
3065
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
3122
3066
  // Scroll on highlighted item if change comes from keyboard.
3123
- var shouldScrollRef = useScrollIntoView({
3124
- menuElement: menuRef.current,
3125
- highlightedIndex: highlightedIndex,
3126
- isOpen: isOpen,
3127
- itemRefs: itemRefs,
3128
- scrollIntoView: scrollIntoView,
3129
- getItemNodeFromIndex: getItemNodeFromIndex
3130
- });
3067
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
3131
3068
  useControlPropsValidator({
3132
- props: props,
3133
- state: state
3069
+ state: state,
3070
+ props: props
3134
3071
  });
3135
3072
  // Focus the input on first render if required.
3136
3073
  React.useEffect(function () {
3137
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
3074
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
3138
3075
  if (focusOnOpen && inputRef.current) {
3139
3076
  inputRef.current.focus();
3140
3077
  }
@@ -3160,13 +3097,13 @@ function useCombobox(userProps) {
3160
3097
  // Reset itemRefs on close.
3161
3098
  React.useEffect(function () {
3162
3099
  if (!isOpen) {
3163
- itemRefs.current = {};
3100
+ itemsRef.current = {};
3164
3101
  }
3165
3102
  }, [isOpen]);
3166
3103
  // Reset itemRefs on close.
3167
3104
  React.useEffect(function () {
3168
3105
  var _inputRef$current;
3169
- if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3106
+ if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3170
3107
  return;
3171
3108
  }
3172
3109
  if (environment.document.activeElement !== inputRef.current) {
@@ -3256,29 +3193,30 @@ function useCombobox(userProps) {
3256
3193
  htmlFor: elementIds.inputId
3257
3194
  }, labelProps);
3258
3195
  }, [elementIds]);
3259
- var getMenuProps = React.useCallback(function (_temp, _temp2) {
3196
+ var getMenuProps = React.useCallback(function (menuProps, otherProps) {
3260
3197
  var _extends2;
3261
- var _ref = _temp === void 0 ? {} : _temp,
3198
+ var _ref = menuProps != null ? menuProps : {},
3262
3199
  onMouseLeave = _ref.onMouseLeave,
3263
3200
  _ref$refKey = _ref.refKey,
3264
3201
  refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3265
3202
  ref = _ref.ref,
3203
+ ariaLabel = _ref['aria-label'],
3266
3204
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3267
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3205
+ var _ref2 = otherProps != null ? otherProps : {},
3268
3206
  _ref2$suppressRefErro = _ref2.suppressRefError,
3269
3207
  suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3270
3208
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3271
3209
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3272
3210
  menuRef.current = menuNode;
3273
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3211
+ }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3274
3212
  dispatch({
3275
3213
  type: MenuMouseLeave
3276
3214
  });
3277
3215
  }), _extends2), rest);
3278
3216
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3279
- var getItemProps = React.useCallback(function (_temp3) {
3217
+ var getItemProps = React.useCallback(function (itemProps) {
3280
3218
  var _extends3, _ref4;
3281
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3219
+ var _ref3 = itemProps != null ? itemProps : {},
3282
3220
  itemProp = _ref3.item,
3283
3221
  indexProp = _ref3.index,
3284
3222
  _ref3$refKey = _ref3.refKey,
@@ -3306,7 +3244,7 @@ function useCombobox(userProps) {
3306
3244
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
3307
3245
  return;
3308
3246
  }
3309
- shouldScrollRef.current = false;
3247
+ preventScroll();
3310
3248
  dispatch({
3311
3249
  type: ItemMouseMove,
3312
3250
  index: index,
@@ -3325,21 +3263,22 @@ function useCombobox(userProps) {
3325
3263
 
3326
3264
  return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3327
3265
  if (itemNode) {
3328
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
3266
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
3329
3267
  }
3330
3268
  }), _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), {
3331
3269
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3332
3270
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3333
3271
  }, rest);
3334
- }, [dispatch, elementIds, latest, mouseAndTouchTrackers, shouldScrollRef]);
3335
- var getToggleButtonProps = React.useCallback(function (_temp4) {
3272
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
3273
+ var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
3336
3274
  var _extends4;
3337
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3275
+ var _ref5 = toggleButtonProps != null ? toggleButtonProps : {},
3338
3276
  onClick = _ref5.onClick;
3339
3277
  _ref5.onPress;
3340
3278
  var _ref5$refKey = _ref5.refKey,
3341
3279
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3342
3280
  ref = _ref5.ref,
3281
+ disabled = _ref5.disabled,
3343
3282
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
3344
3283
  var latestState = latest.current.state;
3345
3284
  var toggleButtonHandleClick = function toggleButtonHandleClick() {
@@ -3349,13 +3288,17 @@ function useCombobox(userProps) {
3349
3288
  };
3350
3289
  return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3351
3290
  toggleButtonRef.current = toggleButtonNode;
3352
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
3291
+ }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, {
3353
3292
  onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3354
- }), rest);
3293
+ }), {
3294
+ disabled: disabled
3295
+ }, rest);
3355
3296
  }, [dispatch, latest, elementIds]);
3356
- var getInputProps = React.useCallback(function (_temp5, _temp6) {
3297
+ var getInputProps = React.useCallback(function (inputProps, otherProps) {
3357
3298
  var _extends5;
3358
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3299
+ var _ref6 = inputProps != null ? inputProps : {},
3300
+ ariaLabel = _ref6['aria-label'],
3301
+ disabled = _ref6.disabled,
3359
3302
  onKeyDown = _ref6.onKeyDown,
3360
3303
  onChange = _ref6.onChange,
3361
3304
  onInput = _ref6.onInput,
@@ -3366,15 +3309,16 @@ function useCombobox(userProps) {
3366
3309
  refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3367
3310
  ref = _ref6.ref,
3368
3311
  rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
3369
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3312
+ var _ref7 = otherProps != null ? otherProps : {},
3370
3313
  _ref7$suppressRefErro = _ref7.suppressRefError,
3371
3314
  suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3372
3315
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3373
3316
  var latestState = latest.current.state;
3374
3317
  var inputHandleKeyDown = function inputHandleKeyDown(event) {
3375
3318
  var key = normalizeArrowKey(event);
3376
- if (key && inputKeyDownHandlers[key]) {
3377
- inputKeyDownHandlers[key](event);
3319
+ if (key && key in inputKeyDownHandlers) {
3320
+ var validKey = key;
3321
+ inputKeyDownHandlers[validKey](event);
3378
3322
  }
3379
3323
  };
3380
3324
  var inputHandleChange = function inputHandleChange(event) {
@@ -3402,13 +3346,13 @@ function useCombobox(userProps) {
3402
3346
  /* istanbul ignore next (preact) */
3403
3347
  var onChangeKey = 'onInput' ;
3404
3348
  var eventHandlers = {};
3405
- if (!rest.disabled) {
3349
+ if (!disabled) {
3406
3350
  var _eventHandlers;
3407
3351
  eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
3408
3352
  }
3409
3353
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3410
3354
  inputRef.current = inputNode;
3411
- }), _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);
3355
+ }), _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);
3412
3356
  }, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
3413
3357
 
3414
3358
  // returns
@@ -3478,31 +3422,6 @@ var defaultStateValues = {
3478
3422
  selectedItems: []
3479
3423
  };
3480
3424
 
3481
- /**
3482
- * Returns the initial value for a state key in the following order:
3483
- * 1. controlled prop, 2. initial prop, 3. default prop, 4. default
3484
- * value from Downshift.
3485
- *
3486
- * @param {Object} props Props passed to the hook.
3487
- * @param {string} propKey Props key to generate the value for.
3488
- * @returns {any} The initial value for that prop.
3489
- */
3490
- function getInitialValue(props, propKey) {
3491
- return getInitialValue$1(props, propKey, defaultStateValues);
3492
- }
3493
-
3494
- /**
3495
- * Returns the default value for a state key in the following order:
3496
- * 1. controlled prop, 2. default prop, 3. default value from Downshift.
3497
- *
3498
- * @param {Object} props Props passed to the hook.
3499
- * @param {string} propKey Props key to generate the value for.
3500
- * @returns {any} The initial value for that prop.
3501
- */
3502
- function getDefaultValue(props, propKey) {
3503
- return getDefaultValue$1(props, propKey, defaultStateValues);
3504
- }
3505
-
3506
3425
  /**
3507
3426
  * Gets the initial state based on the provided props. It uses initial, default
3508
3427
  * and controlled props related to state in order to compute the initial value.
@@ -3511,8 +3430,8 @@ function getDefaultValue(props, propKey) {
3511
3430
  * @returns {Object} The initial state.
3512
3431
  */
3513
3432
  function getInitialState$1(props) {
3514
- var activeIndex = getInitialValue(props, 'activeIndex');
3515
- var selectedItems = getInitialValue(props, 'selectedItems');
3433
+ var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
3434
+ var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
3516
3435
  return {
3517
3436
  activeIndex: activeIndex,
3518
3437
  selectedItems: selectedItems
@@ -3556,9 +3475,9 @@ function isStateEqual$1(prevState, newState) {
3556
3475
  return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
3557
3476
  }
3558
3477
  var propTypes$1 = {
3559
- stateReducer: propTypes$4.stateReducer,
3560
- itemToKey: propTypes$4.itemToKey,
3561
- environment: propTypes$4.environment,
3478
+ stateReducer: dropdownPropTypes.stateReducer,
3479
+ itemToKey: dropdownPropTypes.itemToKey,
3480
+ environment: dropdownPropTypes.environment,
3562
3481
  selectedItems: PropTypes.array,
3563
3482
  initialSelectedItems: PropTypes.array,
3564
3483
  defaultSelectedItems: PropTypes.array,
@@ -3572,9 +3491,9 @@ var propTypes$1 = {
3572
3491
  keyNavigationPrevious: PropTypes.string
3573
3492
  };
3574
3493
  var defaultProps = {
3575
- itemToKey: defaultProps$3.itemToKey,
3576
- stateReducer: defaultProps$3.stateReducer,
3577
- environment: defaultProps$3.environment,
3494
+ itemToKey: dropdownDefaultProps.itemToKey,
3495
+ stateReducer: dropdownDefaultProps.stateReducer,
3496
+ environment: dropdownDefaultProps.environment,
3578
3497
  keyNavigationNext: 'ArrowRight',
3579
3498
  keyNavigationPrevious: 'ArrowLeft'
3580
3499
  };
@@ -3620,10 +3539,11 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
3620
3539
  });
3621
3540
 
3622
3541
  /* eslint-disable complexity */
3623
- function downshiftMultipleSelectionReducer(state, props, action) {
3542
+ function downshiftMultipleSelectionReducer(state, action) {
3624
3543
  var type = action.type,
3625
3544
  index = action.index,
3626
- selectedItem = action.selectedItem;
3545
+ selectedItem = action.selectedItem,
3546
+ props = action.props;
3627
3547
  var activeIndex = state.activeIndex,
3628
3548
  selectedItems = state.selectedItems;
3629
3549
  var changes;
@@ -3720,8 +3640,8 @@ function downshiftMultipleSelectionReducer(state, props, action) {
3720
3640
  }
3721
3641
  case FunctionReset:
3722
3642
  changes = {
3723
- activeIndex: getDefaultValue(props, 'activeIndex'),
3724
- selectedItems: getDefaultValue(props, 'selectedItems')
3643
+ activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
3644
+ selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
3725
3645
  };
3726
3646
  break;
3727
3647
  default:
@@ -3953,7 +3873,7 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3953
3873
  TagRemoveClick: TagRemoveClick
3954
3874
  });
3955
3875
 
3956
- function useTagGroupReducer(state, _props, action) {
3876
+ function useTagGroupReducer(state, action) {
3957
3877
  var type = action.type;
3958
3878
  var changes;
3959
3879
  switch (type) {
@@ -4014,8 +3934,9 @@ function useTagGroupReducer(state, _props, action) {
4014
3934
  return _extends({}, state, changes);
4015
3935
  }
4016
3936
 
4017
- // eslint-disable-next-line @typescript-eslint/dot-notation
4018
- var reactUseId = React__namespace['useId'];
3937
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
3938
+ var SafeReact = _extends({}, React__namespace);
3939
+ var reactUseId = SafeReact.useId;
4019
3940
 
4020
3941
  // istanbul ignore next
4021
3942
  var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
@@ -4190,7 +4111,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4190
4111
  'aria-atomic': 'false',
4191
4112
  'aria-relevant': 'additions',
4192
4113
  role: 'listbox',
4193
- onKeyDown: callAllEventHandlers$1(onKeyDown, handleKeyDown)
4114
+ onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
4194
4115
  }, rest);
4195
4116
  return tagGroupProps;
4196
4117
  }, [dispatch, elementIds.tagGroupId]);
@@ -4215,11 +4136,11 @@ var _useTagGroup = function useTagGroup(userProps) {
4215
4136
  var tagId = elementIds.getTagId(index);
4216
4137
  return _extends((_extends2 = {
4217
4138
  'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
4218
- }, _extends2[refKey] = handleRefs$1(ref, function (itemNode) {
4139
+ }, _extends2[refKey] = handleRefs(ref, function (itemNode) {
4219
4140
  if (itemNode) {
4220
4141
  itemRefs.current[tagId] = itemNode;
4221
4142
  }
4222
- }), _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);
4143
+ }), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
4223
4144
  }, [dispatch, elementIds, latest, itemRefs]);
4224
4145
  var getTagRemoveProps = React.useCallback(function (options) {
4225
4146
  var index = options.index,
@@ -4241,7 +4162,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4241
4162
  id: tagRemoveId,
4242
4163
  tabIndex: -1,
4243
4164
  'aria-labelledby': tagRemoveId + " " + tagId,
4244
- onClick: callAllEventHandlers$1(onClick, handleClick)
4165
+ onClick: callAllEventHandlers(onClick, handleClick)
4245
4166
  }, rest);
4246
4167
  }, [elementIds, dispatch]);
4247
4168