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