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