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
@@ -2,7 +2,7 @@ import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWith
2
2
  import _extends from '@babel/runtime/helpers/esm/extends';
3
3
  import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
4
4
  import * as React from 'preact/compat';
5
- import { cloneElement, Component, useRef, useCallback, useEffect, useMemo } from 'preact/compat';
5
+ import { cloneElement, Component, useRef, useEffect, useCallback, useMemo } from 'preact/compat';
6
6
  import { isForwardRef } from 'react-is';
7
7
  import { compute } from 'compute-scroll-into-view';
8
8
  import PropTypes from 'prop-types';
@@ -79,7 +79,7 @@ function useLatestRef(val) {
79
79
  return ref;
80
80
  }
81
81
 
82
- function handleRefs$1() {
82
+ function handleRefs() {
83
83
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
84
84
  refs[_key] = arguments[_key];
85
85
  }
@@ -101,7 +101,7 @@ function handleRefs$1() {
101
101
  * @param fns the event handler functions
102
102
  * @return the event handler to add to an element
103
103
  */
104
- function callAllEventHandlers$1() {
104
+ function callAllEventHandlers() {
105
105
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
106
106
  fns[_key] = arguments[_key];
107
107
  }
@@ -123,7 +123,7 @@ function callAllEventHandlers$1() {
123
123
  * function once after the time given has passed since
124
124
  * it was last called.
125
125
  */
126
- function debounce$1(fn, time) {
126
+ function debounce(fn, time) {
127
127
  var timeoutId;
128
128
  function cancel() {
129
129
  if (timeoutId) {
@@ -144,7 +144,7 @@ function debounce$1(fn, time) {
144
144
  return wrapper;
145
145
  }
146
146
 
147
- var cleanupStatus = debounce$1(function (document) {
147
+ var cleanupStatus = debounce(function (document) {
148
148
  getStatusDiv(document).textContent = '';
149
149
  }, 500);
150
150
 
@@ -225,6 +225,8 @@ function getState(state, props) {
225
225
  }
226
226
  var keys = Object.keys(state);
227
227
  return keys.reduce(function (newState, key) {
228
+ // state keys could be in props, but with value undefined, which means they should be ignored.
229
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
228
230
  if (props[key] !== undefined) {
229
231
  newState[key] = props[key];
230
232
  }
@@ -256,93 +258,149 @@ function scrollIntoView(node, menuNode) {
256
258
  }
257
259
 
258
260
  /**
259
- * Accepts a parameter and returns it if it's a function
260
- * or a noop function if it's not. This allows us to
261
- * accept a callback, but not worry about it if it's not
262
- * passed.
263
- * @param {Function} cb the callback
264
- * @return {Function} a function
265
- */
266
- function cbToCb(cb) {
267
- return typeof cb === 'function' ? cb : noop;
268
- }
269
-
270
- /**
271
- * @param {HTMLElement} parent the parent node
272
- * @param {HTMLElement} child the child node
273
- * @param {Window} environment The window context where downshift renders.
274
- * @return {Boolean} whether the parent is the child or the child is in the parent
261
+ * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
262
+ * @param event a keyboardEvent object
263
+ * @return keyboard key
275
264
  */
276
- function isOrContainsNode(parent, child, environment) {
277
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
278
- return result;
265
+ function normalizeArrowKey(event) {
266
+ var key = event.key,
267
+ keyCode = event.keyCode;
268
+ /* istanbul ignore next (ie) */
269
+ if (keyCode >= 37 && keyCode <= 40 && !key.startsWith('Arrow')) {
270
+ return "Arrow" + key;
271
+ }
272
+ return key;
279
273
  }
280
274
 
281
275
  /**
282
- * Simple debounce implementation. Will call the given
283
- * function once after the time given has passed since
284
- * it was last called.
285
- * @param {Function} fn the function to call after the time
286
- * @param {Number} time the time to wait
287
- * @return {Function} the debounced function
276
+ * Returns the next non-disabled highlightedIndex value.
277
+ *
278
+ * @param start The current highlightedIndex.
279
+ * @param backwards If true, it will search backwards from the start.
280
+ * @param items The items array.
281
+ * @param isItemDisabled Function that tells if an item is disabled or not.
282
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
283
+ * @returns The next non-disabled index.
288
284
  */
289
- function debounce(fn, time) {
290
- var timeoutId;
291
- function cancel() {
292
- if (timeoutId) {
293
- clearTimeout(timeoutId);
294
- }
285
+ function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
286
+ if (circular === void 0) {
287
+ circular = false;
295
288
  }
296
- function wrapper() {
297
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
298
- args[_key] = arguments[_key];
289
+ var count = items.length;
290
+ if (backwards) {
291
+ for (var index = start; index >= 0; index--) {
292
+ if (!isItemDisabled(items[index], index)) {
293
+ return index;
294
+ }
295
+ }
296
+ } else {
297
+ for (var _index = start; _index < count; _index++) {
298
+ if (!isItemDisabled(items[_index], _index)) {
299
+ return _index;
300
+ }
299
301
  }
300
- cancel();
301
- timeoutId = setTimeout(function () {
302
- timeoutId = null;
303
- fn.apply(void 0, args);
304
- }, time);
305
302
  }
306
- wrapper.cancel = cancel;
307
- return wrapper;
303
+ if (circular) {
304
+ return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
305
+ }
306
+ return -1;
308
307
  }
309
308
 
310
309
  /**
311
- * This is intended to be used to compose event handlers.
312
- * They are executed in order until one of them sets
313
- * `event.preventDownshiftDefault = true`.
314
- * @param {...Function} fns the event handler functions
315
- * @return {Function} the event handler to add to an element
310
+ * Returns the next non-disabled highlightedIndex value.
311
+ *
312
+ * @param start The current highlightedIndex.
313
+ * @param offset The offset from the current highlightedIndex to start searching.
314
+ * @param items The items array.
315
+ * @param isItemDisabled Function that tells if an item is disabled or not.
316
+ * @param circular If the search reaches the end, if it can search again starting from the other end.
317
+ * @returns The next highlightedIndex.
316
318
  */
317
- function callAllEventHandlers() {
318
- for (var _len2 = arguments.length, fns = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
319
- fns[_key2] = arguments[_key2];
319
+ function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
320
+ if (circular === void 0) {
321
+ circular = false;
320
322
  }
321
- return function (event) {
322
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
323
- args[_key3 - 1] = arguments[_key3];
324
- }
325
- return fns.some(function (fn) {
326
- if (fn) {
327
- fn.apply(void 0, [event].concat(args));
323
+ var count = items.length;
324
+ if (count === 0) {
325
+ return -1;
326
+ }
327
+ var itemsLastIndex = count - 1;
328
+ if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
329
+ start = offset > 0 ? -1 : itemsLastIndex + 1;
330
+ }
331
+ var current = start + offset;
332
+ if (current < 0) {
333
+ current = circular ? itemsLastIndex : 0;
334
+ } else if (current > itemsLastIndex) {
335
+ current = circular ? 0 : itemsLastIndex;
336
+ }
337
+ var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
338
+ if (highlightedIndex === -1) {
339
+ return start >= count ? -1 : start;
340
+ }
341
+ return highlightedIndex;
342
+ }
343
+
344
+ /* eslint-disable @typescript-eslint/no-explicit-any */
345
+
346
+ // eslint-disable-next-line import/no-mutable-exports
347
+ var validateControlledUnchanged = noop;
348
+ /* istanbul ignore next */
349
+ if (process.env.NODE_ENV !== 'production') {
350
+ validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
351
+ 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";
352
+ Object.keys(state).forEach(function (propKey) {
353
+ if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
354
+ // eslint-disable-next-line no-console
355
+ console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
356
+ } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
357
+ // eslint-disable-next-line no-console
358
+ console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
328
359
  }
329
- return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
330
360
  });
331
361
  };
332
362
  }
333
- function handleRefs() {
334
- for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
335
- refs[_key4] = arguments[_key4];
363
+
364
+ /**
365
+ * Checks if event target is within the downshift elements.
366
+ *
367
+ * @param target Target to check.
368
+ * @param downshiftElements The elements that form downshift (list, toggle button etc).
369
+ * @param environment The window context where downshift renders.
370
+ * @param checkActiveElement Whether to also check activeElement.
371
+ *
372
+ * @returns Whether or not the target is within downshift elements.
373
+ */
374
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
375
+ if (checkActiveElement === void 0) {
376
+ checkActiveElement = true;
336
377
  }
337
- return function (node) {
338
- refs.forEach(function (ref) {
339
- if (typeof ref === 'function') {
340
- ref(node);
341
- } else if (ref) {
342
- ref.current = node;
343
- }
344
- });
345
- };
378
+ return !!environment && downshiftElements.some(function (contextNode) {
379
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
380
+ });
381
+ }
382
+
383
+ /**
384
+ * @param parent the parent node
385
+ * @param child the child node
386
+ * @param environment The window context where downshift renders.
387
+ * @return Whether the parent is the child or the child is in the parent
388
+ */
389
+ function isOrContainsNode(parent, child, environment) {
390
+ var result = parent === child || child instanceof environment.Node && parent.contains(child);
391
+ return result;
392
+ }
393
+
394
+ /**
395
+ * Accepts a parameter and returns it if it's a function
396
+ * or a noop function if it's not. This allows us to
397
+ * accept a callback, but not worry about it if it's not
398
+ * passed.
399
+ * @param {Function} cb the callback
400
+ * @return {Function} a function
401
+ */
402
+ function cbToCb(cb) {
403
+ return typeof cb === 'function' ? cb : noop;
346
404
  }
347
405
 
348
406
  /**
@@ -438,34 +496,6 @@ function pickState(state) {
438
496
  return result;
439
497
  }
440
498
 
441
- /**
442
- * This determines whether a prop is a "controlled prop" meaning it is
443
- * state which is controlled by the outside of this component rather
444
- * than within this component.
445
- *
446
- * @param {Object} props The props that may contain controlled values.
447
- * @param {String} key the key to check
448
- * @return {Boolean} whether it is a controlled controlled prop
449
- */
450
- function isControlledProp(props, key) {
451
- return props[key] !== undefined;
452
- }
453
-
454
- /**
455
- * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
456
- * @param {Object} event a keyboardEvent object
457
- * @return {String} keyboard key
458
- */
459
- function normalizeArrowKey(event) {
460
- var key = event.key,
461
- keyCode = event.keyCode;
462
- /* istanbul ignore next (ie) */
463
- if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
464
- return "Arrow" + key;
465
- }
466
- return key;
467
- }
468
-
469
499
  /**
470
500
  * Simple check if the value passed is object literal
471
501
  * @param {*} obj any things
@@ -475,112 +505,6 @@ function isPlainObject(obj) {
475
505
  return Object.prototype.toString.call(obj) === '[object Object]';
476
506
  }
477
507
 
478
- /**
479
- * Returns the next non-disabled highlightedIndex value.
480
- *
481
- * @param {number} start The current highlightedIndex.
482
- * @param {number} offset The offset from the current highlightedIndex to start searching.
483
- * @param {unknown[]} items The items array.
484
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
485
- * @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
486
- * @returns {number} The next highlightedIndex.
487
- */
488
- function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
489
- if (circular === void 0) {
490
- circular = false;
491
- }
492
- var count = items.length;
493
- if (count === 0) {
494
- return -1;
495
- }
496
- var itemsLastIndex = count - 1;
497
- if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
498
- start = offset > 0 ? -1 : itemsLastIndex + 1;
499
- }
500
- var current = start + offset;
501
- if (current < 0) {
502
- current = circular ? itemsLastIndex : 0;
503
- } else if (current > itemsLastIndex) {
504
- current = circular ? 0 : itemsLastIndex;
505
- }
506
- var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
507
- if (highlightedIndex === -1) {
508
- return start >= count ? -1 : start;
509
- }
510
- return highlightedIndex;
511
- }
512
-
513
- /**
514
- * Returns the next non-disabled highlightedIndex value.
515
- *
516
- * @param {number} start The current highlightedIndex.
517
- * @param {boolean} backwards If true, it will search backwards from the start.
518
- * @param {unknown[]} items The items array.
519
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
520
- * @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
521
- * @returns {number} The next non-disabled index.
522
- */
523
- function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
524
- if (circular === void 0) {
525
- circular = false;
526
- }
527
- var count = items.length;
528
- if (backwards) {
529
- for (var index = start; index >= 0; index--) {
530
- if (!isItemDisabled(items[index], index)) {
531
- return index;
532
- }
533
- }
534
- } else {
535
- for (var _index = start; _index < count; _index++) {
536
- if (!isItemDisabled(items[_index], _index)) {
537
- return _index;
538
- }
539
- }
540
- }
541
- if (circular) {
542
- return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
543
- }
544
- return -1;
545
- }
546
-
547
- /**
548
- * Checks if event target is within the downshift elements.
549
- *
550
- * @param {EventTarget} target Target to check.
551
- * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
552
- * @param {Window} environment The window context where downshift renders.
553
- * @param {boolean} checkActiveElement Whether to also check activeElement.
554
- *
555
- * @returns {boolean} Whether or not the target is within downshift elements.
556
- */
557
- function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
558
- if (checkActiveElement === void 0) {
559
- checkActiveElement = true;
560
- }
561
- return environment && downshiftElements.some(function (contextNode) {
562
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
563
- });
564
- }
565
-
566
- // eslint-disable-next-line import/no-mutable-exports
567
- var validateControlledUnchanged = noop;
568
- /* istanbul ignore next */
569
- if (process.env.NODE_ENV !== 'production') {
570
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
571
- 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";
572
- Object.keys(state).forEach(function (propKey) {
573
- if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
574
- // eslint-disable-next-line no-console
575
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
576
- } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
577
- // eslint-disable-next-line no-console
578
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
579
- }
580
- });
581
- };
582
- }
583
-
584
508
  var _excluded$4 = ["refKey", "ref"],
585
509
  _excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
586
510
  _excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
@@ -731,7 +655,7 @@ var Downshift = /*#__PURE__*/function () {
731
655
  }
732
656
  newStateToSet[key];
733
657
  // if it's coming from props, then we don't care to set it internally
734
- if (!isControlledProp(_this.props, key)) {
658
+ if (_this.props[key] === undefined) {
735
659
  nextState[key] = newStateToSet[key];
736
660
  }
737
661
  });
@@ -1465,7 +1389,7 @@ var Downshift = /*#__PURE__*/function () {
1465
1389
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1466
1390
  }
1467
1391
  }
1468
- if (isControlledProp(this.props, 'selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1392
+ if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1469
1393
  this.internalSetState({
1470
1394
  type: controlledPropUpdatedSelectedItem,
1471
1395
  inputValue: this.props.itemToString(this.props.selectedItem)
@@ -1605,7 +1529,7 @@ function callOnChangeProps(action, props, state, newState) {
1605
1529
  changes[key] = newState[key];
1606
1530
  }
1607
1531
  }
1608
- if (props.onStateChange && Object.keys(changes).length) {
1532
+ if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
1609
1533
  props.onStateChange(_extends({
1610
1534
  type: type
1611
1535
  }, changes));
@@ -1631,50 +1555,53 @@ function invokeOnChangeHandler(key, action, props, state, newState) {
1631
1555
  * two reducers, one from downshift and an optional one from the user.
1632
1556
  * Also calls the onChange handlers for state values that have changed.
1633
1557
  *
1634
- * @param {Function} reducer Reducer function from downshift.
1635
- * @param {Object} props The hook props, also passed to createInitialState.
1636
- * @param {Function} createInitialState Function that returns the initial state.
1637
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1638
- * @returns {Array} An array with the state and an action dispatcher.
1558
+ * @param reducer Reducer function from downshift.
1559
+ * @param props The hook props, also passed to createInitialState.
1560
+ * @param createInitialState Function that returns the initial state.
1561
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1562
+ * @returns An array with the state and an action dispatcher.
1639
1563
  */
1640
1564
  function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
1641
- var prevStateRef = React.useRef(null);
1642
- var actionRef = React.useRef(undefined);
1643
- var propsRef = useLatestRef(props);
1565
+ var prevStateRef = React.useRef({});
1566
+ var actionRef = React.useRef();
1644
1567
  var enhancedReducer = React.useCallback(function (state, action) {
1645
1568
  actionRef.current = action;
1646
- state = getState(state, propsRef.current);
1647
- var changes = reducer(state, propsRef.current, action);
1648
- var newState = propsRef.current.stateReducer(state, _extends({}, action, {
1569
+ state = getState(state, action.props);
1570
+ var changes = reducer(state, action);
1571
+ var newState = action.props.stateReducer(state, _extends({}, action, {
1649
1572
  changes: changes
1650
1573
  }));
1651
1574
  return _extends({}, state, newState);
1652
- }, [propsRef, reducer]);
1575
+ }, [reducer]);
1653
1576
  var _React$useReducer = React.useReducer(enhancedReducer, props, createInitialState),
1654
1577
  state = _React$useReducer[0],
1655
1578
  dispatch = _React$useReducer[1];
1579
+ var propsRef = useLatestRef(props);
1580
+ var dispatchWithProps = React.useCallback(function (action) {
1581
+ return dispatch(_extends({}, action, {
1582
+ props: propsRef.current
1583
+ }));
1584
+ }, [propsRef]);
1656
1585
  var action = actionRef.current;
1657
1586
  React.useEffect(function () {
1658
- var _prevStateRef$current;
1659
- var prevState = getState((_prevStateRef$current = prevStateRef.current) != null ? _prevStateRef$current : {}, propsRef.current);
1660
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
1587
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
1588
+ var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
1661
1589
  if (shouldCallOnChangeProps) {
1662
- callOnChangeProps(action, propsRef.current, prevState, state);
1590
+ callOnChangeProps(action, action.props, prevState, state);
1663
1591
  }
1664
1592
  prevStateRef.current = state;
1665
- }, [state, action, isStateEqual, propsRef]);
1666
- return [state, dispatch];
1593
+ }, [state, action, isStateEqual]);
1594
+ return [state, dispatchWithProps];
1667
1595
  }
1668
1596
 
1669
1597
  /**
1670
1598
  * Wraps the useEnhancedReducer and applies the controlled prop values before
1671
1599
  * returning the new state.
1672
- *
1673
- * @param {Function} reducer Reducer function from downshift.
1674
- * @param {Object} props The hook props, also passed to createInitialState.
1675
- * @param {Function} createInitialState Function that returns the initial state.
1676
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1677
- * @returns {Array} An array with the state and an action dispatcher.
1600
+ * @param reducer Reducer function from downshift.
1601
+ * @param props The hook props, also passed to createInitialState.
1602
+ * @param createInitialState Function that returns the initial state.
1603
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1604
+ * @returns An array with the state and an action dispatcher.
1678
1605
  */
1679
1606
  function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
1680
1607
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
@@ -1727,16 +1654,8 @@ function useIsInitialMount() {
1727
1654
  return isInitialMountRef.current;
1728
1655
  }
1729
1656
 
1730
- /**
1731
- * Default state reducer that returns the changes.
1732
- *
1733
- */
1734
- function stateReducer(_s, a) {
1735
- return a.changes;
1736
- }
1737
-
1738
1657
  // Shared between all exports.
1739
- var propTypes$5 = {
1658
+ var propTypes$4 = {
1740
1659
  environment: PropTypes.shape({
1741
1660
  addEventListener: PropTypes.func.isRequired,
1742
1661
  removeEventListener: PropTypes.func.isRequired,
@@ -1752,30 +1671,47 @@ var propTypes$5 = {
1752
1671
  stateReducer: PropTypes.func
1753
1672
  };
1754
1673
 
1755
- function getDefaultValue$1(props, propKey, defaultStateValues) {
1756
- var defaultValue = props["default" + capitalizeString(propKey)];
1757
- if (defaultValue !== undefined) {
1758
- return defaultValue;
1759
- }
1760
- return defaultStateValues[propKey];
1674
+ /**
1675
+ * Returns the default value based on the defaultProp and defaultStateValue.
1676
+ *
1677
+ * @param defaultProp The default prop value.
1678
+ * @param defaultStateValue The default state value.
1679
+ * @returns The resolved default value.
1680
+ */
1681
+ function getDefaultValue(defaultProp, defaultStateValue) {
1682
+ return defaultProp === undefined ? defaultStateValue : defaultProp;
1761
1683
  }
1762
1684
 
1763
- function getInitialValue$1(props, propKey, defaultStateValues) {
1764
- var value = props[propKey];
1685
+ /**
1686
+ * Returns the initial value for a state variable, based on the following precedence:
1687
+ * 1. The controlled value (if it's not undefined)
1688
+ * 2. The initialValue (if it's not undefined)
1689
+ * 3. The defaultValue (if it's not undefined)
1690
+ * 4. The defaultStateValue
1691
+ *
1692
+ * @param value The controlled value of the state variable.
1693
+ * @param initialValue The initial value of the state variable.
1694
+ * @param defaultValue The default value of the state variable.
1695
+ * @param defaultStateValue The default state value to use if all other values are undefined.
1696
+ * @returns The initial value for the state variable.
1697
+ */
1698
+ function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
1765
1699
  if (value !== undefined) {
1766
1700
  return value;
1767
1701
  }
1768
- var initialValue = props["initial" + capitalizeString(propKey)];
1769
1702
  if (initialValue !== undefined) {
1770
1703
  return initialValue;
1771
1704
  }
1772
- return getDefaultValue$1(props, propKey, defaultStateValues);
1705
+ if (defaultValue !== undefined) {
1706
+ return defaultValue;
1707
+ }
1708
+ return defaultStateValue;
1773
1709
  }
1774
1710
 
1775
1711
  /**
1776
1712
  * Debounced call for updating the a11y message.
1777
1713
  */
1778
- var updateA11yStatus = debounce$1(function (status, document) {
1714
+ var updateA11yStatus = debounce(function (status, document) {
1779
1715
  setStatus(status, document);
1780
1716
  }, 200);
1781
1717
 
@@ -1811,7 +1747,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
1811
1747
  }
1812
1748
 
1813
1749
  // Shared between useSelect, useCombobox, Downshift.
1814
- var propTypes$4 = _extends({}, propTypes$5, {
1750
+ var dropdownPropTypes = _extends({}, propTypes$4, {
1815
1751
  getA11yStatusMessage: PropTypes.func,
1816
1752
  highlightedIndex: PropTypes.number,
1817
1753
  defaultHighlightedIndex: PropTypes.number,
@@ -1834,62 +1770,145 @@ var propTypes$4 = _extends({}, propTypes$5, {
1834
1770
  scrollIntoView: PropTypes.func
1835
1771
  });
1836
1772
 
1837
- var defaultProps$3 = {
1773
+ var dropdownDefaultProps = {
1838
1774
  itemToString: function itemToString(item) {
1839
1775
  return item ? String(item) : '';
1840
1776
  },
1841
1777
  itemToKey: function itemToKey(item) {
1842
1778
  return item;
1843
1779
  },
1844
- stateReducer: stateReducer,
1780
+ isItemDisabled: function isItemDisabled(_item) {
1781
+ return false;
1782
+ },
1783
+ stateReducer: function stateReducer(_state, actionAndChanges) {
1784
+ return actionAndChanges.changes;
1785
+ },
1845
1786
  scrollIntoView: scrollIntoView,
1846
1787
  environment: /* istanbul ignore next (ssr) */
1847
1788
  typeof window === 'undefined' || false ? undefined : window
1848
1789
  };
1849
1790
 
1850
- var defaultStateValues$1 = {
1791
+ var dropdownDefaultStateValues = {
1851
1792
  highlightedIndex: -1,
1852
1793
  isOpen: false,
1853
1794
  selectedItem: null,
1854
1795
  inputValue: ''
1855
1796
  };
1856
1797
 
1857
- // istanbul ignore next
1858
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React.useLayoutEffect : React.useEffect;
1859
- function isAcceptedCharacterKey(key) {
1860
- return /^\S{1}$/.test(key);
1798
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
1799
+ var SafeReact$1 = _extends({}, React);
1800
+ var reactUseId$1 = SafeReact$1.useId;
1801
+ var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
1802
+ function useElementIdsR18$1(_ref) {
1803
+ var id = _ref.id,
1804
+ labelId = _ref.labelId,
1805
+ menuId = _ref.menuId,
1806
+ getItemId = _ref.getItemId,
1807
+ toggleButtonId = _ref.toggleButtonId,
1808
+ inputId = _ref.inputId;
1809
+ var reactId = "downshift-" + reactUseId$1();
1810
+ if (!id) {
1811
+ id = reactId;
1812
+ }
1813
+ var elementIds = React.useMemo(function () {
1814
+ return {
1815
+ labelId: labelId != null ? labelId : id + "-label",
1816
+ menuId: menuId != null ? menuId : id + "-menu",
1817
+ getItemId: getItemId != null ? getItemId : function (index) {
1818
+ return id + "-item-" + index;
1819
+ },
1820
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
1821
+ inputId: inputId != null ? inputId : id + "-input"
1822
+ };
1823
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1824
+ return elementIds;
1861
1825
  }
1862
- function getInitialState$3(props) {
1863
- var selectedItem = getInitialValue$1(props, 'selectedItem', defaultStateValues$1);
1864
- var isOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
1865
- var highlightedIndex = getInitialHighlightedIndex(props);
1866
- var inputValue = getInitialValue$1(props, 'inputValue', defaultStateValues$1);
1867
- return {
1868
- highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1869
- return props.itemToKey(item) === props.itemToKey(selectedItem);
1870
- }) : highlightedIndex,
1871
- isOpen: isOpen,
1872
- selectedItem: selectedItem,
1873
- inputValue: inputValue
1874
- };
1826
+ function useElementIdsLegacy$1(_ref2) {
1827
+ var id = _ref2.id,
1828
+ labelId = _ref2.labelId,
1829
+ menuId = _ref2.menuId,
1830
+ getItemId = _ref2.getItemId,
1831
+ toggleButtonId = _ref2.toggleButtonId,
1832
+ inputId = _ref2.inputId;
1833
+ var baseIdRef = React.useRef(id != null ? id : "downshift-" + generateId());
1834
+ var baseId = baseIdRef.current;
1835
+ var elementIds = React.useMemo(function () {
1836
+ return {
1837
+ labelId: labelId != null ? labelId : baseId + "-label",
1838
+ menuId: menuId != null ? menuId : baseId + "-menu",
1839
+ getItemId: getItemId != null ? getItemId : function (index) {
1840
+ return baseId + "-item-" + index;
1841
+ },
1842
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
1843
+ inputId: inputId != null ? inputId : baseId + "-input"
1844
+ };
1845
+ }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
1846
+ return elementIds;
1875
1847
  }
1876
- function getHighlightedIndexOnOpen(props, state, offset) {
1877
- var items = props.items,
1878
- initialHighlightedIndex = props.initialHighlightedIndex,
1879
- defaultHighlightedIndex = props.defaultHighlightedIndex,
1880
- isItemDisabled = props.isItemDisabled,
1881
- itemToKey = props.itemToKey;
1882
- var selectedItem = state.selectedItem,
1883
- highlightedIndex = state.highlightedIndex;
1848
+
1849
+ /**
1850
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
1851
+ *
1852
+ * @param props Props passed to the hook.
1853
+ * @returns The highlighted index.
1854
+ */
1855
+ function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
1856
+ var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
1857
+ if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
1858
+ return -1;
1859
+ }
1860
+ return highlightedIndex;
1861
+ }
1862
+
1863
+ /**
1864
+ * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
1865
+ * In that case, selects the item and resets to defaults for open state and highlighted idex.
1866
+ *
1867
+ * @param props The Dropdown props.
1868
+ * @param highlightedIndex The index from the state.
1869
+ * @param inputValue Also return the input value for state.
1870
+ * @returns The changes for the state.
1871
+ */
1872
+ function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
1873
+ var shouldSelect = items.length && highlightedIndex >= 0;
1874
+ return _extends({
1875
+ isOpen: false,
1876
+ highlightedIndex: -1
1877
+ }, shouldSelect && _extends({
1878
+ selectedItem: items[highlightedIndex],
1879
+ isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
1880
+ highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
1881
+ }, inputValue && {
1882
+ inputValue: itemToString(items[highlightedIndex])
1883
+ }));
1884
+ }
1885
+
1886
+ /* eslint-disable max-params */
1887
+ /**
1888
+ * Returns the highlighted index when the menu is opened.
1889
+ * Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
1890
+ * selectedItem, and the open direction offset.
1891
+ *
1892
+ * @param items The list of items.
1893
+ * @param initialHighlightedIndex The initial highlighted index prop.
1894
+ * @param defaultHighlightedIndex The default highlighted index prop.
1895
+ * @param isItemDisabled Callback to determine if an item is disabled.
1896
+ * @param itemToKey Callback to get a unique key from an item.
1897
+ * @param selectedItem The currently selected item.
1898
+ * @param highlightedIndex The current highlighted index from state.
1899
+ * @param offset The direction of navigation: positive opens downward, negative opens upward.
1900
+ * @returns The new highlighted index.
1901
+ */
1902
+ function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
1884
1903
  if (items.length === 0) {
1885
1904
  return -1;
1886
1905
  }
1887
1906
 
1888
1907
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
1889
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1908
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1890
1909
  return initialHighlightedIndex;
1891
1910
  }
1892
- if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1911
+ if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1893
1912
  return defaultHighlightedIndex;
1894
1913
  }
1895
1914
  if (selectedItem) {
@@ -1897,21 +1916,71 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1897
1916
  return itemToKey(selectedItem) === itemToKey(item);
1898
1917
  });
1899
1918
  }
1900
- if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1919
+ if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1901
1920
  return items.length - 1;
1902
1921
  }
1903
- if (offset > 0 && !isItemDisabled(items[0], 0)) {
1922
+ if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
1904
1923
  return 0;
1905
1924
  }
1906
1925
  return -1;
1907
1926
  }
1927
+
1928
+ function getInitialState$3(props) {
1929
+ var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
1930
+ var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
1931
+ var highlightedIndex = getInitialHighlightedIndex(props);
1932
+ var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
1933
+ return {
1934
+ highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1935
+ return props.itemToKey(item) === props.itemToKey(selectedItem);
1936
+ }) : highlightedIndex,
1937
+ isOpen: isOpen,
1938
+ selectedItem: selectedItem,
1939
+ inputValue: inputValue
1940
+ };
1941
+ }
1942
+
1943
+ /**
1944
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
1945
+ * @param props Props from useCombobox or useSelect.
1946
+ * @returns The highlighted index.
1947
+ */
1948
+ function getInitialHighlightedIndex(props) {
1949
+ var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
1950
+ if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
1951
+ return -1;
1952
+ }
1953
+ return highlightedIndex;
1954
+ }
1955
+
1956
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1957
+ // eslint-disable-next-line import/no-mutable-exports
1958
+ var useControlPropsValidator = noop;
1959
+ /* istanbul ignore next */
1960
+ if (process.env.NODE_ENV !== 'production') {
1961
+ useControlPropsValidator = function useControlPropsValidator(_ref) {
1962
+ var props = _ref.props,
1963
+ state = _ref.state;
1964
+ // used for checking when props are moving from controlled to uncontrolled.
1965
+ var prevPropsRef = React.useRef(props);
1966
+ var isInitialMount = useIsInitialMount();
1967
+ React.useEffect(function () {
1968
+ if (isInitialMount) {
1969
+ return;
1970
+ }
1971
+ validateControlledUnchanged(state, prevPropsRef.current, props);
1972
+ prevPropsRef.current = props;
1973
+ }, [state, props, isInitialMount]);
1974
+ };
1975
+ }
1976
+
1908
1977
  /**
1909
1978
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
1910
1979
  *
1911
- * @param {Window} environment The environment to add the event listeners to, for instance window.
1912
- * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1913
- * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
1914
- * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
1980
+ * @param environment The environment to add the event listeners to, for instance window.
1981
+ * @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1982
+ * @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
1983
+ * @returns The mouse and touch events information.
1915
1984
  */
1916
1985
  function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
1917
1986
  var mouseAndTouchTrackersRef = React.useRef({
@@ -1975,8 +2044,8 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1975
2044
  /**
1976
2045
  * Custom hook that checks if getter props are called correctly.
1977
2046
  *
1978
- * @param {...any} propKeys Getter prop names to be handled.
1979
- * @returns {Function} Setter function called inside getter props to set call information.
2047
+ * @param propKeys Getter prop names to be handled.
2048
+ * @returns Setter function called inside getter props to set call information.
1980
2049
  */
1981
2050
  /* istanbul ignore next */
1982
2051
  if (process.env.NODE_ENV !== 'production') {
@@ -2012,120 +2081,58 @@ if (process.env.NODE_ENV !== 'production') {
2012
2081
  getterPropsCalledRef.current[propKey] = {
2013
2082
  suppressRefError: suppressRefError,
2014
2083
  refKey: refKey,
2015
- elementRef: elementRef
2016
- };
2017
- }, []);
2018
- return setGetterPropCallInfo;
2019
- };
2020
- }
2021
- function useScrollIntoView(_ref) {
2022
- var highlightedIndex = _ref.highlightedIndex,
2023
- isOpen = _ref.isOpen,
2024
- itemRefs = _ref.itemRefs,
2025
- getItemNodeFromIndex = _ref.getItemNodeFromIndex,
2026
- menuElement = _ref.menuElement,
2027
- scrollIntoViewProp = _ref.scrollIntoView;
2028
- // used not to scroll on highlight by mouse.
2029
- var shouldScrollRef = React.useRef(true);
2030
- // Scroll on highlighted item if change comes from keyboard.
2031
- useIsomorphicLayoutEffect(function () {
2032
- if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2033
- return;
2034
- }
2035
- if (shouldScrollRef.current === false) {
2036
- shouldScrollRef.current = true;
2037
- } else {
2038
- scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
2039
- }
2040
- // eslint-disable-next-line react-hooks/exhaustive-deps
2041
- }, [highlightedIndex]);
2042
- return shouldScrollRef;
2043
- }
2044
-
2045
- // eslint-disable-next-line import/no-mutable-exports
2046
- var useControlPropsValidator = noop;
2047
- /* istanbul ignore next */
2048
- if (process.env.NODE_ENV !== 'production') {
2049
- useControlPropsValidator = function useControlPropsValidator(_ref2) {
2050
- var props = _ref2.props,
2051
- state = _ref2.state;
2052
- // used for checking when props are moving from controlled to uncontrolled.
2053
- var prevPropsRef = React.useRef(props);
2054
- var isInitialMount = useIsInitialMount();
2055
- React.useEffect(function () {
2056
- if (isInitialMount) {
2057
- return;
2058
- }
2059
- validateControlledUnchanged(state, prevPropsRef.current, props);
2060
- prevPropsRef.current = props;
2061
- }, [state, props, isInitialMount]);
2062
- };
2063
- }
2064
-
2065
- /**
2066
- * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
2067
- * In that case, selects the item and resets to defaults for open state and highlighted idex.
2068
- * @param {Object} props The useCombobox props.
2069
- * @param {number} highlightedIndex The index from the state.
2070
- * @param {boolean} inputValue Also return the input value for state.
2071
- * @returns The changes for the state.
2072
- */
2073
- function getChangesOnSelection(props, highlightedIndex, inputValue) {
2074
- var _props$items;
2075
- if (inputValue === void 0) {
2076
- inputValue = true;
2077
- }
2078
- var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
2079
- return _extends({
2080
- isOpen: false,
2081
- highlightedIndex: -1
2082
- }, shouldSelect && _extends({
2083
- selectedItem: props.items[highlightedIndex],
2084
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2085
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
2086
- }, inputValue && {
2087
- inputValue: props.itemToString(props.items[highlightedIndex])
2088
- }));
2089
- }
2090
-
2091
- /**
2092
- * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2093
- * Used by useSelect and useCombobox.
2094
- *
2095
- * @param {Object} prevState
2096
- * @param {Object} newState
2097
- * @returns {boolean} Wheather the states are deeply equal.
2098
- */
2099
- function isDropdownsStateEqual(prevState, newState) {
2100
- return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2084
+ elementRef: elementRef
2085
+ };
2086
+ }, []);
2087
+ return setGetterPropCallInfo;
2088
+ };
2101
2089
  }
2102
2090
 
2091
+ // istanbul ignore next
2092
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React.useLayoutEffect : React.useEffect;
2093
+
2103
2094
  /**
2104
- * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2105
- *
2106
- * @param {Object} props Props from useCombobox or useSelect.
2107
- * @returns {number} The highlighted index.
2095
+ * Utility hook that scrolls an item from a menu into view.
2096
+ * @param scrollIntoView The function that does the scroll.
2097
+ * @param highlightedIndex The index of the item that should be scrolled.
2098
+ * @param isOpen If the menu is open or not.
2099
+ * @param menuElement The menu element.
2100
+ * @param itemElements The object containing item elements.
2101
+ * @param getItemId The function to get the item id from index.
2102
+ * @returns Function that when called prevents the scroll.
2108
2103
  */
2109
- function getDefaultHighlightedIndex(props) {
2110
- var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
2111
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2112
- return -1;
2113
- }
2114
- return highlightedIndex;
2104
+ function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
2105
+ // used not to scroll on highlight by mouse.
2106
+ var shouldScrollRef = React.useRef(true);
2107
+ // Scroll on highlighted item if change comes from keyboard.
2108
+ useIsomorphicLayoutEffect(function () {
2109
+ if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
2110
+ return;
2111
+ }
2112
+ if (shouldScrollRef.current) {
2113
+ var itemElement = itemElements[getItemId(highlightedIndex)];
2114
+ if (itemElement && menuElement) {
2115
+ scrollIntoView(itemElement, menuElement);
2116
+ }
2117
+ } else {
2118
+ shouldScrollRef.current = true;
2119
+ }
2120
+ }, [highlightedIndex]);
2121
+ return React.useCallback(function preventScroll() {
2122
+ shouldScrollRef.current = false;
2123
+ }, []);
2115
2124
  }
2116
2125
 
2117
2126
  /**
2118
- * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2127
+ * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2128
+ * Used by useSelect and useCombobox.
2119
2129
  *
2120
- * @param {Object} props Props from useCombobox or useSelect.
2121
- * @returns {number} The highlighted index.
2130
+ * @param prevState The previous dropdown state.
2131
+ * @param newState The new dropdown state.
2132
+ * @returns Wheather the states are deeply equal.
2122
2133
  */
2123
- function getInitialHighlightedIndex(props) {
2124
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
2125
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2126
- return -1;
2127
- }
2128
- return highlightedIndex;
2134
+ function isDropdownStateEqual(prevState, newState) {
2135
+ return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2129
2136
  }
2130
2137
 
2131
2138
  function downshiftCommonReducer(state, props, action, stateChangeTypes) {
@@ -2146,13 +2153,13 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2146
2153
  case stateChangeTypes.FunctionToggleMenu:
2147
2154
  changes = {
2148
2155
  isOpen: !state.isOpen,
2149
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
2156
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2150
2157
  };
2151
2158
  break;
2152
2159
  case stateChangeTypes.FunctionOpenMenu:
2153
2160
  changes = {
2154
2161
  isOpen: true,
2155
- highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
2162
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2156
2163
  };
2157
2164
  break;
2158
2165
  case stateChangeTypes.FunctionCloseMenu:
@@ -2161,9 +2168,12 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2161
2168
  };
2162
2169
  break;
2163
2170
  case stateChangeTypes.FunctionSetHighlightedIndex:
2164
- changes = {
2165
- highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
2166
- };
2171
+ {
2172
+ var highlightedIndex = action.highlightedIndex;
2173
+ changes = {
2174
+ highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
2175
+ };
2176
+ }
2167
2177
  break;
2168
2178
  case stateChangeTypes.FunctionSetInputValue:
2169
2179
  changes = {
@@ -2172,10 +2182,10 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2172
2182
  break;
2173
2183
  case stateChangeTypes.FunctionReset:
2174
2184
  changes = {
2175
- highlightedIndex: getDefaultHighlightedIndex(props),
2176
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2177
- selectedItem: getDefaultValue$1(props, 'selectedItem', defaultStateValues$1),
2178
- inputValue: getDefaultValue$1(props, 'inputValue', defaultStateValues$1)
2185
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2186
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2187
+ selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
2188
+ inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
2179
2189
  };
2180
2190
  break;
2181
2191
  default:
@@ -2185,17 +2195,11 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2185
2195
  }
2186
2196
  /* eslint-enable complexity */
2187
2197
 
2188
- var propTypes$3 = _extends({}, propTypes$4, {
2198
+ var propTypes$3 = _extends({}, dropdownPropTypes, {
2189
2199
  items: PropTypes.array.isRequired,
2190
2200
  isItemDisabled: PropTypes.func
2191
2201
  });
2192
2202
 
2193
- var defaultProps$2 = _extends({}, defaultProps$3, {
2194
- isItemDisabled: function isItemDisabled() {
2195
- return false;
2196
- }
2197
- });
2198
-
2199
2203
  function getItemIndexByCharacterKey(_ref) {
2200
2204
  var keysSoFar = _ref.keysSoFar,
2201
2205
  highlightedIndex = _ref.highlightedIndex,
@@ -2264,16 +2268,15 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
2264
2268
  });
2265
2269
 
2266
2270
  /* eslint-disable complexity */
2267
- function downshiftSelectReducer(state, props, action) {
2268
- var _props$items;
2271
+ function downshiftSelectReducer(state, action) {
2269
2272
  var type = action.type,
2270
- altKey = action.altKey;
2273
+ props = action.props;
2271
2274
  var changes;
2272
2275
  switch (type) {
2273
2276
  case ItemClick$1:
2274
2277
  changes = {
2275
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2276
- highlightedIndex: getDefaultHighlightedIndex(props),
2278
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2279
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2277
2280
  selectedItem: props.items[action.index]
2278
2281
  };
2279
2282
  break;
@@ -2300,7 +2303,8 @@ function downshiftSelectReducer(state, props, action) {
2300
2303
  break;
2301
2304
  case ToggleButtonKeyDownArrowDown:
2302
2305
  {
2303
- var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2306
+ var altKey = action.altKey;
2307
+ 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);
2304
2308
  changes = {
2305
2309
  highlightedIndex: _highlightedIndex,
2306
2310
  isOpen: true
@@ -2308,20 +2312,23 @@ function downshiftSelectReducer(state, props, action) {
2308
2312
  }
2309
2313
  break;
2310
2314
  case ToggleButtonKeyDownArrowUp:
2311
- if (state.isOpen && altKey) {
2312
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2313
- } else {
2314
- var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props, state, -1);
2315
- changes = {
2316
- highlightedIndex: _highlightedIndex2,
2317
- isOpen: true
2318
- };
2315
+ {
2316
+ var _altKey = action.altKey;
2317
+ if (state.isOpen && _altKey) {
2318
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2319
+ } else {
2320
+ 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);
2321
+ changes = {
2322
+ highlightedIndex: _highlightedIndex2,
2323
+ isOpen: true
2324
+ };
2325
+ }
2319
2326
  }
2320
2327
  break;
2321
2328
  // only triggered when menu is open.
2322
2329
  case ToggleButtonKeyDownEnter:
2323
2330
  case ToggleButtonKeyDownSpaceButton:
2324
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2331
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2325
2332
  break;
2326
2333
  case ToggleButtonKeyDownHome:
2327
2334
  changes = {
@@ -2355,7 +2362,7 @@ function downshiftSelectReducer(state, props, action) {
2355
2362
  changes = _extends({
2356
2363
  isOpen: false,
2357
2364
  highlightedIndex: -1
2358
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
2365
+ }, state.highlightedIndex >= 0 && props.items.length && {
2359
2366
  selectedItem: props.items[state.highlightedIndex]
2360
2367
  });
2361
2368
  break;
@@ -2371,59 +2378,9 @@ function downshiftSelectReducer(state, props, action) {
2371
2378
  }
2372
2379
  /* eslint-enable complexity */
2373
2380
 
2374
- // eslint-disable-next-line @typescript-eslint/dot-notation
2375
- var reactUseId$1 = React['useId'];
2376
- var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
2377
- function useElementIdsR18$1(_ref) {
2378
- var id = _ref.id,
2379
- labelId = _ref.labelId,
2380
- menuId = _ref.menuId,
2381
- getItemId = _ref.getItemId,
2382
- toggleButtonId = _ref.toggleButtonId,
2383
- inputId = _ref.inputId;
2384
- var reactId = "downshift-" + reactUseId$1();
2385
- if (!id) {
2386
- id = reactId;
2387
- }
2388
- var elementIds = React.useMemo(function () {
2389
- return {
2390
- labelId: labelId != null ? labelId : id + "-label",
2391
- menuId: menuId != null ? menuId : id + "-menu",
2392
- getItemId: getItemId != null ? getItemId : function (index) {
2393
- return id + "-item-" + index;
2394
- },
2395
- toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
2396
- inputId: inputId != null ? inputId : id + "-input"
2397
- };
2398
- }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2399
- return elementIds;
2400
- }
2401
- function useElementIdsLegacy$1(_ref2) {
2402
- var id = _ref2.id,
2403
- labelId = _ref2.labelId,
2404
- menuId = _ref2.menuId,
2405
- getItemId = _ref2.getItemId,
2406
- toggleButtonId = _ref2.toggleButtonId,
2407
- inputId = _ref2.inputId;
2408
- var baseIdRef = React.useRef(id != null ? id : "downshift-" + generateId());
2409
- var baseId = baseIdRef.current;
2410
- var elementIds = React.useMemo(function () {
2411
- return {
2412
- labelId: labelId != null ? labelId : baseId + "-label",
2413
- menuId: menuId != null ? menuId : baseId + "-menu",
2414
- getItemId: getItemId != null ? getItemId : function (index) {
2415
- return baseId + "-item-" + index;
2416
- },
2417
- toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
2418
- inputId: inputId != null ? inputId : baseId + "-input"
2419
- };
2420
- }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
2421
- return elementIds;
2422
- }
2423
-
2424
2381
  var _excluded$3 = ["onClick"],
2425
- _excluded2$3 = ["onMouseLeave", "refKey", "ref"],
2426
- _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
2382
+ _excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
2383
+ _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
2427
2384
  _excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
2428
2385
  useSelect.stateChangeTypes = stateChangeTypes$3;
2429
2386
  function useSelect(userProps) {
@@ -2432,22 +2389,23 @@ function useSelect(userProps) {
2432
2389
  }
2433
2390
  validatePropTypes$1(userProps, useSelect, propTypes$3);
2434
2391
  // Props defaults and destructuring.
2435
- var props = _extends({}, defaultProps$2, userProps);
2392
+ var props = _extends({}, dropdownDefaultProps, userProps);
2436
2393
  var scrollIntoView = props.scrollIntoView,
2437
2394
  environment = props.environment,
2438
2395
  getA11yStatusMessage = props.getA11yStatusMessage;
2439
2396
  // Initial state depending on controlled props.
2440
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownsStateEqual),
2397
+ var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
2441
2398
  state = _useControlledReducer[0],
2442
2399
  dispatch = _useControlledReducer[1];
2443
2400
  var isOpen = state.isOpen,
2444
2401
  highlightedIndex = state.highlightedIndex,
2445
2402
  selectedItem = state.selectedItem,
2446
2403
  inputValue = state.inputValue;
2447
- // Element efs.
2404
+
2405
+ // Element refs.
2448
2406
  var toggleButtonRef = useRef(null);
2449
2407
  var menuRef = useRef(null);
2450
- var itemRefs = useRef({});
2408
+ var itemsRef = useRef({});
2451
2409
 
2452
2410
  // used to keep the inputValue clearTimeout object between renders.
2453
2411
  var clearTimeoutRef = useRef(null);
@@ -2459,24 +2417,12 @@ function useSelect(userProps) {
2459
2417
  props: props
2460
2418
  });
2461
2419
 
2462
- // Some utils.
2463
- var getItemNodeFromIndex = useCallback(function (index) {
2464
- return itemRefs.current[elementIds.getItemId(index)];
2465
- }, [elementIds]);
2466
-
2467
2420
  // Effects.
2468
2421
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
2469
2422
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
2470
2423
  // Scroll on highlighted item if change comes from keyboard.
2471
- var shouldScrollRef = useScrollIntoView({
2472
- menuElement: menuRef.current,
2473
- highlightedIndex: highlightedIndex,
2474
- isOpen: isOpen,
2475
- itemRefs: itemRefs,
2476
- scrollIntoView: scrollIntoView,
2477
- getItemNodeFromIndex: getItemNodeFromIndex
2478
- });
2479
- // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2424
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
2425
+ // Sets cleanup for the keysSoFar callback, debounced after 500ms.
2480
2426
  useEffect(function () {
2481
2427
  // init the clean function here as we need access to dispatch.
2482
2428
  clearTimeoutRef.current = debounce(function (outerDispatch) {
@@ -2488,7 +2434,8 @@ function useSelect(userProps) {
2488
2434
 
2489
2435
  // Cancel any pending debounced calls on mount
2490
2436
  return function () {
2491
- clearTimeoutRef.current.cancel();
2437
+ var _clearTimeoutRef$curr;
2438
+ (_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
2492
2439
  };
2493
2440
  }, []);
2494
2441
  // Invokes the keysSoFar callback set up above.
@@ -2496,7 +2443,7 @@ function useSelect(userProps) {
2496
2443
  if (!inputValue) {
2497
2444
  return;
2498
2445
  }
2499
- clearTimeoutRef.current(dispatch);
2446
+ clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
2500
2447
  }, [dispatch, inputValue]);
2501
2448
  useControlPropsValidator({
2502
2449
  props: props,
@@ -2504,7 +2451,7 @@ function useSelect(userProps) {
2504
2451
  });
2505
2452
  // Focus the toggle button on first render if required.
2506
2453
  useEffect(function () {
2507
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
2454
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
2508
2455
  if (focusOnOpen && toggleButtonRef.current) {
2509
2456
  toggleButtonRef.current.focus();
2510
2457
  }
@@ -2525,7 +2472,7 @@ function useSelect(userProps) {
2525
2472
  // Reset itemRefs on close.
2526
2473
  useEffect(function () {
2527
2474
  if (!isOpen) {
2528
- itemRefs.current = {};
2475
+ itemsRef.current = {};
2529
2476
  }
2530
2477
  }, [isOpen]);
2531
2478
 
@@ -2610,50 +2557,11 @@ function useSelect(userProps) {
2610
2557
  };
2611
2558
  }, [dispatch, latest]);
2612
2559
 
2613
- // Action functions.
2614
- var toggleMenu = useCallback(function () {
2615
- dispatch({
2616
- type: FunctionToggleMenu$1
2617
- });
2618
- }, [dispatch]);
2619
- var closeMenu = useCallback(function () {
2620
- dispatch({
2621
- type: FunctionCloseMenu$1
2622
- });
2623
- }, [dispatch]);
2624
- var openMenu = useCallback(function () {
2625
- dispatch({
2626
- type: FunctionOpenMenu$1
2627
- });
2628
- }, [dispatch]);
2629
- var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
2630
- dispatch({
2631
- type: FunctionSetHighlightedIndex$1,
2632
- highlightedIndex: newHighlightedIndex
2633
- });
2634
- }, [dispatch]);
2635
- var selectItem = useCallback(function (newSelectedItem) {
2636
- dispatch({
2637
- type: FunctionSelectItem$1,
2638
- selectedItem: newSelectedItem
2639
- });
2640
- }, [dispatch]);
2641
- var reset = useCallback(function () {
2642
- dispatch({
2643
- type: FunctionReset$2
2644
- });
2645
- }, [dispatch]);
2646
- var setInputValue = useCallback(function (newInputValue) {
2647
- dispatch({
2648
- type: FunctionSetInputValue$1,
2649
- inputValue: newInputValue
2650
- });
2651
- }, [dispatch]);
2652
2560
  // Getter functions.
2653
- var getLabelProps = useCallback(function (_temp) {
2654
- var _ref = _temp === void 0 ? {} : _temp,
2561
+ var getLabelProps = useCallback(function (labelProps) {
2562
+ var _ref = labelProps != null ? labelProps : {},
2655
2563
  onClick = _ref.onClick,
2656
- labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2564
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2657
2565
  var labelHandleClick = function labelHandleClick() {
2658
2566
  var _toggleButtonRef$curr;
2659
2567
  (_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
@@ -2662,17 +2570,18 @@ function useSelect(userProps) {
2662
2570
  id: elementIds.labelId,
2663
2571
  htmlFor: elementIds.toggleButtonId,
2664
2572
  onClick: callAllEventHandlers(onClick, labelHandleClick)
2665
- }, labelProps);
2573
+ }, rest);
2666
2574
  }, [elementIds]);
2667
- var getMenuProps = useCallback(function (_temp2, _temp3) {
2575
+ var getMenuProps = useCallback(function (menuProps, otherProps) {
2668
2576
  var _extends2;
2669
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2577
+ var _ref2 = menuProps != null ? menuProps : {},
2670
2578
  onMouseLeave = _ref2.onMouseLeave,
2671
2579
  _ref2$refKey = _ref2.refKey,
2672
2580
  refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
2673
2581
  ref = _ref2.ref,
2582
+ ariaLabel = _ref2['aria-label'],
2674
2583
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
2675
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2584
+ var _ref3 = otherProps != null ? otherProps : {},
2676
2585
  _ref3$suppressRefErro = _ref3.suppressRefError,
2677
2586
  suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
2678
2587
  var menuHandleMouseLeave = function menuHandleMouseLeave() {
@@ -2683,11 +2592,11 @@ function useSelect(userProps) {
2683
2592
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2684
2593
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2685
2594
  menuRef.current = menuNode;
2686
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
2595
+ }), _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);
2687
2596
  }, [dispatch, setGetterPropCallInfo, elementIds]);
2688
- var getToggleButtonProps = useCallback(function (_temp4, _temp5) {
2597
+ var getToggleButtonProps = useCallback(function (toggleButtonProps, otherProps) {
2689
2598
  var _extends3;
2690
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2599
+ var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
2691
2600
  onBlur = _ref4.onBlur,
2692
2601
  onClick = _ref4.onClick;
2693
2602
  _ref4.onPress;
@@ -2695,8 +2604,9 @@ function useSelect(userProps) {
2695
2604
  _ref4$refKey = _ref4.refKey,
2696
2605
  refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
2697
2606
  ref = _ref4.ref,
2607
+ disabled = _ref4.disabled,
2698
2608
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
2699
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2609
+ var _ref5 = otherProps != null ? otherProps : {},
2700
2610
  _ref5$suppressRefErro = _ref5.suppressRefError,
2701
2611
  suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
2702
2612
  var latestState = latest.current.state;
@@ -2714,9 +2624,9 @@ function useSelect(userProps) {
2714
2624
  };
2715
2625
  var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2716
2626
  var key = normalizeArrowKey(event);
2717
- if (key && toggleButtonKeyDownHandlers[key]) {
2627
+ if (key && key in toggleButtonKeyDownHandlers) {
2718
2628
  toggleButtonKeyDownHandlers[key](event);
2719
- } else if (isAcceptedCharacterKey(key)) {
2629
+ } else if (/^\S{1}$/.test(key)) {
2720
2630
  dispatch({
2721
2631
  type: ToggleButtonKeyDownCharacter,
2722
2632
  key: key
@@ -2725,20 +2635,22 @@ function useSelect(userProps) {
2725
2635
  };
2726
2636
  var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2727
2637
  toggleButtonRef.current = toggleButtonNode;
2728
- }), _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);
2729
- if (!rest.disabled) {
2638
+ }), _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);
2639
+ if (!disabled) {
2730
2640
  /* istanbul ignore if (react-native) */
2731
2641
  {
2732
- toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
2733
- toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
2642
+ Object.assign(toggleProps, {
2643
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick),
2644
+ onKeyDown: callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown)
2645
+ });
2734
2646
  }
2735
2647
  }
2736
2648
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2737
2649
  return toggleProps;
2738
2650
  }, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
2739
- var getItemProps = useCallback(function (_temp6) {
2651
+ var getItemProps = useCallback(function (itemProps) {
2740
2652
  var _extends4;
2741
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
2653
+ var _ref6 = itemProps != null ? itemProps : {},
2742
2654
  itemProp = _ref6.item,
2743
2655
  indexProp = _ref6.index,
2744
2656
  onMouseMove = _ref6.onMouseMove,
@@ -2764,7 +2676,7 @@ function useSelect(userProps) {
2764
2676
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
2765
2677
  return;
2766
2678
  }
2767
- shouldScrollRef.current = false;
2679
+ preventScroll();
2768
2680
  dispatch({
2769
2681
  type: ItemMouseMove$1,
2770
2682
  index: index,
@@ -2781,21 +2693,61 @@ function useSelect(userProps) {
2781
2693
  return e.preventDefault();
2782
2694
  }; // keep focus on the toggle after item click select.
2783
2695
 
2784
- var itemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2696
+ var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2785
2697
  if (itemNode) {
2786
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
2698
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
2787
2699
  }
2788
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2700
+ }), _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);
2789
2701
  if (!disabled) {
2790
2702
  /* istanbul ignore next (react-native) */
2791
2703
  {
2792
- itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2704
+ Object.assign(resultItemProps, {
2705
+ onClick: callAllEventHandlers(onClick, itemHandleClick)
2706
+ });
2793
2707
  }
2794
2708
  }
2795
- itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
2796
- itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
2797
- return itemProps;
2798
- }, [latest, elementIds, mouseAndTouchTrackers, shouldScrollRef, dispatch]);
2709
+ return resultItemProps;
2710
+ }, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
2711
+
2712
+ // Action functions.
2713
+ var toggleMenu = useCallback(function () {
2714
+ dispatch({
2715
+ type: FunctionToggleMenu$1
2716
+ });
2717
+ }, [dispatch]);
2718
+ var closeMenu = useCallback(function () {
2719
+ dispatch({
2720
+ type: FunctionCloseMenu$1
2721
+ });
2722
+ }, [dispatch]);
2723
+ var openMenu = useCallback(function () {
2724
+ dispatch({
2725
+ type: FunctionOpenMenu$1
2726
+ });
2727
+ }, [dispatch]);
2728
+ var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
2729
+ dispatch({
2730
+ type: FunctionSetHighlightedIndex$1,
2731
+ highlightedIndex: newHighlightedIndex
2732
+ });
2733
+ }, [dispatch]);
2734
+ var selectItem = useCallback(function (newSelectedItem) {
2735
+ dispatch({
2736
+ type: FunctionSelectItem$1,
2737
+ selectedItem: newSelectedItem
2738
+ });
2739
+ }, [dispatch]);
2740
+ var reset = useCallback(function () {
2741
+ dispatch({
2742
+ type: FunctionReset$2
2743
+ });
2744
+ }, [dispatch]);
2745
+ var setInputValue = useCallback(function (newInputValue) {
2746
+ dispatch({
2747
+ type: FunctionSetInputValue$1,
2748
+ inputValue: newInputValue
2749
+ });
2750
+ }, [dispatch]);
2799
2751
  return {
2800
2752
  // prop getters.
2801
2753
  getToggleButtonProps: getToggleButtonProps,
@@ -2818,6 +2770,18 @@ function useSelect(userProps) {
2818
2770
  };
2819
2771
  }
2820
2772
 
2773
+ function getInitialState$2(props) {
2774
+ var initialState = getInitialState$3(props);
2775
+ var selectedItem = initialState.selectedItem;
2776
+ var inputValue = initialState.inputValue;
2777
+ if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2778
+ inputValue = props.itemToString(selectedItem);
2779
+ }
2780
+ return _extends({}, initialState, {
2781
+ inputValue: inputValue
2782
+ });
2783
+ }
2784
+
2821
2785
  var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2822
2786
  var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2823
2787
  var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
@@ -2869,27 +2833,6 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2869
2833
  ToggleButtonClick: ToggleButtonClick
2870
2834
  });
2871
2835
 
2872
- function getInitialState$2(props) {
2873
- var initialState = getInitialState$3(props);
2874
- var selectedItem = initialState.selectedItem;
2875
- var inputValue = initialState.inputValue;
2876
- if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2877
- inputValue = props.itemToString(selectedItem);
2878
- }
2879
- return _extends({}, initialState, {
2880
- inputValue: inputValue
2881
- });
2882
- }
2883
- var propTypes$2 = _extends({}, propTypes$4, {
2884
- items: PropTypes.array.isRequired,
2885
- isItemDisabled: PropTypes.func,
2886
- inputValue: PropTypes.string,
2887
- defaultInputValue: PropTypes.string,
2888
- initialInputValue: PropTypes.string,
2889
- inputId: PropTypes.string,
2890
- onInputValueChange: PropTypes.func
2891
- });
2892
-
2893
2836
  /**
2894
2837
  * The useCombobox version of useControlledReducer, which also
2895
2838
  * checks if the controlled prop selectedItem changed between
@@ -2897,20 +2840,20 @@ var propTypes$2 = _extends({}, propTypes$4, {
2897
2840
  * string equivalent. It uses the common useEnhancedReducer to
2898
2841
  * compute the rest of the state.
2899
2842
  *
2900
- * @param {Function} reducer Reducer function from downshift.
2901
- * @param {Object} props The hook props, also passed to createInitialState.
2902
- * @param {Function} createInitialState Function that returns the initial state.
2903
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
2904
- * @returns {Array} An array with the state and an action dispatcher.
2843
+ * @param reducer Reducer function from downshift.
2844
+ * @param props The hook props, also passed to createInitialState.
2845
+ * @param createInitialState Function that returns the initial state.
2846
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
2847
+ * @returns An array with the state and an action dispatcher.
2905
2848
  */
2906
2849
  function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
2907
- var previousSelectedItemRef = useRef();
2850
+ var previousSelectedItemRef = useRef(null);
2908
2851
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
2909
2852
  state = _useEnhancedReducer[0],
2910
2853
  dispatch = _useEnhancedReducer[1];
2911
2854
  var isInitialMount = useIsInitialMount();
2912
2855
  useEffect(function () {
2913
- if (!isControlledProp(props, 'selectedItem')) {
2856
+ if (props.selectedItem === undefined) {
2914
2857
  return;
2915
2858
  }
2916
2859
  if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
@@ -2928,23 +2871,27 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
2928
2871
  }, [state.selectedItem, props.selectedItem]);
2929
2872
  return [getState(state, props), dispatch];
2930
2873
  }
2931
- var defaultProps$1 = _extends({}, defaultProps$3, {
2932
- isItemDisabled: function isItemDisabled() {
2933
- return false;
2934
- }
2874
+
2875
+ var propTypes$2 = _extends({}, dropdownPropTypes, {
2876
+ items: PropTypes.array.isRequired,
2877
+ isItemDisabled: PropTypes.func,
2878
+ inputValue: PropTypes.string,
2879
+ defaultInputValue: PropTypes.string,
2880
+ initialInputValue: PropTypes.string,
2881
+ inputId: PropTypes.string,
2882
+ onInputValueChange: PropTypes.func
2935
2883
  });
2936
2884
 
2937
2885
  /* eslint-disable complexity */
2938
- function downshiftUseComboboxReducer(state, props, action) {
2939
- var _props$items;
2886
+ function downshiftUseComboboxReducer(state, action) {
2940
2887
  var type = action.type,
2941
- altKey = action.altKey;
2888
+ props = action.props;
2942
2889
  var changes;
2943
2890
  switch (type) {
2944
2891
  case ItemClick:
2945
2892
  changes = {
2946
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2947
- highlightedIndex: getDefaultHighlightedIndex(props),
2893
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2894
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2948
2895
  selectedItem: props.items[action.index],
2949
2896
  inputValue: props.itemToString(props.items[action.index])
2950
2897
  };
@@ -2956,15 +2903,15 @@ function downshiftUseComboboxReducer(state, props, action) {
2956
2903
  };
2957
2904
  } else {
2958
2905
  changes = {
2959
- highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
2906
+ highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
2960
2907
  isOpen: props.items.length >= 0
2961
2908
  };
2962
2909
  }
2963
2910
  break;
2964
2911
  case InputKeyDownArrowUp:
2965
2912
  if (state.isOpen) {
2966
- if (altKey) {
2967
- changes = getChangesOnSelection(props, state.highlightedIndex);
2913
+ if (action.altKey) {
2914
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
2968
2915
  } else {
2969
2916
  changes = {
2970
2917
  highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
@@ -2972,13 +2919,13 @@ function downshiftUseComboboxReducer(state, props, action) {
2972
2919
  }
2973
2920
  } else {
2974
2921
  changes = {
2975
- highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
2922
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
2976
2923
  isOpen: props.items.length >= 0
2977
2924
  };
2978
2925
  }
2979
2926
  break;
2980
2927
  case InputKeyDownEnter:
2981
- changes = getChangesOnSelection(props, state.highlightedIndex);
2928
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
2982
2929
  break;
2983
2930
  case InputKeyDownEscape:
2984
2931
  changes = _extends({
@@ -3013,7 +2960,7 @@ function downshiftUseComboboxReducer(state, props, action) {
3013
2960
  changes = _extends({
3014
2961
  isOpen: false,
3015
2962
  highlightedIndex: -1
3016
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
2963
+ }, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
3017
2964
  selectedItem: props.items[state.highlightedIndex],
3018
2965
  inputValue: props.itemToString(props.items[state.highlightedIndex])
3019
2966
  });
@@ -3021,14 +2968,14 @@ function downshiftUseComboboxReducer(state, props, action) {
3021
2968
  case InputChange:
3022
2969
  changes = {
3023
2970
  isOpen: true,
3024
- highlightedIndex: getDefaultHighlightedIndex(props),
2971
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3025
2972
  inputValue: action.inputValue
3026
2973
  };
3027
2974
  break;
3028
2975
  case InputClick:
3029
2976
  changes = {
3030
2977
  isOpen: !state.isOpen,
3031
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
2978
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
3032
2979
  };
3033
2980
  break;
3034
2981
  case FunctionSelectItem:
@@ -3049,10 +2996,10 @@ function downshiftUseComboboxReducer(state, props, action) {
3049
2996
  }
3050
2997
  /* eslint-enable complexity */
3051
2998
 
3052
- var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
2999
+ var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
3053
3000
  _excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
3054
- _excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
3055
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3001
+ _excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
3002
+ _excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3056
3003
  useCombobox.stateChangeTypes = stateChangeTypes$2;
3057
3004
  function useCombobox(userProps) {
3058
3005
  if (userProps === void 0) {
@@ -3060,13 +3007,13 @@ function useCombobox(userProps) {
3060
3007
  }
3061
3008
  validatePropTypes$1(userProps, useCombobox, propTypes$2);
3062
3009
  // Props defaults and destructuring.
3063
- var props = _extends({}, defaultProps$1, userProps);
3010
+ var props = _extends({}, dropdownDefaultProps, userProps);
3064
3011
  var items = props.items,
3065
3012
  scrollIntoView = props.scrollIntoView,
3066
3013
  environment = props.environment,
3067
3014
  getA11yStatusMessage = props.getA11yStatusMessage;
3068
3015
  // Initial state depending on controlled props.
3069
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownsStateEqual),
3016
+ var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
3070
3017
  state = _useControlledReducer[0],
3071
3018
  dispatch = _useControlledReducer[1];
3072
3019
  var isOpen = state.isOpen,
@@ -3076,7 +3023,7 @@ function useCombobox(userProps) {
3076
3023
 
3077
3024
  // Element refs.
3078
3025
  var menuRef = useRef(null);
3079
- var itemRefs = useRef({});
3026
+ var itemsRef = useRef({});
3080
3027
  var inputRef = useRef(null);
3081
3028
  var toggleButtonRef = useRef(null);
3082
3029
  var isInitialMount = useIsInitialMount();
@@ -3090,29 +3037,19 @@ function useCombobox(userProps) {
3090
3037
  state: state,
3091
3038
  props: props
3092
3039
  });
3093
- var getItemNodeFromIndex = useCallback(function (index) {
3094
- return itemRefs.current[elementIds.getItemId(index)];
3095
- }, [elementIds]);
3096
3040
 
3097
3041
  // Effects.
3098
3042
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
3099
3043
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
3100
3044
  // Scroll on highlighted item if change comes from keyboard.
3101
- var shouldScrollRef = useScrollIntoView({
3102
- menuElement: menuRef.current,
3103
- highlightedIndex: highlightedIndex,
3104
- isOpen: isOpen,
3105
- itemRefs: itemRefs,
3106
- scrollIntoView: scrollIntoView,
3107
- getItemNodeFromIndex: getItemNodeFromIndex
3108
- });
3045
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
3109
3046
  useControlPropsValidator({
3110
- props: props,
3111
- state: state
3047
+ state: state,
3048
+ props: props
3112
3049
  });
3113
3050
  // Focus the input on first render if required.
3114
3051
  useEffect(function () {
3115
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
3052
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
3116
3053
  if (focusOnOpen && inputRef.current) {
3117
3054
  inputRef.current.focus();
3118
3055
  }
@@ -3138,13 +3075,13 @@ function useCombobox(userProps) {
3138
3075
  // Reset itemRefs on close.
3139
3076
  useEffect(function () {
3140
3077
  if (!isOpen) {
3141
- itemRefs.current = {};
3078
+ itemsRef.current = {};
3142
3079
  }
3143
3080
  }, [isOpen]);
3144
3081
  // Reset itemRefs on close.
3145
3082
  useEffect(function () {
3146
3083
  var _inputRef$current;
3147
- if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3084
+ if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3148
3085
  return;
3149
3086
  }
3150
3087
  if (environment.document.activeElement !== inputRef.current) {
@@ -3234,29 +3171,30 @@ function useCombobox(userProps) {
3234
3171
  htmlFor: elementIds.inputId
3235
3172
  }, labelProps);
3236
3173
  }, [elementIds]);
3237
- var getMenuProps = useCallback(function (_temp, _temp2) {
3174
+ var getMenuProps = useCallback(function (menuProps, otherProps) {
3238
3175
  var _extends2;
3239
- var _ref = _temp === void 0 ? {} : _temp,
3176
+ var _ref = menuProps != null ? menuProps : {},
3240
3177
  onMouseLeave = _ref.onMouseLeave,
3241
3178
  _ref$refKey = _ref.refKey,
3242
3179
  refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3243
3180
  ref = _ref.ref,
3181
+ ariaLabel = _ref['aria-label'],
3244
3182
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3245
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3183
+ var _ref2 = otherProps != null ? otherProps : {},
3246
3184
  _ref2$suppressRefErro = _ref2.suppressRefError,
3247
3185
  suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3248
3186
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3249
3187
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3250
3188
  menuRef.current = menuNode;
3251
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3189
+ }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3252
3190
  dispatch({
3253
3191
  type: MenuMouseLeave
3254
3192
  });
3255
3193
  }), _extends2), rest);
3256
3194
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3257
- var getItemProps = useCallback(function (_temp3) {
3195
+ var getItemProps = useCallback(function (itemProps) {
3258
3196
  var _extends3, _ref4;
3259
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3197
+ var _ref3 = itemProps != null ? itemProps : {},
3260
3198
  itemProp = _ref3.item,
3261
3199
  indexProp = _ref3.index,
3262
3200
  _ref3$refKey = _ref3.refKey,
@@ -3284,7 +3222,7 @@ function useCombobox(userProps) {
3284
3222
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
3285
3223
  return;
3286
3224
  }
3287
- shouldScrollRef.current = false;
3225
+ preventScroll();
3288
3226
  dispatch({
3289
3227
  type: ItemMouseMove,
3290
3228
  index: index,
@@ -3303,21 +3241,22 @@ function useCombobox(userProps) {
3303
3241
 
3304
3242
  return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3305
3243
  if (itemNode) {
3306
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
3244
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
3307
3245
  }
3308
3246
  }), _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), {
3309
3247
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3310
3248
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3311
3249
  }, rest);
3312
- }, [dispatch, elementIds, latest, mouseAndTouchTrackers, shouldScrollRef]);
3313
- var getToggleButtonProps = useCallback(function (_temp4) {
3250
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
3251
+ var getToggleButtonProps = useCallback(function (toggleButtonProps) {
3314
3252
  var _extends4;
3315
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3253
+ var _ref5 = toggleButtonProps != null ? toggleButtonProps : {},
3316
3254
  onClick = _ref5.onClick;
3317
3255
  _ref5.onPress;
3318
3256
  var _ref5$refKey = _ref5.refKey,
3319
3257
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3320
3258
  ref = _ref5.ref,
3259
+ disabled = _ref5.disabled,
3321
3260
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
3322
3261
  var latestState = latest.current.state;
3323
3262
  var toggleButtonHandleClick = function toggleButtonHandleClick() {
@@ -3327,13 +3266,17 @@ function useCombobox(userProps) {
3327
3266
  };
3328
3267
  return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3329
3268
  toggleButtonRef.current = toggleButtonNode;
3330
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
3269
+ }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, {
3331
3270
  onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3332
- }), rest);
3271
+ }), {
3272
+ disabled: disabled
3273
+ }, rest);
3333
3274
  }, [dispatch, latest, elementIds]);
3334
- var getInputProps = useCallback(function (_temp5, _temp6) {
3275
+ var getInputProps = useCallback(function (inputProps, otherProps) {
3335
3276
  var _extends5;
3336
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3277
+ var _ref6 = inputProps != null ? inputProps : {},
3278
+ ariaLabel = _ref6['aria-label'],
3279
+ disabled = _ref6.disabled,
3337
3280
  onKeyDown = _ref6.onKeyDown,
3338
3281
  onChange = _ref6.onChange,
3339
3282
  onInput = _ref6.onInput,
@@ -3344,15 +3287,16 @@ function useCombobox(userProps) {
3344
3287
  refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3345
3288
  ref = _ref6.ref,
3346
3289
  rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
3347
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3290
+ var _ref7 = otherProps != null ? otherProps : {},
3348
3291
  _ref7$suppressRefErro = _ref7.suppressRefError,
3349
3292
  suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3350
3293
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3351
3294
  var latestState = latest.current.state;
3352
3295
  var inputHandleKeyDown = function inputHandleKeyDown(event) {
3353
3296
  var key = normalizeArrowKey(event);
3354
- if (key && inputKeyDownHandlers[key]) {
3355
- inputKeyDownHandlers[key](event);
3297
+ if (key && key in inputKeyDownHandlers) {
3298
+ var validKey = key;
3299
+ inputKeyDownHandlers[validKey](event);
3356
3300
  }
3357
3301
  };
3358
3302
  var inputHandleChange = function inputHandleChange(event) {
@@ -3380,13 +3324,13 @@ function useCombobox(userProps) {
3380
3324
  /* istanbul ignore next (preact) */
3381
3325
  var onChangeKey = 'onInput' ;
3382
3326
  var eventHandlers = {};
3383
- if (!rest.disabled) {
3327
+ if (!disabled) {
3384
3328
  var _eventHandlers;
3385
3329
  eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
3386
3330
  }
3387
3331
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3388
3332
  inputRef.current = inputNode;
3389
- }), _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);
3333
+ }), _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);
3390
3334
  }, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
3391
3335
 
3392
3336
  // returns
@@ -3456,31 +3400,6 @@ var defaultStateValues = {
3456
3400
  selectedItems: []
3457
3401
  };
3458
3402
 
3459
- /**
3460
- * Returns the initial value for a state key in the following order:
3461
- * 1. controlled prop, 2. initial prop, 3. default prop, 4. default
3462
- * value from Downshift.
3463
- *
3464
- * @param {Object} props Props passed to the hook.
3465
- * @param {string} propKey Props key to generate the value for.
3466
- * @returns {any} The initial value for that prop.
3467
- */
3468
- function getInitialValue(props, propKey) {
3469
- return getInitialValue$1(props, propKey, defaultStateValues);
3470
- }
3471
-
3472
- /**
3473
- * Returns the default value for a state key in the following order:
3474
- * 1. controlled prop, 2. default prop, 3. default value from Downshift.
3475
- *
3476
- * @param {Object} props Props passed to the hook.
3477
- * @param {string} propKey Props key to generate the value for.
3478
- * @returns {any} The initial value for that prop.
3479
- */
3480
- function getDefaultValue(props, propKey) {
3481
- return getDefaultValue$1(props, propKey, defaultStateValues);
3482
- }
3483
-
3484
3403
  /**
3485
3404
  * Gets the initial state based on the provided props. It uses initial, default
3486
3405
  * and controlled props related to state in order to compute the initial value.
@@ -3489,8 +3408,8 @@ function getDefaultValue(props, propKey) {
3489
3408
  * @returns {Object} The initial state.
3490
3409
  */
3491
3410
  function getInitialState$1(props) {
3492
- var activeIndex = getInitialValue(props, 'activeIndex');
3493
- var selectedItems = getInitialValue(props, 'selectedItems');
3411
+ var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
3412
+ var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
3494
3413
  return {
3495
3414
  activeIndex: activeIndex,
3496
3415
  selectedItems: selectedItems
@@ -3534,9 +3453,9 @@ function isStateEqual$1(prevState, newState) {
3534
3453
  return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
3535
3454
  }
3536
3455
  var propTypes$1 = {
3537
- stateReducer: propTypes$4.stateReducer,
3538
- itemToKey: propTypes$4.itemToKey,
3539
- environment: propTypes$4.environment,
3456
+ stateReducer: dropdownPropTypes.stateReducer,
3457
+ itemToKey: dropdownPropTypes.itemToKey,
3458
+ environment: dropdownPropTypes.environment,
3540
3459
  selectedItems: PropTypes.array,
3541
3460
  initialSelectedItems: PropTypes.array,
3542
3461
  defaultSelectedItems: PropTypes.array,
@@ -3550,9 +3469,9 @@ var propTypes$1 = {
3550
3469
  keyNavigationPrevious: PropTypes.string
3551
3470
  };
3552
3471
  var defaultProps = {
3553
- itemToKey: defaultProps$3.itemToKey,
3554
- stateReducer: defaultProps$3.stateReducer,
3555
- environment: defaultProps$3.environment,
3472
+ itemToKey: dropdownDefaultProps.itemToKey,
3473
+ stateReducer: dropdownDefaultProps.stateReducer,
3474
+ environment: dropdownDefaultProps.environment,
3556
3475
  keyNavigationNext: 'ArrowRight',
3557
3476
  keyNavigationPrevious: 'ArrowLeft'
3558
3477
  };
@@ -3598,10 +3517,11 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
3598
3517
  });
3599
3518
 
3600
3519
  /* eslint-disable complexity */
3601
- function downshiftMultipleSelectionReducer(state, props, action) {
3520
+ function downshiftMultipleSelectionReducer(state, action) {
3602
3521
  var type = action.type,
3603
3522
  index = action.index,
3604
- selectedItem = action.selectedItem;
3523
+ selectedItem = action.selectedItem,
3524
+ props = action.props;
3605
3525
  var activeIndex = state.activeIndex,
3606
3526
  selectedItems = state.selectedItems;
3607
3527
  var changes;
@@ -3698,8 +3618,8 @@ function downshiftMultipleSelectionReducer(state, props, action) {
3698
3618
  }
3699
3619
  case FunctionReset:
3700
3620
  changes = {
3701
- activeIndex: getDefaultValue(props, 'activeIndex'),
3702
- selectedItems: getDefaultValue(props, 'selectedItems')
3621
+ activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
3622
+ selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
3703
3623
  };
3704
3624
  break;
3705
3625
  default:
@@ -3931,7 +3851,7 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3931
3851
  TagRemoveClick: TagRemoveClick
3932
3852
  });
3933
3853
 
3934
- function useTagGroupReducer(state, _props, action) {
3854
+ function useTagGroupReducer(state, action) {
3935
3855
  var type = action.type;
3936
3856
  var changes;
3937
3857
  switch (type) {
@@ -3992,8 +3912,9 @@ function useTagGroupReducer(state, _props, action) {
3992
3912
  return _extends({}, state, changes);
3993
3913
  }
3994
3914
 
3995
- // eslint-disable-next-line @typescript-eslint/dot-notation
3996
- var reactUseId = React['useId'];
3915
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
3916
+ var SafeReact = _extends({}, React);
3917
+ var reactUseId = SafeReact.useId;
3997
3918
 
3998
3919
  // istanbul ignore next
3999
3920
  var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
@@ -4168,7 +4089,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4168
4089
  'aria-atomic': 'false',
4169
4090
  'aria-relevant': 'additions',
4170
4091
  role: 'listbox',
4171
- onKeyDown: callAllEventHandlers$1(onKeyDown, handleKeyDown)
4092
+ onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
4172
4093
  }, rest);
4173
4094
  return tagGroupProps;
4174
4095
  }, [dispatch, elementIds.tagGroupId]);
@@ -4193,11 +4114,11 @@ var _useTagGroup = function useTagGroup(userProps) {
4193
4114
  var tagId = elementIds.getTagId(index);
4194
4115
  return _extends((_extends2 = {
4195
4116
  'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
4196
- }, _extends2[refKey] = handleRefs$1(ref, function (itemNode) {
4117
+ }, _extends2[refKey] = handleRefs(ref, function (itemNode) {
4197
4118
  if (itemNode) {
4198
4119
  itemRefs.current[tagId] = itemNode;
4199
4120
  }
4200
- }), _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);
4121
+ }), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
4201
4122
  }, [dispatch, elementIds, latest, itemRefs]);
4202
4123
  var getTagRemoveProps = useCallback(function (options) {
4203
4124
  var index = options.index,
@@ -4219,7 +4140,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4219
4140
  id: tagRemoveId,
4220
4141
  tabIndex: -1,
4221
4142
  'aria-labelledby': tagRemoveId + " " + tagId,
4222
- onClick: callAllEventHandlers$1(onClick, handleClick)
4143
+ onClick: callAllEventHandlers(onClick, handleClick)
4223
4144
  }, rest);
4224
4145
  }, [elementIds, dispatch]);
4225
4146