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
@@ -3,7 +3,7 @@ import _extends from '@babel/runtime/helpers/esm/extends';
3
3
  import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
4
4
  import PropTypes from 'prop-types';
5
5
  import * as React from 'react';
6
- import { cloneElement, Component, useRef, useCallback, useEffect, useMemo } from 'react';
6
+ import { cloneElement, Component, useRef, useEffect, useCallback, useMemo } from 'react';
7
7
  import { isForwardRef } from 'react-is';
8
8
  import { compute } from 'compute-scroll-into-view';
9
9
 
@@ -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
  /**
@@ -431,34 +489,6 @@ function pickState(state) {
431
489
  return result;
432
490
  }
433
491
 
434
- /**
435
- * This determines whether a prop is a "controlled prop" meaning it is
436
- * state which is controlled by the outside of this component rather
437
- * than within this component.
438
- *
439
- * @param {Object} props The props that may contain controlled values.
440
- * @param {String} key the key to check
441
- * @return {Boolean} whether it is a controlled controlled prop
442
- */
443
- function isControlledProp(props, key) {
444
- return props[key] !== undefined;
445
- }
446
-
447
- /**
448
- * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
449
- * @param {Object} event a keyboardEvent object
450
- * @return {String} keyboard key
451
- */
452
- function normalizeArrowKey(event) {
453
- var key = event.key,
454
- keyCode = event.keyCode;
455
- /* istanbul ignore next (ie) */
456
- if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
457
- return "Arrow" + key;
458
- }
459
- return key;
460
- }
461
-
462
492
  /**
463
493
  * Simple check if the value passed is object literal
464
494
  * @param {*} obj any things
@@ -468,112 +498,6 @@ function isPlainObject(obj) {
468
498
  return Object.prototype.toString.call(obj) === '[object Object]';
469
499
  }
470
500
 
471
- /**
472
- * Returns the next non-disabled highlightedIndex value.
473
- *
474
- * @param {number} start The current highlightedIndex.
475
- * @param {number} offset The offset from the current highlightedIndex to start searching.
476
- * @param {unknown[]} items The items array.
477
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
478
- * @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
479
- * @returns {number} The next highlightedIndex.
480
- */
481
- function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
482
- if (circular === void 0) {
483
- circular = false;
484
- }
485
- var count = items.length;
486
- if (count === 0) {
487
- return -1;
488
- }
489
- var itemsLastIndex = count - 1;
490
- if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
491
- start = offset > 0 ? -1 : itemsLastIndex + 1;
492
- }
493
- var current = start + offset;
494
- if (current < 0) {
495
- current = circular ? itemsLastIndex : 0;
496
- } else if (current > itemsLastIndex) {
497
- current = circular ? 0 : itemsLastIndex;
498
- }
499
- var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
500
- if (highlightedIndex === -1) {
501
- return start >= count ? -1 : start;
502
- }
503
- return highlightedIndex;
504
- }
505
-
506
- /**
507
- * Returns the next non-disabled highlightedIndex value.
508
- *
509
- * @param {number} start The current highlightedIndex.
510
- * @param {boolean} backwards If true, it will search backwards from the start.
511
- * @param {unknown[]} items The items array.
512
- * @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
513
- * @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
514
- * @returns {number} The next non-disabled index.
515
- */
516
- function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
517
- if (circular === void 0) {
518
- circular = false;
519
- }
520
- var count = items.length;
521
- if (backwards) {
522
- for (var index = start; index >= 0; index--) {
523
- if (!isItemDisabled(items[index], index)) {
524
- return index;
525
- }
526
- }
527
- } else {
528
- for (var _index = start; _index < count; _index++) {
529
- if (!isItemDisabled(items[_index], _index)) {
530
- return _index;
531
- }
532
- }
533
- }
534
- if (circular) {
535
- return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
536
- }
537
- return -1;
538
- }
539
-
540
- /**
541
- * Checks if event target is within the downshift elements.
542
- *
543
- * @param {EventTarget} target Target to check.
544
- * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
545
- * @param {Window} environment The window context where downshift renders.
546
- * @param {boolean} checkActiveElement Whether to also check activeElement.
547
- *
548
- * @returns {boolean} Whether or not the target is within downshift elements.
549
- */
550
- function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
551
- if (checkActiveElement === void 0) {
552
- checkActiveElement = true;
553
- }
554
- return environment && downshiftElements.some(function (contextNode) {
555
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
556
- });
557
- }
558
-
559
- // eslint-disable-next-line import/no-mutable-exports
560
- var validateControlledUnchanged = noop;
561
- /* istanbul ignore next */
562
- if (process.env.NODE_ENV !== 'production') {
563
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
564
- 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";
565
- Object.keys(state).forEach(function (propKey) {
566
- if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
567
- // eslint-disable-next-line no-console
568
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
569
- } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
570
- // eslint-disable-next-line no-console
571
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
572
- }
573
- });
574
- };
575
- }
576
-
577
501
  var _excluded$4 = ["refKey", "ref"],
578
502
  _excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
579
503
  _excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
@@ -724,7 +648,7 @@ var Downshift = /*#__PURE__*/function () {
724
648
  }
725
649
  newStateToSet[key];
726
650
  // if it's coming from props, then we don't care to set it internally
727
- if (!isControlledProp(_this.props, key)) {
651
+ if (_this.props[key] === undefined) {
728
652
  nextState[key] = newStateToSet[key];
729
653
  }
730
654
  });
@@ -1458,7 +1382,7 @@ var Downshift = /*#__PURE__*/function () {
1458
1382
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1459
1383
  }
1460
1384
  }
1461
- if (isControlledProp(this.props, 'selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1385
+ if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1462
1386
  this.internalSetState({
1463
1387
  type: controlledPropUpdatedSelectedItem,
1464
1388
  inputValue: this.props.itemToString(this.props.selectedItem)
@@ -1644,7 +1568,7 @@ function callOnChangeProps(action, props, state, newState) {
1644
1568
  changes[key] = newState[key];
1645
1569
  }
1646
1570
  }
1647
- if (props.onStateChange && Object.keys(changes).length) {
1571
+ if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
1648
1572
  props.onStateChange(_extends({
1649
1573
  type: type
1650
1574
  }, changes));
@@ -1670,50 +1594,53 @@ function invokeOnChangeHandler(key, action, props, state, newState) {
1670
1594
  * two reducers, one from downshift and an optional one from the user.
1671
1595
  * Also calls the onChange handlers for state values that have changed.
1672
1596
  *
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.
1597
+ * @param reducer Reducer function from downshift.
1598
+ * @param props The hook props, also passed to createInitialState.
1599
+ * @param createInitialState Function that returns the initial state.
1600
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1601
+ * @returns An array with the state and an action dispatcher.
1678
1602
  */
1679
1603
  function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
1680
- var prevStateRef = React.useRef(null);
1681
- var actionRef = React.useRef(undefined);
1682
- var propsRef = useLatestRef(props);
1604
+ var prevStateRef = React.useRef({});
1605
+ var actionRef = React.useRef();
1683
1606
  var enhancedReducer = React.useCallback(function (state, action) {
1684
1607
  actionRef.current = action;
1685
- state = getState(state, propsRef.current);
1686
- var changes = reducer(state, propsRef.current, action);
1687
- var newState = propsRef.current.stateReducer(state, _extends({}, action, {
1608
+ state = getState(state, action.props);
1609
+ var changes = reducer(state, action);
1610
+ var newState = action.props.stateReducer(state, _extends({}, action, {
1688
1611
  changes: changes
1689
1612
  }));
1690
1613
  return _extends({}, state, newState);
1691
- }, [propsRef, reducer]);
1614
+ }, [reducer]);
1692
1615
  var _React$useReducer = React.useReducer(enhancedReducer, props, createInitialState),
1693
1616
  state = _React$useReducer[0],
1694
1617
  dispatch = _React$useReducer[1];
1618
+ var propsRef = useLatestRef(props);
1619
+ var dispatchWithProps = React.useCallback(function (action) {
1620
+ return dispatch(_extends({}, action, {
1621
+ props: propsRef.current
1622
+ }));
1623
+ }, [propsRef]);
1695
1624
  var action = actionRef.current;
1696
1625
  React.useEffect(function () {
1697
- var _prevStateRef$current;
1698
- var prevState = getState((_prevStateRef$current = prevStateRef.current) != null ? _prevStateRef$current : {}, propsRef.current);
1699
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
1626
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
1627
+ var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
1700
1628
  if (shouldCallOnChangeProps) {
1701
- callOnChangeProps(action, propsRef.current, prevState, state);
1629
+ callOnChangeProps(action, action.props, prevState, state);
1702
1630
  }
1703
1631
  prevStateRef.current = state;
1704
- }, [state, action, isStateEqual, propsRef]);
1705
- return [state, dispatch];
1632
+ }, [state, action, isStateEqual]);
1633
+ return [state, dispatchWithProps];
1706
1634
  }
1707
1635
 
1708
1636
  /**
1709
1637
  * Wraps the useEnhancedReducer and applies the controlled prop values before
1710
1638
  * returning the new state.
1711
- *
1712
- * @param {Function} reducer Reducer function from downshift.
1713
- * @param {Object} props The hook props, also passed to createInitialState.
1714
- * @param {Function} createInitialState Function that returns the initial state.
1715
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
1716
- * @returns {Array} An array with the state and an action dispatcher.
1639
+ * @param reducer Reducer function from downshift.
1640
+ * @param props The hook props, also passed to createInitialState.
1641
+ * @param createInitialState Function that returns the initial state.
1642
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
1643
+ * @returns An array with the state and an action dispatcher.
1717
1644
  */
1718
1645
  function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
1719
1646
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
@@ -1766,16 +1693,8 @@ function useIsInitialMount() {
1766
1693
  return isInitialMountRef.current;
1767
1694
  }
1768
1695
 
1769
- /**
1770
- * Default state reducer that returns the changes.
1771
- *
1772
- */
1773
- function stateReducer(_s, a) {
1774
- return a.changes;
1775
- }
1776
-
1777
1696
  // Shared between all exports.
1778
- var propTypes$5 = {
1697
+ var propTypes$4 = {
1779
1698
  environment: PropTypes.shape({
1780
1699
  addEventListener: PropTypes.func.isRequired,
1781
1700
  removeEventListener: PropTypes.func.isRequired,
@@ -1791,30 +1710,47 @@ var propTypes$5 = {
1791
1710
  stateReducer: PropTypes.func
1792
1711
  };
1793
1712
 
1794
- function getDefaultValue$1(props, propKey, defaultStateValues) {
1795
- var defaultValue = props["default" + capitalizeString(propKey)];
1796
- if (defaultValue !== undefined) {
1797
- return defaultValue;
1798
- }
1799
- return defaultStateValues[propKey];
1713
+ /**
1714
+ * Returns the default value based on the defaultProp and defaultStateValue.
1715
+ *
1716
+ * @param defaultProp The default prop value.
1717
+ * @param defaultStateValue The default state value.
1718
+ * @returns The resolved default value.
1719
+ */
1720
+ function getDefaultValue(defaultProp, defaultStateValue) {
1721
+ return defaultProp === undefined ? defaultStateValue : defaultProp;
1800
1722
  }
1801
1723
 
1802
- function getInitialValue$1(props, propKey, defaultStateValues) {
1803
- var value = props[propKey];
1724
+ /**
1725
+ * Returns the initial value for a state variable, based on the following precedence:
1726
+ * 1. The controlled value (if it's not undefined)
1727
+ * 2. The initialValue (if it's not undefined)
1728
+ * 3. The defaultValue (if it's not undefined)
1729
+ * 4. The defaultStateValue
1730
+ *
1731
+ * @param value The controlled value of the state variable.
1732
+ * @param initialValue The initial value of the state variable.
1733
+ * @param defaultValue The default value of the state variable.
1734
+ * @param defaultStateValue The default state value to use if all other values are undefined.
1735
+ * @returns The initial value for the state variable.
1736
+ */
1737
+ function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
1804
1738
  if (value !== undefined) {
1805
1739
  return value;
1806
1740
  }
1807
- var initialValue = props["initial" + capitalizeString(propKey)];
1808
1741
  if (initialValue !== undefined) {
1809
1742
  return initialValue;
1810
1743
  }
1811
- return getDefaultValue$1(props, propKey, defaultStateValues);
1744
+ if (defaultValue !== undefined) {
1745
+ return defaultValue;
1746
+ }
1747
+ return defaultStateValue;
1812
1748
  }
1813
1749
 
1814
1750
  /**
1815
1751
  * Debounced call for updating the a11y message.
1816
1752
  */
1817
- var updateA11yStatus = debounce$1(function (status, document) {
1753
+ var updateA11yStatus = debounce(function (status, document) {
1818
1754
  setStatus(status, document);
1819
1755
  }, 200);
1820
1756
 
@@ -1850,7 +1786,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
1850
1786
  }
1851
1787
 
1852
1788
  // Shared between useSelect, useCombobox, Downshift.
1853
- var propTypes$4 = _extends({}, propTypes$5, {
1789
+ var dropdownPropTypes = _extends({}, propTypes$4, {
1854
1790
  getA11yStatusMessage: PropTypes.func,
1855
1791
  highlightedIndex: PropTypes.number,
1856
1792
  defaultHighlightedIndex: PropTypes.number,
@@ -1873,62 +1809,145 @@ var propTypes$4 = _extends({}, propTypes$5, {
1873
1809
  scrollIntoView: PropTypes.func
1874
1810
  });
1875
1811
 
1876
- var defaultProps$3 = {
1812
+ var dropdownDefaultProps = {
1877
1813
  itemToString: function itemToString(item) {
1878
1814
  return item ? String(item) : '';
1879
1815
  },
1880
1816
  itemToKey: function itemToKey(item) {
1881
1817
  return item;
1882
1818
  },
1883
- stateReducer: stateReducer,
1819
+ isItemDisabled: function isItemDisabled(_item) {
1820
+ return false;
1821
+ },
1822
+ stateReducer: function stateReducer(_state, actionAndChanges) {
1823
+ return actionAndChanges.changes;
1824
+ },
1884
1825
  scrollIntoView: scrollIntoView,
1885
1826
  environment: /* istanbul ignore next (ssr) */
1886
1827
  typeof window === 'undefined' || false ? undefined : window
1887
1828
  };
1888
1829
 
1889
- var defaultStateValues$1 = {
1830
+ var dropdownDefaultStateValues = {
1890
1831
  highlightedIndex: -1,
1891
1832
  isOpen: false,
1892
1833
  selectedItem: null,
1893
1834
  inputValue: ''
1894
1835
  };
1895
1836
 
1896
- // istanbul ignore next
1897
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React.useLayoutEffect : React.useEffect;
1898
- function isAcceptedCharacterKey(key) {
1899
- return /^\S{1}$/.test(key);
1837
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
1838
+ var SafeReact$1 = _extends({}, React);
1839
+ var reactUseId$1 = SafeReact$1.useId;
1840
+ var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
1841
+ function useElementIdsR18$1(_ref) {
1842
+ var id = _ref.id,
1843
+ labelId = _ref.labelId,
1844
+ menuId = _ref.menuId,
1845
+ getItemId = _ref.getItemId,
1846
+ toggleButtonId = _ref.toggleButtonId,
1847
+ inputId = _ref.inputId;
1848
+ var reactId = "downshift-" + reactUseId$1();
1849
+ if (!id) {
1850
+ id = reactId;
1851
+ }
1852
+ var elementIds = React.useMemo(function () {
1853
+ return {
1854
+ labelId: labelId != null ? labelId : id + "-label",
1855
+ menuId: menuId != null ? menuId : id + "-menu",
1856
+ getItemId: getItemId != null ? getItemId : function (index) {
1857
+ return id + "-item-" + index;
1858
+ },
1859
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
1860
+ inputId: inputId != null ? inputId : id + "-input"
1861
+ };
1862
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1863
+ return elementIds;
1900
1864
  }
1901
- function getInitialState$3(props) {
1902
- var selectedItem = getInitialValue$1(props, 'selectedItem', defaultStateValues$1);
1903
- var isOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
1904
- var highlightedIndex = getInitialHighlightedIndex(props);
1905
- var inputValue = getInitialValue$1(props, 'inputValue', defaultStateValues$1);
1906
- return {
1907
- highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1908
- return props.itemToKey(item) === props.itemToKey(selectedItem);
1909
- }) : highlightedIndex,
1910
- isOpen: isOpen,
1911
- selectedItem: selectedItem,
1912
- inputValue: inputValue
1913
- };
1865
+ function useElementIdsLegacy$1(_ref2) {
1866
+ var id = _ref2.id,
1867
+ labelId = _ref2.labelId,
1868
+ menuId = _ref2.menuId,
1869
+ getItemId = _ref2.getItemId,
1870
+ toggleButtonId = _ref2.toggleButtonId,
1871
+ inputId = _ref2.inputId;
1872
+ var baseIdRef = React.useRef(id != null ? id : "downshift-" + generateId());
1873
+ var baseId = baseIdRef.current;
1874
+ var elementIds = React.useMemo(function () {
1875
+ return {
1876
+ labelId: labelId != null ? labelId : baseId + "-label",
1877
+ menuId: menuId != null ? menuId : baseId + "-menu",
1878
+ getItemId: getItemId != null ? getItemId : function (index) {
1879
+ return baseId + "-item-" + index;
1880
+ },
1881
+ toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
1882
+ inputId: inputId != null ? inputId : baseId + "-input"
1883
+ };
1884
+ }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
1885
+ return elementIds;
1914
1886
  }
1915
- function getHighlightedIndexOnOpen(props, state, offset) {
1916
- var items = props.items,
1917
- initialHighlightedIndex = props.initialHighlightedIndex,
1918
- defaultHighlightedIndex = props.defaultHighlightedIndex,
1919
- isItemDisabled = props.isItemDisabled,
1920
- itemToKey = props.itemToKey;
1921
- var selectedItem = state.selectedItem,
1922
- highlightedIndex = state.highlightedIndex;
1887
+
1888
+ /**
1889
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
1890
+ *
1891
+ * @param props Props passed to the hook.
1892
+ * @returns The highlighted index.
1893
+ */
1894
+ function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
1895
+ var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
1896
+ if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
1897
+ return -1;
1898
+ }
1899
+ return highlightedIndex;
1900
+ }
1901
+
1902
+ /**
1903
+ * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
1904
+ * In that case, selects the item and resets to defaults for open state and highlighted idex.
1905
+ *
1906
+ * @param props The Dropdown props.
1907
+ * @param highlightedIndex The index from the state.
1908
+ * @param inputValue Also return the input value for state.
1909
+ * @returns The changes for the state.
1910
+ */
1911
+ function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
1912
+ var shouldSelect = items.length && highlightedIndex >= 0;
1913
+ return _extends({
1914
+ isOpen: false,
1915
+ highlightedIndex: -1
1916
+ }, shouldSelect && _extends({
1917
+ selectedItem: items[highlightedIndex],
1918
+ isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
1919
+ highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
1920
+ }, inputValue && {
1921
+ inputValue: itemToString(items[highlightedIndex])
1922
+ }));
1923
+ }
1924
+
1925
+ /* eslint-disable max-params */
1926
+ /**
1927
+ * Returns the highlighted index when the menu is opened.
1928
+ * Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
1929
+ * selectedItem, and the open direction offset.
1930
+ *
1931
+ * @param items The list of items.
1932
+ * @param initialHighlightedIndex The initial highlighted index prop.
1933
+ * @param defaultHighlightedIndex The default highlighted index prop.
1934
+ * @param isItemDisabled Callback to determine if an item is disabled.
1935
+ * @param itemToKey Callback to get a unique key from an item.
1936
+ * @param selectedItem The currently selected item.
1937
+ * @param highlightedIndex The current highlighted index from state.
1938
+ * @param offset The direction of navigation: positive opens downward, negative opens upward.
1939
+ * @returns The new highlighted index.
1940
+ */
1941
+ function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
1923
1942
  if (items.length === 0) {
1924
1943
  return -1;
1925
1944
  }
1926
1945
 
1927
1946
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
1928
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1947
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1929
1948
  return initialHighlightedIndex;
1930
1949
  }
1931
- if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1950
+ if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1932
1951
  return defaultHighlightedIndex;
1933
1952
  }
1934
1953
  if (selectedItem) {
@@ -1936,21 +1955,71 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1936
1955
  return itemToKey(selectedItem) === itemToKey(item);
1937
1956
  });
1938
1957
  }
1939
- if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1958
+ if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1940
1959
  return items.length - 1;
1941
1960
  }
1942
- if (offset > 0 && !isItemDisabled(items[0], 0)) {
1961
+ if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
1943
1962
  return 0;
1944
1963
  }
1945
1964
  return -1;
1946
1965
  }
1966
+
1967
+ function getInitialState$3(props) {
1968
+ var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
1969
+ var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
1970
+ var highlightedIndex = getInitialHighlightedIndex(props);
1971
+ var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
1972
+ return {
1973
+ highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
1974
+ return props.itemToKey(item) === props.itemToKey(selectedItem);
1975
+ }) : highlightedIndex,
1976
+ isOpen: isOpen,
1977
+ selectedItem: selectedItem,
1978
+ inputValue: inputValue
1979
+ };
1980
+ }
1981
+
1982
+ /**
1983
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
1984
+ * @param props Props from useCombobox or useSelect.
1985
+ * @returns The highlighted index.
1986
+ */
1987
+ function getInitialHighlightedIndex(props) {
1988
+ var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
1989
+ if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
1990
+ return -1;
1991
+ }
1992
+ return highlightedIndex;
1993
+ }
1994
+
1995
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1996
+ // eslint-disable-next-line import/no-mutable-exports
1997
+ var useControlPropsValidator = noop;
1998
+ /* istanbul ignore next */
1999
+ if (process.env.NODE_ENV !== 'production') {
2000
+ useControlPropsValidator = function useControlPropsValidator(_ref) {
2001
+ var props = _ref.props,
2002
+ state = _ref.state;
2003
+ // used for checking when props are moving from controlled to uncontrolled.
2004
+ var prevPropsRef = React.useRef(props);
2005
+ var isInitialMount = useIsInitialMount();
2006
+ React.useEffect(function () {
2007
+ if (isInitialMount) {
2008
+ return;
2009
+ }
2010
+ validateControlledUnchanged(state, prevPropsRef.current, props);
2011
+ prevPropsRef.current = props;
2012
+ }, [state, props, isInitialMount]);
2013
+ };
2014
+ }
2015
+
1947
2016
  /**
1948
2017
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
1949
2018
  *
1950
- * @param {Window} environment The environment to add the event listeners to, for instance window.
1951
- * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1952
- * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
1953
- * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
2019
+ * @param environment The environment to add the event listeners to, for instance window.
2020
+ * @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
2021
+ * @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
2022
+ * @returns The mouse and touch events information.
1954
2023
  */
1955
2024
  function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
1956
2025
  var mouseAndTouchTrackersRef = React.useRef({
@@ -2014,8 +2083,8 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2014
2083
  /**
2015
2084
  * Custom hook that checks if getter props are called correctly.
2016
2085
  *
2017
- * @param {...any} propKeys Getter prop names to be handled.
2018
- * @returns {Function} Setter function called inside getter props to set call information.
2086
+ * @param propKeys Getter prop names to be handled.
2087
+ * @returns Setter function called inside getter props to set call information.
2019
2088
  */
2020
2089
  /* istanbul ignore next */
2021
2090
  if (process.env.NODE_ENV !== 'production') {
@@ -2051,120 +2120,58 @@ if (process.env.NODE_ENV !== 'production') {
2051
2120
  getterPropsCalledRef.current[propKey] = {
2052
2121
  suppressRefError: suppressRefError,
2053
2122
  refKey: refKey,
2054
- elementRef: elementRef
2055
- };
2056
- }, []);
2057
- return setGetterPropCallInfo;
2058
- };
2059
- }
2060
- function useScrollIntoView(_ref) {
2061
- var highlightedIndex = _ref.highlightedIndex,
2062
- isOpen = _ref.isOpen,
2063
- itemRefs = _ref.itemRefs,
2064
- getItemNodeFromIndex = _ref.getItemNodeFromIndex,
2065
- menuElement = _ref.menuElement,
2066
- scrollIntoViewProp = _ref.scrollIntoView;
2067
- // used not to scroll on highlight by mouse.
2068
- var shouldScrollRef = React.useRef(true);
2069
- // Scroll on highlighted item if change comes from keyboard.
2070
- useIsomorphicLayoutEffect(function () {
2071
- if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2072
- return;
2073
- }
2074
- if (shouldScrollRef.current === false) {
2075
- shouldScrollRef.current = true;
2076
- } else {
2077
- scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
2078
- }
2079
- // eslint-disable-next-line react-hooks/exhaustive-deps
2080
- }, [highlightedIndex]);
2081
- return shouldScrollRef;
2082
- }
2083
-
2084
- // eslint-disable-next-line import/no-mutable-exports
2085
- var useControlPropsValidator = noop;
2086
- /* istanbul ignore next */
2087
- if (process.env.NODE_ENV !== 'production') {
2088
- useControlPropsValidator = function useControlPropsValidator(_ref2) {
2089
- var props = _ref2.props,
2090
- state = _ref2.state;
2091
- // used for checking when props are moving from controlled to uncontrolled.
2092
- var prevPropsRef = React.useRef(props);
2093
- var isInitialMount = useIsInitialMount();
2094
- React.useEffect(function () {
2095
- if (isInitialMount) {
2096
- return;
2097
- }
2098
- validateControlledUnchanged(state, prevPropsRef.current, props);
2099
- prevPropsRef.current = props;
2100
- }, [state, props, isInitialMount]);
2101
- };
2102
- }
2103
-
2104
- /**
2105
- * Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
2106
- * In that case, selects the item and resets to defaults for open state and highlighted idex.
2107
- * @param {Object} props The useCombobox props.
2108
- * @param {number} highlightedIndex The index from the state.
2109
- * @param {boolean} inputValue Also return the input value for state.
2110
- * @returns The changes for the state.
2111
- */
2112
- function getChangesOnSelection(props, highlightedIndex, inputValue) {
2113
- var _props$items;
2114
- if (inputValue === void 0) {
2115
- inputValue = true;
2116
- }
2117
- var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
2118
- return _extends({
2119
- isOpen: false,
2120
- highlightedIndex: -1
2121
- }, shouldSelect && _extends({
2122
- selectedItem: props.items[highlightedIndex],
2123
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2124
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
2125
- }, inputValue && {
2126
- inputValue: props.itemToString(props.items[highlightedIndex])
2127
- }));
2128
- }
2129
-
2130
- /**
2131
- * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2132
- * Used by useSelect and useCombobox.
2133
- *
2134
- * @param {Object} prevState
2135
- * @param {Object} newState
2136
- * @returns {boolean} Wheather the states are deeply equal.
2137
- */
2138
- function isDropdownsStateEqual(prevState, newState) {
2139
- return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2123
+ elementRef: elementRef
2124
+ };
2125
+ }, []);
2126
+ return setGetterPropCallInfo;
2127
+ };
2140
2128
  }
2141
2129
 
2130
+ // istanbul ignore next
2131
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React.useLayoutEffect : React.useEffect;
2132
+
2142
2133
  /**
2143
- * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2144
- *
2145
- * @param {Object} props Props from useCombobox or useSelect.
2146
- * @returns {number} The highlighted index.
2134
+ * Utility hook that scrolls an item from a menu into view.
2135
+ * @param scrollIntoView The function that does the scroll.
2136
+ * @param highlightedIndex The index of the item that should be scrolled.
2137
+ * @param isOpen If the menu is open or not.
2138
+ * @param menuElement The menu element.
2139
+ * @param itemElements The object containing item elements.
2140
+ * @param getItemId The function to get the item id from index.
2141
+ * @returns Function that when called prevents the scroll.
2147
2142
  */
2148
- function getDefaultHighlightedIndex(props) {
2149
- var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
2150
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2151
- return -1;
2152
- }
2153
- return highlightedIndex;
2143
+ function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
2144
+ // used not to scroll on highlight by mouse.
2145
+ var shouldScrollRef = React.useRef(true);
2146
+ // Scroll on highlighted item if change comes from keyboard.
2147
+ useIsomorphicLayoutEffect(function () {
2148
+ if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
2149
+ return;
2150
+ }
2151
+ if (shouldScrollRef.current) {
2152
+ var itemElement = itemElements[getItemId(highlightedIndex)];
2153
+ if (itemElement && menuElement) {
2154
+ scrollIntoView(itemElement, menuElement);
2155
+ }
2156
+ } else {
2157
+ shouldScrollRef.current = true;
2158
+ }
2159
+ }, [highlightedIndex]);
2160
+ return React.useCallback(function preventScroll() {
2161
+ shouldScrollRef.current = false;
2162
+ }, []);
2154
2163
  }
2155
2164
 
2156
2165
  /**
2157
- * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2166
+ * Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
2167
+ * Used by useSelect and useCombobox.
2158
2168
  *
2159
- * @param {Object} props Props from useCombobox or useSelect.
2160
- * @returns {number} The highlighted index.
2169
+ * @param prevState The previous dropdown state.
2170
+ * @param newState The new dropdown state.
2171
+ * @returns Wheather the states are deeply equal.
2161
2172
  */
2162
- function getInitialHighlightedIndex(props) {
2163
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
2164
- if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2165
- return -1;
2166
- }
2167
- return highlightedIndex;
2173
+ function isDropdownStateEqual(prevState, newState) {
2174
+ return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2168
2175
  }
2169
2176
 
2170
2177
  function downshiftCommonReducer(state, props, action, stateChangeTypes) {
@@ -2185,13 +2192,13 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2185
2192
  case stateChangeTypes.FunctionToggleMenu:
2186
2193
  changes = {
2187
2194
  isOpen: !state.isOpen,
2188
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
2195
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2189
2196
  };
2190
2197
  break;
2191
2198
  case stateChangeTypes.FunctionOpenMenu:
2192
2199
  changes = {
2193
2200
  isOpen: true,
2194
- highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
2201
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
2195
2202
  };
2196
2203
  break;
2197
2204
  case stateChangeTypes.FunctionCloseMenu:
@@ -2200,9 +2207,12 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2200
2207
  };
2201
2208
  break;
2202
2209
  case stateChangeTypes.FunctionSetHighlightedIndex:
2203
- changes = {
2204
- highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
2205
- };
2210
+ {
2211
+ var highlightedIndex = action.highlightedIndex;
2212
+ changes = {
2213
+ highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
2214
+ };
2215
+ }
2206
2216
  break;
2207
2217
  case stateChangeTypes.FunctionSetInputValue:
2208
2218
  changes = {
@@ -2211,10 +2221,10 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2211
2221
  break;
2212
2222
  case stateChangeTypes.FunctionReset:
2213
2223
  changes = {
2214
- highlightedIndex: getDefaultHighlightedIndex(props),
2215
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2216
- selectedItem: getDefaultValue$1(props, 'selectedItem', defaultStateValues$1),
2217
- inputValue: getDefaultValue$1(props, 'inputValue', defaultStateValues$1)
2224
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2225
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2226
+ selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
2227
+ inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
2218
2228
  };
2219
2229
  break;
2220
2230
  default:
@@ -2224,17 +2234,11 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
2224
2234
  }
2225
2235
  /* eslint-enable complexity */
2226
2236
 
2227
- var propTypes$3 = _extends({}, propTypes$4, {
2237
+ var propTypes$3 = _extends({}, dropdownPropTypes, {
2228
2238
  items: PropTypes.array.isRequired,
2229
2239
  isItemDisabled: PropTypes.func
2230
2240
  });
2231
2241
 
2232
- var defaultProps$2 = _extends({}, defaultProps$3, {
2233
- isItemDisabled: function isItemDisabled() {
2234
- return false;
2235
- }
2236
- });
2237
-
2238
2242
  function getItemIndexByCharacterKey(_ref) {
2239
2243
  var keysSoFar = _ref.keysSoFar,
2240
2244
  highlightedIndex = _ref.highlightedIndex,
@@ -2303,16 +2307,15 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
2303
2307
  });
2304
2308
 
2305
2309
  /* eslint-disable complexity */
2306
- function downshiftSelectReducer(state, props, action) {
2307
- var _props$items;
2310
+ function downshiftSelectReducer(state, action) {
2308
2311
  var type = action.type,
2309
- altKey = action.altKey;
2312
+ props = action.props;
2310
2313
  var changes;
2311
2314
  switch (type) {
2312
2315
  case ItemClick$1:
2313
2316
  changes = {
2314
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2315
- highlightedIndex: getDefaultHighlightedIndex(props),
2317
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2318
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2316
2319
  selectedItem: props.items[action.index]
2317
2320
  };
2318
2321
  break;
@@ -2339,7 +2342,8 @@ function downshiftSelectReducer(state, props, action) {
2339
2342
  break;
2340
2343
  case ToggleButtonKeyDownArrowDown:
2341
2344
  {
2342
- var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2345
+ var altKey = action.altKey;
2346
+ 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);
2343
2347
  changes = {
2344
2348
  highlightedIndex: _highlightedIndex,
2345
2349
  isOpen: true
@@ -2347,20 +2351,23 @@ function downshiftSelectReducer(state, props, action) {
2347
2351
  }
2348
2352
  break;
2349
2353
  case ToggleButtonKeyDownArrowUp:
2350
- if (state.isOpen && altKey) {
2351
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2352
- } else {
2353
- var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props, state, -1);
2354
- changes = {
2355
- highlightedIndex: _highlightedIndex2,
2356
- isOpen: true
2357
- };
2354
+ {
2355
+ var _altKey = action.altKey;
2356
+ if (state.isOpen && _altKey) {
2357
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2358
+ } else {
2359
+ 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);
2360
+ changes = {
2361
+ highlightedIndex: _highlightedIndex2,
2362
+ isOpen: true
2363
+ };
2364
+ }
2358
2365
  }
2359
2366
  break;
2360
2367
  // only triggered when menu is open.
2361
2368
  case ToggleButtonKeyDownEnter:
2362
2369
  case ToggleButtonKeyDownSpaceButton:
2363
- changes = getChangesOnSelection(props, state.highlightedIndex, false);
2370
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
2364
2371
  break;
2365
2372
  case ToggleButtonKeyDownHome:
2366
2373
  changes = {
@@ -2394,7 +2401,7 @@ function downshiftSelectReducer(state, props, action) {
2394
2401
  changes = _extends({
2395
2402
  isOpen: false,
2396
2403
  highlightedIndex: -1
2397
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
2404
+ }, state.highlightedIndex >= 0 && props.items.length && {
2398
2405
  selectedItem: props.items[state.highlightedIndex]
2399
2406
  });
2400
2407
  break;
@@ -2410,59 +2417,9 @@ function downshiftSelectReducer(state, props, action) {
2410
2417
  }
2411
2418
  /* eslint-enable complexity */
2412
2419
 
2413
- // eslint-disable-next-line @typescript-eslint/dot-notation
2414
- var reactUseId$1 = React['useId'];
2415
- var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
2416
- function useElementIdsR18$1(_ref) {
2417
- var id = _ref.id,
2418
- labelId = _ref.labelId,
2419
- menuId = _ref.menuId,
2420
- getItemId = _ref.getItemId,
2421
- toggleButtonId = _ref.toggleButtonId,
2422
- inputId = _ref.inputId;
2423
- var reactId = "downshift-" + reactUseId$1();
2424
- if (!id) {
2425
- id = reactId;
2426
- }
2427
- var elementIds = React.useMemo(function () {
2428
- return {
2429
- labelId: labelId != null ? labelId : id + "-label",
2430
- menuId: menuId != null ? menuId : id + "-menu",
2431
- getItemId: getItemId != null ? getItemId : function (index) {
2432
- return id + "-item-" + index;
2433
- },
2434
- toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
2435
- inputId: inputId != null ? inputId : id + "-input"
2436
- };
2437
- }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2438
- return elementIds;
2439
- }
2440
- function useElementIdsLegacy$1(_ref2) {
2441
- var id = _ref2.id,
2442
- labelId = _ref2.labelId,
2443
- menuId = _ref2.menuId,
2444
- getItemId = _ref2.getItemId,
2445
- toggleButtonId = _ref2.toggleButtonId,
2446
- inputId = _ref2.inputId;
2447
- var baseIdRef = React.useRef(id != null ? id : "downshift-" + generateId());
2448
- var baseId = baseIdRef.current;
2449
- var elementIds = React.useMemo(function () {
2450
- return {
2451
- labelId: labelId != null ? labelId : baseId + "-label",
2452
- menuId: menuId != null ? menuId : baseId + "-menu",
2453
- getItemId: getItemId != null ? getItemId : function (index) {
2454
- return baseId + "-item-" + index;
2455
- },
2456
- toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
2457
- inputId: inputId != null ? inputId : baseId + "-input"
2458
- };
2459
- }, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
2460
- return elementIds;
2461
- }
2462
-
2463
2420
  var _excluded$3 = ["onClick"],
2464
- _excluded2$3 = ["onMouseLeave", "refKey", "ref"],
2465
- _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
2421
+ _excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
2422
+ _excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
2466
2423
  _excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
2467
2424
  useSelect.stateChangeTypes = stateChangeTypes$3;
2468
2425
  function useSelect(userProps) {
@@ -2471,22 +2428,23 @@ function useSelect(userProps) {
2471
2428
  }
2472
2429
  validatePropTypes$1(userProps, useSelect, propTypes$3);
2473
2430
  // Props defaults and destructuring.
2474
- var props = _extends({}, defaultProps$2, userProps);
2431
+ var props = _extends({}, dropdownDefaultProps, userProps);
2475
2432
  var scrollIntoView = props.scrollIntoView,
2476
2433
  environment = props.environment,
2477
2434
  getA11yStatusMessage = props.getA11yStatusMessage;
2478
2435
  // Initial state depending on controlled props.
2479
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownsStateEqual),
2436
+ var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
2480
2437
  state = _useControlledReducer[0],
2481
2438
  dispatch = _useControlledReducer[1];
2482
2439
  var isOpen = state.isOpen,
2483
2440
  highlightedIndex = state.highlightedIndex,
2484
2441
  selectedItem = state.selectedItem,
2485
2442
  inputValue = state.inputValue;
2486
- // Element efs.
2443
+
2444
+ // Element refs.
2487
2445
  var toggleButtonRef = useRef(null);
2488
2446
  var menuRef = useRef(null);
2489
- var itemRefs = useRef({});
2447
+ var itemsRef = useRef({});
2490
2448
 
2491
2449
  // used to keep the inputValue clearTimeout object between renders.
2492
2450
  var clearTimeoutRef = useRef(null);
@@ -2498,24 +2456,12 @@ function useSelect(userProps) {
2498
2456
  props: props
2499
2457
  });
2500
2458
 
2501
- // Some utils.
2502
- var getItemNodeFromIndex = useCallback(function (index) {
2503
- return itemRefs.current[elementIds.getItemId(index)];
2504
- }, [elementIds]);
2505
-
2506
2459
  // Effects.
2507
2460
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
2508
2461
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
2509
2462
  // Scroll on highlighted item if change comes from keyboard.
2510
- var shouldScrollRef = useScrollIntoView({
2511
- menuElement: menuRef.current,
2512
- highlightedIndex: highlightedIndex,
2513
- isOpen: isOpen,
2514
- itemRefs: itemRefs,
2515
- scrollIntoView: scrollIntoView,
2516
- getItemNodeFromIndex: getItemNodeFromIndex
2517
- });
2518
- // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2463
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
2464
+ // Sets cleanup for the keysSoFar callback, debounced after 500ms.
2519
2465
  useEffect(function () {
2520
2466
  // init the clean function here as we need access to dispatch.
2521
2467
  clearTimeoutRef.current = debounce(function (outerDispatch) {
@@ -2527,7 +2473,8 @@ function useSelect(userProps) {
2527
2473
 
2528
2474
  // Cancel any pending debounced calls on mount
2529
2475
  return function () {
2530
- clearTimeoutRef.current.cancel();
2476
+ var _clearTimeoutRef$curr;
2477
+ (_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
2531
2478
  };
2532
2479
  }, []);
2533
2480
  // Invokes the keysSoFar callback set up above.
@@ -2535,7 +2482,7 @@ function useSelect(userProps) {
2535
2482
  if (!inputValue) {
2536
2483
  return;
2537
2484
  }
2538
- clearTimeoutRef.current(dispatch);
2485
+ clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
2539
2486
  }, [dispatch, inputValue]);
2540
2487
  useControlPropsValidator({
2541
2488
  props: props,
@@ -2543,7 +2490,7 @@ function useSelect(userProps) {
2543
2490
  });
2544
2491
  // Focus the toggle button on first render if required.
2545
2492
  useEffect(function () {
2546
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
2493
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
2547
2494
  if (focusOnOpen && toggleButtonRef.current) {
2548
2495
  toggleButtonRef.current.focus();
2549
2496
  }
@@ -2564,7 +2511,7 @@ function useSelect(userProps) {
2564
2511
  // Reset itemRefs on close.
2565
2512
  useEffect(function () {
2566
2513
  if (!isOpen) {
2567
- itemRefs.current = {};
2514
+ itemsRef.current = {};
2568
2515
  }
2569
2516
  }, [isOpen]);
2570
2517
 
@@ -2649,50 +2596,11 @@ function useSelect(userProps) {
2649
2596
  };
2650
2597
  }, [dispatch, latest]);
2651
2598
 
2652
- // Action functions.
2653
- var toggleMenu = useCallback(function () {
2654
- dispatch({
2655
- type: FunctionToggleMenu$1
2656
- });
2657
- }, [dispatch]);
2658
- var closeMenu = useCallback(function () {
2659
- dispatch({
2660
- type: FunctionCloseMenu$1
2661
- });
2662
- }, [dispatch]);
2663
- var openMenu = useCallback(function () {
2664
- dispatch({
2665
- type: FunctionOpenMenu$1
2666
- });
2667
- }, [dispatch]);
2668
- var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
2669
- dispatch({
2670
- type: FunctionSetHighlightedIndex$1,
2671
- highlightedIndex: newHighlightedIndex
2672
- });
2673
- }, [dispatch]);
2674
- var selectItem = useCallback(function (newSelectedItem) {
2675
- dispatch({
2676
- type: FunctionSelectItem$1,
2677
- selectedItem: newSelectedItem
2678
- });
2679
- }, [dispatch]);
2680
- var reset = useCallback(function () {
2681
- dispatch({
2682
- type: FunctionReset$2
2683
- });
2684
- }, [dispatch]);
2685
- var setInputValue = useCallback(function (newInputValue) {
2686
- dispatch({
2687
- type: FunctionSetInputValue$1,
2688
- inputValue: newInputValue
2689
- });
2690
- }, [dispatch]);
2691
2599
  // Getter functions.
2692
- var getLabelProps = useCallback(function (_temp) {
2693
- var _ref = _temp === void 0 ? {} : _temp,
2600
+ var getLabelProps = useCallback(function (labelProps) {
2601
+ var _ref = labelProps != null ? labelProps : {},
2694
2602
  onClick = _ref.onClick,
2695
- labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2603
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
2696
2604
  var labelHandleClick = function labelHandleClick() {
2697
2605
  var _toggleButtonRef$curr;
2698
2606
  (_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
@@ -2701,17 +2609,18 @@ function useSelect(userProps) {
2701
2609
  id: elementIds.labelId,
2702
2610
  htmlFor: elementIds.toggleButtonId,
2703
2611
  onClick: callAllEventHandlers(onClick, labelHandleClick)
2704
- }, labelProps);
2612
+ }, rest);
2705
2613
  }, [elementIds]);
2706
- var getMenuProps = useCallback(function (_temp2, _temp3) {
2614
+ var getMenuProps = useCallback(function (menuProps, otherProps) {
2707
2615
  var _extends2;
2708
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2616
+ var _ref2 = menuProps != null ? menuProps : {},
2709
2617
  onMouseLeave = _ref2.onMouseLeave,
2710
2618
  _ref2$refKey = _ref2.refKey,
2711
2619
  refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
2712
2620
  ref = _ref2.ref,
2621
+ ariaLabel = _ref2['aria-label'],
2713
2622
  rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
2714
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2623
+ var _ref3 = otherProps != null ? otherProps : {},
2715
2624
  _ref3$suppressRefErro = _ref3.suppressRefError,
2716
2625
  suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
2717
2626
  var menuHandleMouseLeave = function menuHandleMouseLeave() {
@@ -2722,11 +2631,11 @@ function useSelect(userProps) {
2722
2631
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2723
2632
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2724
2633
  menuRef.current = menuNode;
2725
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
2634
+ }), _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);
2726
2635
  }, [dispatch, setGetterPropCallInfo, elementIds]);
2727
- var getToggleButtonProps = useCallback(function (_temp4, _temp5) {
2636
+ var getToggleButtonProps = useCallback(function (toggleButtonProps, otherProps) {
2728
2637
  var _extends3;
2729
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2638
+ var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
2730
2639
  onBlur = _ref4.onBlur,
2731
2640
  onClick = _ref4.onClick;
2732
2641
  _ref4.onPress;
@@ -2734,8 +2643,9 @@ function useSelect(userProps) {
2734
2643
  _ref4$refKey = _ref4.refKey,
2735
2644
  refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
2736
2645
  ref = _ref4.ref,
2646
+ disabled = _ref4.disabled,
2737
2647
  rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
2738
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2648
+ var _ref5 = otherProps != null ? otherProps : {},
2739
2649
  _ref5$suppressRefErro = _ref5.suppressRefError,
2740
2650
  suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
2741
2651
  var latestState = latest.current.state;
@@ -2753,9 +2663,9 @@ function useSelect(userProps) {
2753
2663
  };
2754
2664
  var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2755
2665
  var key = normalizeArrowKey(event);
2756
- if (key && toggleButtonKeyDownHandlers[key]) {
2666
+ if (key && key in toggleButtonKeyDownHandlers) {
2757
2667
  toggleButtonKeyDownHandlers[key](event);
2758
- } else if (isAcceptedCharacterKey(key)) {
2668
+ } else if (/^\S{1}$/.test(key)) {
2759
2669
  dispatch({
2760
2670
  type: ToggleButtonKeyDownCharacter,
2761
2671
  key: key
@@ -2764,20 +2674,22 @@ function useSelect(userProps) {
2764
2674
  };
2765
2675
  var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2766
2676
  toggleButtonRef.current = toggleButtonNode;
2767
- }), _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);
2768
- if (!rest.disabled) {
2677
+ }), _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);
2678
+ if (!disabled) {
2769
2679
  /* istanbul ignore if (react-native) */
2770
2680
  {
2771
- toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
2772
- toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
2681
+ Object.assign(toggleProps, {
2682
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick),
2683
+ onKeyDown: callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown)
2684
+ });
2773
2685
  }
2774
2686
  }
2775
2687
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2776
2688
  return toggleProps;
2777
2689
  }, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
2778
- var getItemProps = useCallback(function (_temp6) {
2690
+ var getItemProps = useCallback(function (itemProps) {
2779
2691
  var _extends4;
2780
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
2692
+ var _ref6 = itemProps != null ? itemProps : {},
2781
2693
  itemProp = _ref6.item,
2782
2694
  indexProp = _ref6.index,
2783
2695
  onMouseMove = _ref6.onMouseMove,
@@ -2803,7 +2715,7 @@ function useSelect(userProps) {
2803
2715
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
2804
2716
  return;
2805
2717
  }
2806
- shouldScrollRef.current = false;
2718
+ preventScroll();
2807
2719
  dispatch({
2808
2720
  type: ItemMouseMove$1,
2809
2721
  index: index,
@@ -2820,21 +2732,61 @@ function useSelect(userProps) {
2820
2732
  return e.preventDefault();
2821
2733
  }; // keep focus on the toggle after item click select.
2822
2734
 
2823
- var itemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2735
+ var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2824
2736
  if (itemNode) {
2825
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
2737
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
2826
2738
  }
2827
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2739
+ }), _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);
2828
2740
  if (!disabled) {
2829
2741
  /* istanbul ignore next (react-native) */
2830
2742
  {
2831
- itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2743
+ Object.assign(resultItemProps, {
2744
+ onClick: callAllEventHandlers(onClick, itemHandleClick)
2745
+ });
2832
2746
  }
2833
2747
  }
2834
- itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
2835
- itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
2836
- return itemProps;
2837
- }, [latest, elementIds, mouseAndTouchTrackers, shouldScrollRef, dispatch]);
2748
+ return resultItemProps;
2749
+ }, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
2750
+
2751
+ // Action functions.
2752
+ var toggleMenu = useCallback(function () {
2753
+ dispatch({
2754
+ type: FunctionToggleMenu$1
2755
+ });
2756
+ }, [dispatch]);
2757
+ var closeMenu = useCallback(function () {
2758
+ dispatch({
2759
+ type: FunctionCloseMenu$1
2760
+ });
2761
+ }, [dispatch]);
2762
+ var openMenu = useCallback(function () {
2763
+ dispatch({
2764
+ type: FunctionOpenMenu$1
2765
+ });
2766
+ }, [dispatch]);
2767
+ var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
2768
+ dispatch({
2769
+ type: FunctionSetHighlightedIndex$1,
2770
+ highlightedIndex: newHighlightedIndex
2771
+ });
2772
+ }, [dispatch]);
2773
+ var selectItem = useCallback(function (newSelectedItem) {
2774
+ dispatch({
2775
+ type: FunctionSelectItem$1,
2776
+ selectedItem: newSelectedItem
2777
+ });
2778
+ }, [dispatch]);
2779
+ var reset = useCallback(function () {
2780
+ dispatch({
2781
+ type: FunctionReset$2
2782
+ });
2783
+ }, [dispatch]);
2784
+ var setInputValue = useCallback(function (newInputValue) {
2785
+ dispatch({
2786
+ type: FunctionSetInputValue$1,
2787
+ inputValue: newInputValue
2788
+ });
2789
+ }, [dispatch]);
2838
2790
  return {
2839
2791
  // prop getters.
2840
2792
  getToggleButtonProps: getToggleButtonProps,
@@ -2857,6 +2809,18 @@ function useSelect(userProps) {
2857
2809
  };
2858
2810
  }
2859
2811
 
2812
+ function getInitialState$2(props) {
2813
+ var initialState = getInitialState$3(props);
2814
+ var selectedItem = initialState.selectedItem;
2815
+ var inputValue = initialState.inputValue;
2816
+ if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2817
+ inputValue = props.itemToString(selectedItem);
2818
+ }
2819
+ return _extends({}, initialState, {
2820
+ inputValue: inputValue
2821
+ });
2822
+ }
2823
+
2860
2824
  var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2861
2825
  var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2862
2826
  var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
@@ -2908,27 +2872,6 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2908
2872
  ToggleButtonClick: ToggleButtonClick
2909
2873
  });
2910
2874
 
2911
- function getInitialState$2(props) {
2912
- var initialState = getInitialState$3(props);
2913
- var selectedItem = initialState.selectedItem;
2914
- var inputValue = initialState.inputValue;
2915
- if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2916
- inputValue = props.itemToString(selectedItem);
2917
- }
2918
- return _extends({}, initialState, {
2919
- inputValue: inputValue
2920
- });
2921
- }
2922
- var propTypes$2 = _extends({}, propTypes$4, {
2923
- items: PropTypes.array.isRequired,
2924
- isItemDisabled: PropTypes.func,
2925
- inputValue: PropTypes.string,
2926
- defaultInputValue: PropTypes.string,
2927
- initialInputValue: PropTypes.string,
2928
- inputId: PropTypes.string,
2929
- onInputValueChange: PropTypes.func
2930
- });
2931
-
2932
2875
  /**
2933
2876
  * The useCombobox version of useControlledReducer, which also
2934
2877
  * checks if the controlled prop selectedItem changed between
@@ -2936,20 +2879,20 @@ var propTypes$2 = _extends({}, propTypes$4, {
2936
2879
  * string equivalent. It uses the common useEnhancedReducer to
2937
2880
  * compute the rest of the state.
2938
2881
  *
2939
- * @param {Function} reducer Reducer function from downshift.
2940
- * @param {Object} props The hook props, also passed to createInitialState.
2941
- * @param {Function} createInitialState Function that returns the initial state.
2942
- * @param {Function} isStateEqual Function that checks if a previous state is equal to the next.
2943
- * @returns {Array} An array with the state and an action dispatcher.
2882
+ * @param reducer Reducer function from downshift.
2883
+ * @param props The hook props, also passed to createInitialState.
2884
+ * @param createInitialState Function that returns the initial state.
2885
+ * @param isStateEqual Function that checks if a previous state is equal to the next.
2886
+ * @returns An array with the state and an action dispatcher.
2944
2887
  */
2945
2888
  function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
2946
- var previousSelectedItemRef = useRef();
2889
+ var previousSelectedItemRef = useRef(null);
2947
2890
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
2948
2891
  state = _useEnhancedReducer[0],
2949
2892
  dispatch = _useEnhancedReducer[1];
2950
2893
  var isInitialMount = useIsInitialMount();
2951
2894
  useEffect(function () {
2952
- if (!isControlledProp(props, 'selectedItem')) {
2895
+ if (props.selectedItem === undefined) {
2953
2896
  return;
2954
2897
  }
2955
2898
  if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
@@ -2967,23 +2910,27 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
2967
2910
  }, [state.selectedItem, props.selectedItem]);
2968
2911
  return [getState(state, props), dispatch];
2969
2912
  }
2970
- var defaultProps$1 = _extends({}, defaultProps$3, {
2971
- isItemDisabled: function isItemDisabled() {
2972
- return false;
2973
- }
2913
+
2914
+ var propTypes$2 = _extends({}, dropdownPropTypes, {
2915
+ items: PropTypes.array.isRequired,
2916
+ isItemDisabled: PropTypes.func,
2917
+ inputValue: PropTypes.string,
2918
+ defaultInputValue: PropTypes.string,
2919
+ initialInputValue: PropTypes.string,
2920
+ inputId: PropTypes.string,
2921
+ onInputValueChange: PropTypes.func
2974
2922
  });
2975
2923
 
2976
2924
  /* eslint-disable complexity */
2977
- function downshiftUseComboboxReducer(state, props, action) {
2978
- var _props$items;
2925
+ function downshiftUseComboboxReducer(state, action) {
2979
2926
  var type = action.type,
2980
- altKey = action.altKey;
2927
+ props = action.props;
2981
2928
  var changes;
2982
2929
  switch (type) {
2983
2930
  case ItemClick:
2984
2931
  changes = {
2985
- isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
2986
- highlightedIndex: getDefaultHighlightedIndex(props),
2932
+ isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
2933
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
2987
2934
  selectedItem: props.items[action.index],
2988
2935
  inputValue: props.itemToString(props.items[action.index])
2989
2936
  };
@@ -2995,15 +2942,15 @@ function downshiftUseComboboxReducer(state, props, action) {
2995
2942
  };
2996
2943
  } else {
2997
2944
  changes = {
2998
- highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
2945
+ highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
2999
2946
  isOpen: props.items.length >= 0
3000
2947
  };
3001
2948
  }
3002
2949
  break;
3003
2950
  case InputKeyDownArrowUp:
3004
2951
  if (state.isOpen) {
3005
- if (altKey) {
3006
- changes = getChangesOnSelection(props, state.highlightedIndex);
2952
+ if (action.altKey) {
2953
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
3007
2954
  } else {
3008
2955
  changes = {
3009
2956
  highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
@@ -3011,13 +2958,13 @@ function downshiftUseComboboxReducer(state, props, action) {
3011
2958
  }
3012
2959
  } else {
3013
2960
  changes = {
3014
- highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
2961
+ highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
3015
2962
  isOpen: props.items.length >= 0
3016
2963
  };
3017
2964
  }
3018
2965
  break;
3019
2966
  case InputKeyDownEnter:
3020
- changes = getChangesOnSelection(props, state.highlightedIndex);
2967
+ changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
3021
2968
  break;
3022
2969
  case InputKeyDownEscape:
3023
2970
  changes = _extends({
@@ -3052,7 +2999,7 @@ function downshiftUseComboboxReducer(state, props, action) {
3052
2999
  changes = _extends({
3053
3000
  isOpen: false,
3054
3001
  highlightedIndex: -1
3055
- }, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
3002
+ }, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
3056
3003
  selectedItem: props.items[state.highlightedIndex],
3057
3004
  inputValue: props.itemToString(props.items[state.highlightedIndex])
3058
3005
  });
@@ -3060,14 +3007,14 @@ function downshiftUseComboboxReducer(state, props, action) {
3060
3007
  case InputChange:
3061
3008
  changes = {
3062
3009
  isOpen: true,
3063
- highlightedIndex: getDefaultHighlightedIndex(props),
3010
+ highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
3064
3011
  inputValue: action.inputValue
3065
3012
  };
3066
3013
  break;
3067
3014
  case InputClick:
3068
3015
  changes = {
3069
3016
  isOpen: !state.isOpen,
3070
- highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
3017
+ highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
3071
3018
  };
3072
3019
  break;
3073
3020
  case FunctionSelectItem:
@@ -3088,10 +3035,10 @@ function downshiftUseComboboxReducer(state, props, action) {
3088
3035
  }
3089
3036
  /* eslint-enable complexity */
3090
3037
 
3091
- var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
3038
+ var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
3092
3039
  _excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
3093
- _excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
3094
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3040
+ _excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
3041
+ _excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
3095
3042
  useCombobox.stateChangeTypes = stateChangeTypes$2;
3096
3043
  function useCombobox(userProps) {
3097
3044
  if (userProps === void 0) {
@@ -3099,13 +3046,13 @@ function useCombobox(userProps) {
3099
3046
  }
3100
3047
  validatePropTypes$1(userProps, useCombobox, propTypes$2);
3101
3048
  // Props defaults and destructuring.
3102
- var props = _extends({}, defaultProps$1, userProps);
3049
+ var props = _extends({}, dropdownDefaultProps, userProps);
3103
3050
  var items = props.items,
3104
3051
  scrollIntoView = props.scrollIntoView,
3105
3052
  environment = props.environment,
3106
3053
  getA11yStatusMessage = props.getA11yStatusMessage;
3107
3054
  // Initial state depending on controlled props.
3108
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownsStateEqual),
3055
+ var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
3109
3056
  state = _useControlledReducer[0],
3110
3057
  dispatch = _useControlledReducer[1];
3111
3058
  var isOpen = state.isOpen,
@@ -3115,7 +3062,7 @@ function useCombobox(userProps) {
3115
3062
 
3116
3063
  // Element refs.
3117
3064
  var menuRef = useRef(null);
3118
- var itemRefs = useRef({});
3065
+ var itemsRef = useRef({});
3119
3066
  var inputRef = useRef(null);
3120
3067
  var toggleButtonRef = useRef(null);
3121
3068
  var isInitialMount = useIsInitialMount();
@@ -3129,29 +3076,19 @@ function useCombobox(userProps) {
3129
3076
  state: state,
3130
3077
  props: props
3131
3078
  });
3132
- var getItemNodeFromIndex = useCallback(function (index) {
3133
- return itemRefs.current[elementIds.getItemId(index)];
3134
- }, [elementIds]);
3135
3079
 
3136
3080
  // Effects.
3137
3081
  // Adds an a11y aria live status message if getA11yStatusMessage is passed.
3138
3082
  useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
3139
3083
  // Scroll on highlighted item if change comes from keyboard.
3140
- var shouldScrollRef = useScrollIntoView({
3141
- menuElement: menuRef.current,
3142
- highlightedIndex: highlightedIndex,
3143
- isOpen: isOpen,
3144
- itemRefs: itemRefs,
3145
- scrollIntoView: scrollIntoView,
3146
- getItemNodeFromIndex: getItemNodeFromIndex
3147
- });
3084
+ var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
3148
3085
  useControlPropsValidator({
3149
- props: props,
3150
- state: state
3086
+ state: state,
3087
+ props: props
3151
3088
  });
3152
3089
  // Focus the input on first render if required.
3153
3090
  useEffect(function () {
3154
- var focusOnOpen = getInitialValue$1(props, 'isOpen', defaultStateValues$1);
3091
+ var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
3155
3092
  if (focusOnOpen && inputRef.current) {
3156
3093
  inputRef.current.focus();
3157
3094
  }
@@ -3177,13 +3114,13 @@ function useCombobox(userProps) {
3177
3114
  // Reset itemRefs on close.
3178
3115
  useEffect(function () {
3179
3116
  if (!isOpen) {
3180
- itemRefs.current = {};
3117
+ itemsRef.current = {};
3181
3118
  }
3182
3119
  }, [isOpen]);
3183
3120
  // Reset itemRefs on close.
3184
3121
  useEffect(function () {
3185
3122
  var _inputRef$current;
3186
- if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3123
+ if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
3187
3124
  return;
3188
3125
  }
3189
3126
  if (environment.document.activeElement !== inputRef.current) {
@@ -3273,29 +3210,30 @@ function useCombobox(userProps) {
3273
3210
  htmlFor: elementIds.inputId
3274
3211
  }, labelProps);
3275
3212
  }, [elementIds]);
3276
- var getMenuProps = useCallback(function (_temp, _temp2) {
3213
+ var getMenuProps = useCallback(function (menuProps, otherProps) {
3277
3214
  var _extends2;
3278
- var _ref = _temp === void 0 ? {} : _temp,
3215
+ var _ref = menuProps != null ? menuProps : {},
3279
3216
  onMouseLeave = _ref.onMouseLeave,
3280
3217
  _ref$refKey = _ref.refKey,
3281
3218
  refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3282
3219
  ref = _ref.ref,
3220
+ ariaLabel = _ref['aria-label'],
3283
3221
  rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3284
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3222
+ var _ref2 = otherProps != null ? otherProps : {},
3285
3223
  _ref2$suppressRefErro = _ref2.suppressRefError,
3286
3224
  suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3287
3225
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3288
3226
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3289
3227
  menuRef.current = menuNode;
3290
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3228
+ }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3291
3229
  dispatch({
3292
3230
  type: MenuMouseLeave
3293
3231
  });
3294
3232
  }), _extends2), rest);
3295
3233
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3296
- var getItemProps = useCallback(function (_temp3) {
3234
+ var getItemProps = useCallback(function (itemProps) {
3297
3235
  var _extends3, _ref4;
3298
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3236
+ var _ref3 = itemProps != null ? itemProps : {},
3299
3237
  itemProp = _ref3.item,
3300
3238
  indexProp = _ref3.index,
3301
3239
  _ref3$refKey = _ref3.refKey,
@@ -3323,7 +3261,7 @@ function useCombobox(userProps) {
3323
3261
  if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
3324
3262
  return;
3325
3263
  }
3326
- shouldScrollRef.current = false;
3264
+ preventScroll();
3327
3265
  dispatch({
3328
3266
  type: ItemMouseMove,
3329
3267
  index: index,
@@ -3342,21 +3280,22 @@ function useCombobox(userProps) {
3342
3280
 
3343
3281
  return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3344
3282
  if (itemNode) {
3345
- itemRefs.current[elementIds.getItemId(index)] = itemNode;
3283
+ itemsRef.current[elementIds.getItemId(index)] = itemNode;
3346
3284
  }
3347
3285
  }), _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), {
3348
3286
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3349
3287
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3350
3288
  }, rest);
3351
- }, [dispatch, elementIds, latest, mouseAndTouchTrackers, shouldScrollRef]);
3352
- var getToggleButtonProps = useCallback(function (_temp4) {
3289
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
3290
+ var getToggleButtonProps = useCallback(function (toggleButtonProps) {
3353
3291
  var _extends4;
3354
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3292
+ var _ref5 = toggleButtonProps != null ? toggleButtonProps : {},
3355
3293
  onClick = _ref5.onClick;
3356
3294
  _ref5.onPress;
3357
3295
  var _ref5$refKey = _ref5.refKey,
3358
3296
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3359
3297
  ref = _ref5.ref,
3298
+ disabled = _ref5.disabled,
3360
3299
  rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
3361
3300
  var latestState = latest.current.state;
3362
3301
  var toggleButtonHandleClick = function toggleButtonHandleClick() {
@@ -3366,13 +3305,17 @@ function useCombobox(userProps) {
3366
3305
  };
3367
3306
  return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3368
3307
  toggleButtonRef.current = toggleButtonNode;
3369
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
3308
+ }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, {
3370
3309
  onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3371
- }), rest);
3310
+ }), {
3311
+ disabled: disabled
3312
+ }, rest);
3372
3313
  }, [dispatch, latest, elementIds]);
3373
- var getInputProps = useCallback(function (_temp5, _temp6) {
3314
+ var getInputProps = useCallback(function (inputProps, otherProps) {
3374
3315
  var _extends5;
3375
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3316
+ var _ref6 = inputProps != null ? inputProps : {},
3317
+ ariaLabel = _ref6['aria-label'],
3318
+ disabled = _ref6.disabled,
3376
3319
  onKeyDown = _ref6.onKeyDown,
3377
3320
  onChange = _ref6.onChange,
3378
3321
  onInput = _ref6.onInput,
@@ -3383,15 +3326,16 @@ function useCombobox(userProps) {
3383
3326
  refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3384
3327
  ref = _ref6.ref,
3385
3328
  rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
3386
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3329
+ var _ref7 = otherProps != null ? otherProps : {},
3387
3330
  _ref7$suppressRefErro = _ref7.suppressRefError,
3388
3331
  suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3389
3332
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3390
3333
  var latestState = latest.current.state;
3391
3334
  var inputHandleKeyDown = function inputHandleKeyDown(event) {
3392
3335
  var key = normalizeArrowKey(event);
3393
- if (key && inputKeyDownHandlers[key]) {
3394
- inputKeyDownHandlers[key](event);
3336
+ if (key && key in inputKeyDownHandlers) {
3337
+ var validKey = key;
3338
+ inputKeyDownHandlers[validKey](event);
3395
3339
  }
3396
3340
  };
3397
3341
  var inputHandleChange = function inputHandleChange(event) {
@@ -3419,13 +3363,13 @@ function useCombobox(userProps) {
3419
3363
  /* istanbul ignore next (preact) */
3420
3364
  var onChangeKey = 'onChange';
3421
3365
  var eventHandlers = {};
3422
- if (!rest.disabled) {
3366
+ if (!disabled) {
3423
3367
  var _eventHandlers;
3424
3368
  eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
3425
3369
  }
3426
3370
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3427
3371
  inputRef.current = inputNode;
3428
- }), _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);
3372
+ }), _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);
3429
3373
  }, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
3430
3374
 
3431
3375
  // returns
@@ -3495,31 +3439,6 @@ var defaultStateValues = {
3495
3439
  selectedItems: []
3496
3440
  };
3497
3441
 
3498
- /**
3499
- * Returns the initial value for a state key in the following order:
3500
- * 1. controlled prop, 2. initial prop, 3. default prop, 4. default
3501
- * value from Downshift.
3502
- *
3503
- * @param {Object} props Props passed to the hook.
3504
- * @param {string} propKey Props key to generate the value for.
3505
- * @returns {any} The initial value for that prop.
3506
- */
3507
- function getInitialValue(props, propKey) {
3508
- return getInitialValue$1(props, propKey, defaultStateValues);
3509
- }
3510
-
3511
- /**
3512
- * Returns the default value for a state key in the following order:
3513
- * 1. controlled prop, 2. default prop, 3. default value from Downshift.
3514
- *
3515
- * @param {Object} props Props passed to the hook.
3516
- * @param {string} propKey Props key to generate the value for.
3517
- * @returns {any} The initial value for that prop.
3518
- */
3519
- function getDefaultValue(props, propKey) {
3520
- return getDefaultValue$1(props, propKey, defaultStateValues);
3521
- }
3522
-
3523
3442
  /**
3524
3443
  * Gets the initial state based on the provided props. It uses initial, default
3525
3444
  * and controlled props related to state in order to compute the initial value.
@@ -3528,8 +3447,8 @@ function getDefaultValue(props, propKey) {
3528
3447
  * @returns {Object} The initial state.
3529
3448
  */
3530
3449
  function getInitialState$1(props) {
3531
- var activeIndex = getInitialValue(props, 'activeIndex');
3532
- var selectedItems = getInitialValue(props, 'selectedItems');
3450
+ var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
3451
+ var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
3533
3452
  return {
3534
3453
  activeIndex: activeIndex,
3535
3454
  selectedItems: selectedItems
@@ -3573,9 +3492,9 @@ function isStateEqual$1(prevState, newState) {
3573
3492
  return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
3574
3493
  }
3575
3494
  var propTypes$1 = {
3576
- stateReducer: propTypes$4.stateReducer,
3577
- itemToKey: propTypes$4.itemToKey,
3578
- environment: propTypes$4.environment,
3495
+ stateReducer: dropdownPropTypes.stateReducer,
3496
+ itemToKey: dropdownPropTypes.itemToKey,
3497
+ environment: dropdownPropTypes.environment,
3579
3498
  selectedItems: PropTypes.array,
3580
3499
  initialSelectedItems: PropTypes.array,
3581
3500
  defaultSelectedItems: PropTypes.array,
@@ -3589,9 +3508,9 @@ var propTypes$1 = {
3589
3508
  keyNavigationPrevious: PropTypes.string
3590
3509
  };
3591
3510
  var defaultProps = {
3592
- itemToKey: defaultProps$3.itemToKey,
3593
- stateReducer: defaultProps$3.stateReducer,
3594
- environment: defaultProps$3.environment,
3511
+ itemToKey: dropdownDefaultProps.itemToKey,
3512
+ stateReducer: dropdownDefaultProps.stateReducer,
3513
+ environment: dropdownDefaultProps.environment,
3595
3514
  keyNavigationNext: 'ArrowRight',
3596
3515
  keyNavigationPrevious: 'ArrowLeft'
3597
3516
  };
@@ -3637,10 +3556,11 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
3637
3556
  });
3638
3557
 
3639
3558
  /* eslint-disable complexity */
3640
- function downshiftMultipleSelectionReducer(state, props, action) {
3559
+ function downshiftMultipleSelectionReducer(state, action) {
3641
3560
  var type = action.type,
3642
3561
  index = action.index,
3643
- selectedItem = action.selectedItem;
3562
+ selectedItem = action.selectedItem,
3563
+ props = action.props;
3644
3564
  var activeIndex = state.activeIndex,
3645
3565
  selectedItems = state.selectedItems;
3646
3566
  var changes;
@@ -3737,8 +3657,8 @@ function downshiftMultipleSelectionReducer(state, props, action) {
3737
3657
  }
3738
3658
  case FunctionReset:
3739
3659
  changes = {
3740
- activeIndex: getDefaultValue(props, 'activeIndex'),
3741
- selectedItems: getDefaultValue(props, 'selectedItems')
3660
+ activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
3661
+ selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
3742
3662
  };
3743
3663
  break;
3744
3664
  default:
@@ -3970,7 +3890,7 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3970
3890
  TagRemoveClick: TagRemoveClick
3971
3891
  });
3972
3892
 
3973
- function useTagGroupReducer(state, _props, action) {
3893
+ function useTagGroupReducer(state, action) {
3974
3894
  var type = action.type;
3975
3895
  var changes;
3976
3896
  switch (type) {
@@ -4031,8 +3951,9 @@ function useTagGroupReducer(state, _props, action) {
4031
3951
  return _extends({}, state, changes);
4032
3952
  }
4033
3953
 
4034
- // eslint-disable-next-line @typescript-eslint/dot-notation
4035
- var reactUseId = React['useId'];
3954
+ // https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
3955
+ var SafeReact = _extends({}, React);
3956
+ var reactUseId = SafeReact.useId;
4036
3957
 
4037
3958
  // istanbul ignore next
4038
3959
  var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
@@ -4207,7 +4128,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4207
4128
  'aria-atomic': 'false',
4208
4129
  'aria-relevant': 'additions',
4209
4130
  role: 'listbox',
4210
- onKeyDown: callAllEventHandlers$1(onKeyDown, handleKeyDown)
4131
+ onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
4211
4132
  }, rest);
4212
4133
  return tagGroupProps;
4213
4134
  }, [dispatch, elementIds.tagGroupId]);
@@ -4232,11 +4153,11 @@ var _useTagGroup = function useTagGroup(userProps) {
4232
4153
  var tagId = elementIds.getTagId(index);
4233
4154
  return _extends((_extends2 = {
4234
4155
  'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
4235
- }, _extends2[refKey] = handleRefs$1(ref, function (itemNode) {
4156
+ }, _extends2[refKey] = handleRefs(ref, function (itemNode) {
4236
4157
  if (itemNode) {
4237
4158
  itemRefs.current[tagId] = itemNode;
4238
4159
  }
4239
- }), _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);
4160
+ }), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
4240
4161
  }, [dispatch, elementIds, latest, itemRefs]);
4241
4162
  var getTagRemoveProps = useCallback(function (options) {
4242
4163
  var index = options.index,
@@ -4258,7 +4179,7 @@ var _useTagGroup = function useTagGroup(userProps) {
4258
4179
  id: tagRemoveId,
4259
4180
  tabIndex: -1,
4260
4181
  'aria-labelledby': tagRemoveId + " " + tagId,
4261
- onClick: callAllEventHandlers$1(onClick, handleClick)
4182
+ onClick: callAllEventHandlers(onClick, handleClick)
4262
4183
  }, rest);
4263
4184
  }, [elementIds, dispatch]);
4264
4185