downshift 7.2.2-alpha.0 → 7.2.2

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.
@@ -59,6 +59,17 @@ function scrollIntoView(node, menuNode) {
59
59
  });
60
60
  }
61
61
 
62
+ /**
63
+ * @param {HTMLElement} parent the parent node
64
+ * @param {HTMLElement} child the child node
65
+ * @param {Window} environment The window context where downshift renders.
66
+ * @return {Boolean} whether the parent is the child or the child is in the parent
67
+ */
68
+ function isOrContainsNode(parent, child, environment) {
69
+ var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
70
+ return result;
71
+ }
72
+
62
73
  /**
63
74
  * Simple debounce implementation. Will call the given
64
75
  * function once after the time given has passed since
@@ -351,6 +362,25 @@ function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFr
351
362
  return -1;
352
363
  }
353
364
 
365
+ /**
366
+ * Checks if event target is within the downshift elements.
367
+ *
368
+ * @param {EventTarget} target Target to check.
369
+ * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
370
+ * @param {Window} environment The window context where downshift renders.
371
+ * @param {boolean} checkActiveElement Whether to also check activeElement.
372
+ *
373
+ * @returns {boolean} Whether or not the target is within downshift elements.
374
+ */
375
+ function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
376
+ if (checkActiveElement === void 0) {
377
+ checkActiveElement = true;
378
+ }
379
+ return downshiftElements.some(function (contextNode) {
380
+ return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
381
+ });
382
+ }
383
+
354
384
  // eslint-disable-next-line import/no-mutable-exports
355
385
  var validateControlledUnchanged = noop;
356
386
  /* istanbul ignore next */
@@ -480,9 +510,18 @@ var Downshift = /*#__PURE__*/function () {
480
510
  };
481
511
  _this.input = null;
482
512
  _this.items = [];
513
+ // itemCount can be changed asynchronously
514
+ // from within downshift (so it can't come from a prop)
515
+ // this is why we store it as an instance and use
516
+ // getItemCount rather than just use items.length
517
+ // (to support windowing + async)
483
518
  _this.itemCount = null;
484
519
  _this.previousResultCount = 0;
485
520
  _this.timeoutIds = [];
521
+ /**
522
+ * @param {Function} fn the function to call after the time
523
+ * @param {Number} time the time to wait
524
+ */
486
525
  _this.internalSetTimeout = function (fn, time) {
487
526
  var id = setTimeout(function () {
488
527
  _this.timeoutIds = _this.timeoutIds.filter(function (i) {
@@ -537,6 +576,14 @@ var Downshift = /*#__PURE__*/function () {
537
576
  _this.selectHighlightedItem = function (otherStateToSet, cb) {
538
577
  return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
539
578
  };
579
+ // any piece of our state can live in two places:
580
+ // 1. Uncontrolled: it's internal (this.state)
581
+ // We will call this.setState to update that state
582
+ // 2. Controlled: it's external (this.props)
583
+ // We will call this.props.onStateChange to update that state
584
+ //
585
+ // In addition, we'll call this.props.onChange if the
586
+ // selectedItem is changed.
540
587
  _this.internalSetState = function (stateToSet, cb) {
541
588
  var isItemSelected, onChangeArg;
542
589
  var onStateChangeArg = {};
@@ -619,6 +666,7 @@ var Downshift = /*#__PURE__*/function () {
619
666
  _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
620
667
  });
621
668
  };
669
+ //////////////////////////// ROOT
622
670
  _this.rootRef = function (node) {
623
671
  return _this._rootNode = node;
624
672
  };
@@ -641,6 +689,7 @@ var Downshift = /*#__PURE__*/function () {
641
689
  isOpen = _this$getState.isOpen;
642
690
  return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
643
691
  };
692
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\ ROOT
644
693
  _this.keyDownHandlers = {
645
694
  ArrowDown: function ArrowDown(event) {
646
695
  var _this2 = this;
@@ -725,6 +774,7 @@ var Downshift = /*#__PURE__*/function () {
725
774
  }));
726
775
  }
727
776
  };
777
+ //////////////////////////// BUTTON
728
778
  _this.buttonKeyDownHandlers = _extends__default["default"]({}, _this.keyDownHandlers, {
729
779
  ' ': function _(event) {
730
780
  event.preventDefault();
@@ -840,12 +890,16 @@ var Downshift = /*#__PURE__*/function () {
840
890
  }
841
891
  });
842
892
  };
893
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ BUTTON
894
+ /////////////////////////////// LABEL
843
895
  _this.getLabelProps = function (props) {
844
896
  return _extends__default["default"]({
845
897
  htmlFor: _this.inputId,
846
898
  id: _this.labelId
847
899
  }, props);
848
900
  };
901
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ LABEL
902
+ /////////////////////////////// INPUT
849
903
  _this.getInputProps = function (_temp4) {
850
904
  var _ref4 = _temp4 === void 0 ? {} : _temp4,
851
905
  onKeyDown = _ref4.onKeyDown,
@@ -921,6 +975,8 @@ var Downshift = /*#__PURE__*/function () {
921
975
  }
922
976
  });
923
977
  };
978
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ INPUT
979
+ /////////////////////////////// MENU
924
980
  _this.menuRef = function (node) {
925
981
  _this._menuNode = node;
926
982
  };
@@ -939,6 +995,8 @@ var Downshift = /*#__PURE__*/function () {
939
995
  _this.getMenuProps.suppressRefError = suppressRefError;
940
996
  return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
941
997
  };
998
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ MENU
999
+ /////////////////////////////// ITEM
942
1000
  _this.getItemProps = function (_temp7) {
943
1001
  var _enabledEventHandlers;
944
1002
  var _ref7 = _temp7 === void 0 ? {} : _temp7,
@@ -1002,6 +1060,7 @@ var Downshift = /*#__PURE__*/function () {
1002
1060
  'aria-selected': _this.getState().highlightedIndex === index
1003
1061
  }, eventHandlers, rest);
1004
1062
  };
1063
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ITEM
1005
1064
  _this.clearItems = function () {
1006
1065
  _this.items = [];
1007
1066
  };
@@ -1204,10 +1263,7 @@ var Downshift = /*#__PURE__*/function () {
1204
1263
  isOpen: isOpen,
1205
1264
  selectedItem: selectedItem
1206
1265
  };
1207
- }
1208
-
1209
- //////////////////////////// ROOT
1210
- ;
1266
+ };
1211
1267
  _proto.componentDidMount = function componentDidMount() {
1212
1268
  var _this7 = this;
1213
1269
  /* istanbul ignore if (react-native) */
@@ -1497,6 +1553,9 @@ function getItemIndex(index, item, items) {
1497
1553
  function itemToString(item) {
1498
1554
  return item ? String(item) : '';
1499
1555
  }
1556
+ function isAcceptedCharacterKey(key) {
1557
+ return /^\S{1}$/.test(key);
1558
+ }
1500
1559
  function capitalizeString(string) {
1501
1560
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1502
1561
  }
@@ -1652,10 +1711,50 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1652
1711
  isTouchMove: false
1653
1712
  });
1654
1713
  react.useEffect(function () {
1655
- /* istanbul ignore if (react-native) */
1656
- {
1714
+ if ((environment == null ? void 0 : environment.addEventListener) == null) {
1657
1715
  return;
1658
1716
  }
1717
+
1718
+ // The same strategy for checking if a click occurred inside or outside downshift
1719
+ // as in downshift.js.
1720
+ var onMouseDown = function onMouseDown() {
1721
+ mouseAndTouchTrackersRef.current.isMouseDown = true;
1722
+ };
1723
+ var onMouseUp = function onMouseUp(event) {
1724
+ mouseAndTouchTrackersRef.current.isMouseDown = false;
1725
+ if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1726
+ return ref.current;
1727
+ }), environment)) {
1728
+ handleBlur();
1729
+ }
1730
+ };
1731
+ var onTouchStart = function onTouchStart() {
1732
+ mouseAndTouchTrackersRef.current.isTouchMove = false;
1733
+ };
1734
+ var onTouchMove = function onTouchMove() {
1735
+ mouseAndTouchTrackersRef.current.isTouchMove = true;
1736
+ };
1737
+ var onTouchEnd = function onTouchEnd(event) {
1738
+ if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1739
+ return ref.current;
1740
+ }), environment, false)) {
1741
+ handleBlur();
1742
+ }
1743
+ };
1744
+ environment.addEventListener('mousedown', onMouseDown);
1745
+ environment.addEventListener('mouseup', onMouseUp);
1746
+ environment.addEventListener('touchstart', onTouchStart);
1747
+ environment.addEventListener('touchmove', onTouchMove);
1748
+ environment.addEventListener('touchend', onTouchEnd);
1749
+
1750
+ // eslint-disable-next-line consistent-return
1751
+ return function cleanup() {
1752
+ environment.removeEventListener('mousedown', onMouseDown);
1753
+ environment.removeEventListener('mouseup', onMouseUp);
1754
+ environment.removeEventListener('touchstart', onTouchStart);
1755
+ environment.removeEventListener('touchmove', onTouchMove);
1756
+ environment.removeEventListener('touchend', onTouchEnd);
1757
+ };
1659
1758
  // eslint-disable-next-line react-hooks/exhaustive-deps
1660
1759
  }, [isOpen, environment]);
1661
1760
  return mouseAndTouchTrackersRef;
@@ -2084,8 +2183,8 @@ function downshiftSelectReducer(state, action) {
2084
2183
  /* eslint-enable complexity */
2085
2184
 
2086
2185
  var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
2087
- _excluded2$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
2088
- _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "onPress", "refKey", "ref", "disabled"];
2186
+ _excluded2$2 = ["onBlur", "onClick", "onKeyDown", "refKey", "ref"],
2187
+ _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref", "disabled"];
2089
2188
  useSelect.stateChangeTypes = stateChangeTypes$2;
2090
2189
  function useSelect(userProps) {
2091
2190
  if (userProps === void 0) {
@@ -2194,7 +2293,11 @@ function useSelect(userProps) {
2194
2293
  previousResultCountRef.current = items.length;
2195
2294
  });
2196
2295
  // Add mouse/touch events to document.
2197
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment);
2296
+ var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
2297
+ dispatch({
2298
+ type: ToggleButtonBlur
2299
+ });
2300
+ });
2198
2301
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2199
2302
  // Make initial ref false.
2200
2303
  react.useEffect(function () {
@@ -2370,11 +2473,10 @@ function useSelect(userProps) {
2370
2473
  var getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
2371
2474
  var _extends3;
2372
2475
  var _ref3 = _temp3 === void 0 ? {} : _temp3,
2373
- onBlur = _ref3.onBlur;
2374
- _ref3.onClick;
2375
- var onPress = _ref3.onPress;
2376
- _ref3.onKeyDown;
2377
- var _ref3$refKey = _ref3.refKey,
2476
+ onBlur = _ref3.onBlur,
2477
+ onClick = _ref3.onClick,
2478
+ onKeyDown = _ref3.onKeyDown,
2479
+ _ref3$refKey = _ref3.refKey,
2378
2480
  refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
2379
2481
  ref = _ref3.ref,
2380
2482
  rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded2$2);
@@ -2394,14 +2496,24 @@ function useSelect(userProps) {
2394
2496
  });
2395
2497
  }
2396
2498
  };
2499
+ var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2500
+ var key = normalizeArrowKey(event);
2501
+ if (key && toggleButtonKeyDownHandlers[key]) {
2502
+ toggleButtonKeyDownHandlers[key](event);
2503
+ } else if (isAcceptedCharacterKey(key)) {
2504
+ dispatch({
2505
+ type: ToggleButtonKeyDownCharacter,
2506
+ key: key,
2507
+ getItemNodeFromIndex: getItemNodeFromIndex
2508
+ });
2509
+ }
2510
+ };
2397
2511
  var toggleProps = _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2398
2512
  toggleButtonRef.current = toggleButtonNode;
2399
2513
  }), _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'] = "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3), rest);
2400
2514
  if (!rest.disabled) {
2401
- /* istanbul ignore if (react-native) */
2402
- {
2403
- toggleProps.onPress = callAllEventHandlers(onPress, toggleButtonHandleClick);
2404
- }
2515
+ toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
2516
+ toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
2405
2517
  }
2406
2518
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2407
2519
  return toggleProps;
@@ -2411,9 +2523,8 @@ function useSelect(userProps) {
2411
2523
  var _ref5 = _temp5 === void 0 ? {} : _temp5,
2412
2524
  itemProp = _ref5.item,
2413
2525
  indexProp = _ref5.index,
2414
- onMouseMove = _ref5.onMouseMove;
2415
- _ref5.onClick;
2416
- var onPress = _ref5.onPress,
2526
+ onMouseMove = _ref5.onMouseMove,
2527
+ onClick = _ref5.onClick,
2417
2528
  _ref5$refKey = _ref5.refKey,
2418
2529
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
2419
2530
  ref = _ref5.ref,
@@ -2456,10 +2567,7 @@ function useSelect(userProps) {
2456
2567
  }
2457
2568
  }), _extends4), rest);
2458
2569
  if (!disabled) {
2459
- /* istanbul ignore next (react-native) */
2460
- {
2461
- itemProps.onPress = callAllEventHandlers(onPress, itemHandleClick);
2462
- }
2570
+ itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2463
2571
  }
2464
2572
  itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
2465
2573
  return itemProps;
@@ -2855,7 +2963,12 @@ function useCombobox(userProps) {
2855
2963
  previousResultCountRef.current = items.length;
2856
2964
  });
2857
2965
  // Add mouse/touch events to document.
2858
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment);
2966
+ var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, function () {
2967
+ dispatch({
2968
+ type: InputBlur,
2969
+ selectItem: false
2970
+ });
2971
+ });
2859
2972
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
2860
2973
  // Make initial ref false.
2861
2974
  react.useEffect(function () {
@@ -2866,13 +2979,14 @@ function useCombobox(userProps) {
2866
2979
  }, []);
2867
2980
  // Reset itemRefs on close.
2868
2981
  react.useEffect(function () {
2982
+ var _environment$document;
2869
2983
  if (!isOpen) {
2870
2984
  itemRefs.current = {};
2871
- } else if (document.activeElement !== inputRef.current) {
2985
+ } else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
2872
2986
  var _inputRef$current;
2873
2987
  inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
2874
2988
  }
2875
- }, [isOpen]);
2989
+ }, [isOpen, environment]);
2876
2990
 
2877
2991
  /* Event handler functions */
2878
2992
  var inputKeyDownHandlers = react.useMemo(function () {
@@ -1803,9 +1803,18 @@
1803
1803
  };
1804
1804
  _this.input = null;
1805
1805
  _this.items = [];
1806
+ // itemCount can be changed asynchronously
1807
+ // from within downshift (so it can't come from a prop)
1808
+ // this is why we store it as an instance and use
1809
+ // getItemCount rather than just use items.length
1810
+ // (to support windowing + async)
1806
1811
  _this.itemCount = null;
1807
1812
  _this.previousResultCount = 0;
1808
1813
  _this.timeoutIds = [];
1814
+ /**
1815
+ * @param {Function} fn the function to call after the time
1816
+ * @param {Number} time the time to wait
1817
+ */
1809
1818
  _this.internalSetTimeout = function (fn, time) {
1810
1819
  var id = setTimeout(function () {
1811
1820
  _this.timeoutIds = _this.timeoutIds.filter(function (i) {
@@ -1860,6 +1869,14 @@
1860
1869
  _this.selectHighlightedItem = function (otherStateToSet, cb) {
1861
1870
  return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
1862
1871
  };
1872
+ // any piece of our state can live in two places:
1873
+ // 1. Uncontrolled: it's internal (this.state)
1874
+ // We will call this.setState to update that state
1875
+ // 2. Controlled: it's external (this.props)
1876
+ // We will call this.props.onStateChange to update that state
1877
+ //
1878
+ // In addition, we'll call this.props.onChange if the
1879
+ // selectedItem is changed.
1863
1880
  _this.internalSetState = function (stateToSet, cb) {
1864
1881
  var isItemSelected, onChangeArg;
1865
1882
  var onStateChangeArg = {};
@@ -1942,6 +1959,7 @@
1942
1959
  _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
1943
1960
  });
1944
1961
  };
1962
+ //////////////////////////// ROOT
1945
1963
  _this.rootRef = function (node) {
1946
1964
  return _this._rootNode = node;
1947
1965
  };
@@ -1964,6 +1982,7 @@
1964
1982
  isOpen = _this$getState.isOpen;
1965
1983
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
1966
1984
  };
1985
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\ ROOT
1967
1986
  _this.keyDownHandlers = {
1968
1987
  ArrowDown: function ArrowDown(event) {
1969
1988
  var _this2 = this;
@@ -2048,6 +2067,7 @@
2048
2067
  }));
2049
2068
  }
2050
2069
  };
2070
+ //////////////////////////// BUTTON
2051
2071
  _this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
2052
2072
  ' ': function _(event) {
2053
2073
  event.preventDefault();
@@ -2167,12 +2187,16 @@
2167
2187
  }
2168
2188
  });
2169
2189
  };
2190
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ BUTTON
2191
+ /////////////////////////////// LABEL
2170
2192
  _this.getLabelProps = function (props) {
2171
2193
  return _extends({
2172
2194
  htmlFor: _this.inputId,
2173
2195
  id: _this.labelId
2174
2196
  }, props);
2175
2197
  };
2198
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ LABEL
2199
+ /////////////////////////////// INPUT
2176
2200
  _this.getInputProps = function (_temp4) {
2177
2201
  var _ref4 = _temp4 === void 0 ? {} : _temp4,
2178
2202
  onKeyDown = _ref4.onKeyDown,
@@ -2233,6 +2257,8 @@
2233
2257
  }
2234
2258
  });
2235
2259
  };
2260
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ INPUT
2261
+ /////////////////////////////// MENU
2236
2262
  _this.menuRef = function (node) {
2237
2263
  _this._menuNode = node;
2238
2264
  };
@@ -2251,6 +2277,8 @@
2251
2277
  _this.getMenuProps.suppressRefError = suppressRefError;
2252
2278
  return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
2253
2279
  };
2280
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ MENU
2281
+ /////////////////////////////// ITEM
2254
2282
  _this.getItemProps = function (_temp7) {
2255
2283
  var _enabledEventHandlers;
2256
2284
  var _ref7 = _temp7 === void 0 ? {} : _temp7,
@@ -2314,6 +2342,7 @@
2314
2342
  'aria-selected': _this.getState().highlightedIndex === index
2315
2343
  }, eventHandlers, rest);
2316
2344
  };
2345
+ //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ITEM
2317
2346
  _this.clearItems = function () {
2318
2347
  _this.items = [];
2319
2348
  };
@@ -2521,10 +2550,7 @@
2521
2550
  isOpen: isOpen,
2522
2551
  selectedItem: selectedItem
2523
2552
  };
2524
- }
2525
-
2526
- //////////////////////////// ROOT
2527
- ;
2553
+ };
2528
2554
  _proto.componentDidMount = function componentDidMount() {
2529
2555
  var _this7 = this;
2530
2556
  /* istanbul ignore if (react-native) */
@@ -3033,8 +3059,11 @@
3033
3059
  isTouchMove: false
3034
3060
  });
3035
3061
  react.useEffect(function () {
3062
+ if ((environment == null ? void 0 : environment.addEventListener) == null) {
3063
+ return;
3064
+ }
3036
3065
 
3037
- // The same strategy for checking if a click occurred inside or outside downsift
3066
+ // The same strategy for checking if a click occurred inside or outside downshift
3038
3067
  // as in downshift.js.
3039
3068
  var onMouseDown = function onMouseDown() {
3040
3069
  mouseAndTouchTrackersRef.current.isMouseDown = true;
@@ -3528,8 +3557,8 @@
3528
3557
  /* eslint-enable complexity */
3529
3558
 
3530
3559
  var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
3531
- _excluded2$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
3532
- _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "onPress", "refKey", "ref", "disabled"];
3560
+ _excluded2$2 = ["onBlur", "onClick", "onKeyDown", "refKey", "ref"],
3561
+ _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref", "disabled"];
3533
3562
  useSelect.stateChangeTypes = stateChangeTypes$2;
3534
3563
  function useSelect(userProps) {
3535
3564
  if (userProps === void 0) {
@@ -3819,9 +3848,8 @@
3819
3848
  var _extends3;
3820
3849
  var _ref3 = _temp3 === void 0 ? {} : _temp3,
3821
3850
  onBlur = _ref3.onBlur,
3822
- onClick = _ref3.onClick;
3823
- _ref3.onPress;
3824
- var onKeyDown = _ref3.onKeyDown,
3851
+ onClick = _ref3.onClick,
3852
+ onKeyDown = _ref3.onKeyDown,
3825
3853
  _ref3$refKey = _ref3.refKey,
3826
3854
  refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
3827
3855
  ref = _ref3.ref,
@@ -3858,11 +3886,8 @@
3858
3886
  toggleButtonRef.current = toggleButtonNode;
3859
3887
  }), _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'] = "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3), rest);
3860
3888
  if (!rest.disabled) {
3861
- /* istanbul ignore if (react-native) */
3862
- {
3863
- toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
3864
- toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
3865
- }
3889
+ toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
3890
+ toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
3866
3891
  }
3867
3892
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
3868
3893
  return toggleProps;
@@ -3873,9 +3898,8 @@
3873
3898
  itemProp = _ref5.item,
3874
3899
  indexProp = _ref5.index,
3875
3900
  onMouseMove = _ref5.onMouseMove,
3876
- onClick = _ref5.onClick;
3877
- _ref5.onPress;
3878
- var _ref5$refKey = _ref5.refKey,
3901
+ onClick = _ref5.onClick,
3902
+ _ref5$refKey = _ref5.refKey,
3879
3903
  refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3880
3904
  ref = _ref5.ref,
3881
3905
  disabled = _ref5.disabled,
@@ -3917,10 +3941,7 @@
3917
3941
  }
3918
3942
  }), _extends4), rest);
3919
3943
  if (!disabled) {
3920
- /* istanbul ignore next (react-native) */
3921
- {
3922
- itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
3923
- }
3944
+ itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
3924
3945
  }
3925
3946
  itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
3926
3947
  return itemProps;
@@ -4332,13 +4353,14 @@
4332
4353
  }, []);
4333
4354
  // Reset itemRefs on close.
4334
4355
  react.useEffect(function () {
4356
+ var _environment$document;
4335
4357
  if (!isOpen) {
4336
4358
  itemRefs.current = {};
4337
- } else if (document.activeElement !== inputRef.current) {
4359
+ } else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
4338
4360
  var _inputRef$current;
4339
4361
  inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
4340
4362
  }
4341
- }, [isOpen]);
4363
+ }, [isOpen, environment]);
4342
4364
 
4343
4365
  /* Event handler functions */
4344
4366
  var inputKeyDownHandlers = react.useMemo(function () {