downshift 8.3.1 → 8.3.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.
@@ -244,6 +244,9 @@ function pickState(state) {
244
244
  * @returns {Object} The merged controlled state.
245
245
  */
246
246
  function getState(state, props) {
247
+ if (!state || !props) {
248
+ return state;
249
+ }
247
250
  return Object.keys(state).reduce(function (prevState, key) {
248
251
  prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
249
252
  return prevState;
@@ -1444,7 +1447,7 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
1444
1447
  }
1445
1448
  }
1446
1449
 
1447
- var _excluded$3 = ["isInitialMount", "highlightedIndex", "items", "environment"];
1450
+ var _excluded$3 = ["highlightedIndex", "items", "environment"];
1448
1451
  var dropdownDefaultStateValues = {
1449
1452
  highlightedIndex: -1,
1450
1453
  isOpen: false,
@@ -1619,9 +1622,10 @@ function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
1619
1622
  }, [propsRef]);
1620
1623
  var action = actionRef.current;
1621
1624
  React.useEffect(function () {
1622
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevStateRef.current, state);
1625
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
1626
+ var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
1623
1627
  if (shouldCallOnChangeProps) {
1624
- callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
1628
+ callOnChangeProps(action, prevState, state);
1625
1629
  }
1626
1630
  prevStateRef.current = state;
1627
1631
  }, [state, action, isStateEqual]);
@@ -1726,7 +1730,8 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1726
1730
  function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
1727
1731
  var mouseAndTouchTrackersRef = React.useRef({
1728
1732
  isMouseDown: false,
1729
- isTouchMove: false
1733
+ isTouchMove: false,
1734
+ isTouchEnd: false
1730
1735
  });
1731
1736
  React.useEffect(function () {
1732
1737
  {
@@ -1790,11 +1795,11 @@ if (process.env.NODE_ENV !== 'production') {
1790
1795
  };
1791
1796
  }
1792
1797
  function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref3) {
1793
- var isInitialMount = _ref3.isInitialMount,
1794
- highlightedIndex = _ref3.highlightedIndex,
1798
+ var highlightedIndex = _ref3.highlightedIndex,
1795
1799
  items = _ref3.items,
1796
1800
  environment = _ref3.environment,
1797
1801
  rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded$3);
1802
+ var isInitialMount = useIsInitialMount();
1798
1803
  // Sets a11y status message on changes in state.
1799
1804
  React.useEffect(function () {
1800
1805
  if (isInitialMount || true || !(environment != null && environment.document)) {
@@ -1839,11 +1844,11 @@ var useControlPropsValidator = noop;
1839
1844
  /* istanbul ignore next */
1840
1845
  if (process.env.NODE_ENV !== 'production') {
1841
1846
  useControlPropsValidator = function useControlPropsValidator(_ref5) {
1842
- var isInitialMount = _ref5.isInitialMount,
1843
- props = _ref5.props,
1847
+ var props = _ref5.props,
1844
1848
  state = _ref5.state;
1845
1849
  // used for checking when props are moving from controlled to uncontrolled.
1846
1850
  var prevPropsRef = React.useRef(props);
1851
+ var isInitialMount = useIsInitialMount();
1847
1852
  React.useEffect(function () {
1848
1853
  if (isInitialMount) {
1849
1854
  return;
@@ -1892,6 +1897,20 @@ function isDropdownsStateEqual(prevState, newState) {
1892
1897
  return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
1893
1898
  }
1894
1899
 
1900
+ /**
1901
+ * Tracks if it's the first render.
1902
+ */
1903
+ function useIsInitialMount() {
1904
+ var isInitialMountRef = React__default["default"].useRef(true);
1905
+ React__default["default"].useEffect(function () {
1906
+ isInitialMountRef.current = false;
1907
+ return function () {
1908
+ isInitialMountRef.current = true;
1909
+ };
1910
+ }, []);
1911
+ return isInitialMountRef.current;
1912
+ }
1913
+
1895
1914
  // Shared between all exports.
1896
1915
  var commonPropTypes = {
1897
1916
  environment: PropTypes__default["default"].shape({
@@ -2232,7 +2251,7 @@ function useSelect(userProps) {
2232
2251
  var elementIds = useElementIds(props);
2233
2252
  // used to keep track of how many items we had on previous cycle.
2234
2253
  var previousResultCountRef = React.useRef();
2235
- var isInitialMountRef = React.useRef(true);
2254
+ var isInitialMount = useIsInitialMount();
2236
2255
  // utility callback to get item element.
2237
2256
  var latest = useLatestRef({
2238
2257
  state: state,
@@ -2247,7 +2266,6 @@ function useSelect(userProps) {
2247
2266
  // Effects.
2248
2267
  // Sets a11y status message on changes in state.
2249
2268
  useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
2250
- isInitialMount: isInitialMountRef.current,
2251
2269
  previousResultCount: previousResultCountRef.current,
2252
2270
  items: items,
2253
2271
  environment: environment,
@@ -2255,7 +2273,6 @@ function useSelect(userProps) {
2255
2273
  }, state));
2256
2274
  // Sets a11y status message on changes in selectedItem.
2257
2275
  useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
2258
- isInitialMount: isInitialMountRef.current,
2259
2276
  previousResultCount: previousResultCountRef.current,
2260
2277
  items: items,
2261
2278
  environment: environment,
@@ -2295,12 +2312,11 @@ function useSelect(userProps) {
2295
2312
  clearTimeoutRef.current(dispatch);
2296
2313
  }, [dispatch, inputValue]);
2297
2314
  useControlPropsValidator({
2298
- isInitialMount: isInitialMountRef.current,
2299
2315
  props: props,
2300
2316
  state: state
2301
2317
  });
2302
2318
  React.useEffect(function () {
2303
- if (isInitialMountRef.current) {
2319
+ if (isInitialMount) {
2304
2320
  return;
2305
2321
  }
2306
2322
  previousResultCountRef.current = items.length;
@@ -2316,13 +2332,6 @@ function useSelect(userProps) {
2316
2332
  // Add mouse/touch events to document.
2317
2333
  var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment);
2318
2334
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2319
- // Make initial ref false.
2320
- React.useEffect(function () {
2321
- isInitialMountRef.current = false;
2322
- return function () {
2323
- isInitialMountRef.current = true;
2324
- };
2325
- }, []);
2326
2335
  // Reset itemRefs on close.
2327
2336
  React.useEffect(function () {
2328
2337
  if (!isOpen) {
@@ -2550,7 +2559,7 @@ function useSelect(userProps) {
2550
2559
  index = _getItemAndIndex[1];
2551
2560
  var disabled = latestProps.isItemDisabled(item, index);
2552
2561
  var itemHandleMouseMove = function itemHandleMouseMove() {
2553
- if (index === latestState.highlightedIndex) {
2562
+ if (mouseAndTouchTrackersRef.current.isTouchEnd || index === latestState.highlightedIndex) {
2554
2563
  return;
2555
2564
  }
2556
2565
  shouldScrollRef.current = false;
@@ -2584,7 +2593,7 @@ function useSelect(userProps) {
2584
2593
  itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
2585
2594
  itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
2586
2595
  return itemProps;
2587
- }, [latest, elementIds, shouldScrollRef, dispatch]);
2596
+ }, [latest, elementIds, mouseAndTouchTrackersRef, shouldScrollRef, dispatch]);
2588
2597
  return {
2589
2598
  // prop getters.
2590
2599
  getToggleButtonProps: getToggleButtonProps,
@@ -2699,13 +2708,14 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
2699
2708
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
2700
2709
  state = _useEnhancedReducer[0],
2701
2710
  dispatch = _useEnhancedReducer[1];
2702
-
2703
- // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
2711
+ var isInitialMount = useIsInitialMount();
2704
2712
  React.useEffect(function () {
2705
2713
  if (!isControlledProp(props, 'selectedItem')) {
2706
2714
  return;
2707
2715
  }
2708
- if (props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem)) {
2716
+ if (!isInitialMount &&
2717
+ // on first mount we already have the proper inputValue for a initial selected item.
2718
+ props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem)) {
2709
2719
  dispatch({
2710
2720
  type: ControlledPropUpdatedSelectedItem,
2711
2721
  inputValue: props.itemToString(props.selectedItem)
@@ -2883,7 +2893,8 @@ function useCombobox(userProps) {
2883
2893
  var itemRefs = React.useRef({});
2884
2894
  var inputRef = React.useRef(null);
2885
2895
  var toggleButtonRef = React.useRef(null);
2886
- var isInitialMountRef = React.useRef(true);
2896
+ var isInitialMount = useIsInitialMount();
2897
+
2887
2898
  // prevent id re-generation between renders.
2888
2899
  var elementIds = useElementIds(props);
2889
2900
  // used to keep track of how many items we had on previous cycle.
@@ -2900,7 +2911,6 @@ function useCombobox(userProps) {
2900
2911
  // Effects.
2901
2912
  // Sets a11y status message on changes in state.
2902
2913
  useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
2903
- isInitialMount: isInitialMountRef.current,
2904
2914
  previousResultCount: previousResultCountRef.current,
2905
2915
  items: items,
2906
2916
  environment: environment,
@@ -2908,7 +2918,6 @@ function useCombobox(userProps) {
2908
2918
  }, state));
2909
2919
  // Sets a11y status message on changes in selectedItem.
2910
2920
  useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
2911
- isInitialMount: isInitialMountRef.current,
2912
2921
  previousResultCount: previousResultCountRef.current,
2913
2922
  items: items,
2914
2923
  environment: environment,
@@ -2924,7 +2933,6 @@ function useCombobox(userProps) {
2924
2933
  getItemNodeFromIndex: getItemNodeFromIndex
2925
2934
  });
2926
2935
  useControlPropsValidator({
2927
- isInitialMount: isInitialMountRef.current,
2928
2936
  props: props,
2929
2937
  state: state
2930
2938
  });
@@ -2937,21 +2945,13 @@ function useCombobox(userProps) {
2937
2945
  // eslint-disable-next-line react-hooks/exhaustive-deps
2938
2946
  }, []);
2939
2947
  React.useEffect(function () {
2940
- if (isInitialMountRef.current) {
2941
- return;
2948
+ if (!isInitialMount) {
2949
+ previousResultCountRef.current = items.length;
2942
2950
  }
2943
- previousResultCountRef.current = items.length;
2944
2951
  });
2945
2952
  // Add mouse/touch events to document.
2946
2953
  var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment);
2947
2954
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
2948
- // Make initial ref false.
2949
- React.useEffect(function () {
2950
- isInitialMountRef.current = false;
2951
- return function () {
2952
- isInitialMountRef.current = true;
2953
- };
2954
- }, []);
2955
2955
  // Reset itemRefs on close.
2956
2956
  React.useEffect(function () {
2957
2957
  if (!isOpen) {
@@ -3098,7 +3098,7 @@ function useCombobox(userProps) {
3098
3098
  var onSelectKey = /* istanbul ignore next (react-native) */'onPress' ;
3099
3099
  var customClickHandler = /* istanbul ignore next (react-native) */onPress ;
3100
3100
  var itemHandleMouseMove = function itemHandleMouseMove() {
3101
- if (index === latestState.highlightedIndex) {
3101
+ if (mouseAndTouchTrackersRef.current.isTouchEnd || index === latestState.highlightedIndex) {
3102
3102
  return;
3103
3103
  }
3104
3104
  shouldScrollRef.current = false;
@@ -3126,7 +3126,7 @@ function useCombobox(userProps) {
3126
3126
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3127
3127
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3128
3128
  }, rest);
3129
- }, [dispatch, latest, shouldScrollRef, elementIds]);
3129
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackersRef, shouldScrollRef]);
3130
3130
  var getToggleButtonProps = React.useCallback(function (_temp4) {
3131
3131
  var _extends4;
3132
3132
  var _ref5 = _temp4 === void 0 ? {} : _temp4;
@@ -3570,7 +3570,7 @@ function useMultipleSelection(userProps) {
3570
3570
  selectedItems = state.selectedItems;
3571
3571
 
3572
3572
  // Refs.
3573
- var isInitialMountRef = React.useRef(true);
3573
+ var isInitialMount = useIsInitialMount();
3574
3574
  var dropdownRef = React.useRef(null);
3575
3575
  var previousSelectedItemsRef = React.useRef(selectedItems);
3576
3576
  var selectedItemRefs = React.useRef();
@@ -3583,7 +3583,7 @@ function useMultipleSelection(userProps) {
3583
3583
  // Effects.
3584
3584
  /* Sets a11y status message on changes in selectedItem. */
3585
3585
  React.useEffect(function () {
3586
- if (isInitialMountRef.current || true || !(environment != null && environment.document)) {
3586
+ if (isInitialMount || true || !(environment != null && environment.document)) {
3587
3587
  return;
3588
3588
  }
3589
3589
  if (selectedItems.length < previousSelectedItemsRef.current.length) {
@@ -3604,7 +3604,7 @@ function useMultipleSelection(userProps) {
3604
3604
  }, [selectedItems.length]);
3605
3605
  // Sets focus on active item.
3606
3606
  React.useEffect(function () {
3607
- if (isInitialMountRef.current) {
3607
+ if (isInitialMount) {
3608
3608
  return;
3609
3609
  }
3610
3610
  if (activeIndex === -1 && dropdownRef.current) {
@@ -3612,20 +3612,12 @@ function useMultipleSelection(userProps) {
3612
3612
  } else if (selectedItemRefs.current[activeIndex]) {
3613
3613
  selectedItemRefs.current[activeIndex].focus();
3614
3614
  }
3615
- }, [activeIndex]);
3615
+ }, [activeIndex, isInitialMount]);
3616
3616
  useControlPropsValidator({
3617
- isInitialMount: isInitialMountRef.current,
3618
3617
  props: props,
3619
3618
  state: state
3620
3619
  });
3621
3620
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
3622
- // Make initial ref false.
3623
- React.useEffect(function () {
3624
- isInitialMountRef.current = false;
3625
- return function () {
3626
- isInitialMountRef.current = true;
3627
- };
3628
- }, []);
3629
3621
 
3630
3622
  // Event handler functions.
3631
3623
  var selectedItemKeyDownHandlers = React.useMemo(function () {
@@ -255,6 +255,9 @@ function pickState(state) {
255
255
  * @returns {Object} The merged controlled state.
256
256
  */
257
257
  function getState(state, props) {
258
+ if (!state || !props) {
259
+ return state;
260
+ }
258
261
  return Object.keys(state).reduce(function (prevState, key) {
259
262
  prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
260
263
  return prevState;
@@ -1543,7 +1546,7 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
1543
1546
  }
1544
1547
  }
1545
1548
 
1546
- var _excluded$3 = ["isInitialMount", "highlightedIndex", "items", "environment"];
1549
+ var _excluded$3 = ["highlightedIndex", "items", "environment"];
1547
1550
  var dropdownDefaultStateValues = {
1548
1551
  highlightedIndex: -1,
1549
1552
  isOpen: false,
@@ -1718,9 +1721,10 @@ function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
1718
1721
  }, [propsRef]);
1719
1722
  var action = actionRef.current;
1720
1723
  React.useEffect(function () {
1721
- var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevStateRef.current, state);
1724
+ var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
1725
+ var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
1722
1726
  if (shouldCallOnChangeProps) {
1723
- callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
1727
+ callOnChangeProps(action, prevState, state);
1724
1728
  }
1725
1729
  prevStateRef.current = state;
1726
1730
  }, [state, action, isStateEqual]);
@@ -1825,7 +1829,8 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1825
1829
  function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
1826
1830
  var mouseAndTouchTrackersRef = React.useRef({
1827
1831
  isMouseDown: false,
1828
- isTouchMove: false
1832
+ isTouchMove: false,
1833
+ isTouchEnd: false
1829
1834
  });
1830
1835
  React.useEffect(function () {
1831
1836
  if (!environment) {
@@ -1835,6 +1840,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1835
1840
  // The same strategy for checking if a click occurred inside or outside downshift
1836
1841
  // as in downshift.js.
1837
1842
  var onMouseDown = function onMouseDown() {
1843
+ mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
1838
1844
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1839
1845
  };
1840
1846
  var onMouseUp = function onMouseUp(event) {
@@ -1846,12 +1852,14 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1846
1852
  }
1847
1853
  };
1848
1854
  var onTouchStart = function onTouchStart() {
1855
+ mouseAndTouchTrackersRef.current.isTouchEnd = false;
1849
1856
  mouseAndTouchTrackersRef.current.isTouchMove = false;
1850
1857
  };
1851
1858
  var onTouchMove = function onTouchMove() {
1852
1859
  mouseAndTouchTrackersRef.current.isTouchMove = true;
1853
1860
  };
1854
1861
  var onTouchEnd = function onTouchEnd(event) {
1862
+ mouseAndTouchTrackersRef.current.isTouchEnd = true;
1855
1863
  if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1856
1864
  return ref.current;
1857
1865
  }), environment, false)) {
@@ -1930,11 +1938,11 @@ if (process.env.NODE_ENV !== 'production') {
1930
1938
  };
1931
1939
  }
1932
1940
  function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref3) {
1933
- var isInitialMount = _ref3.isInitialMount,
1934
- highlightedIndex = _ref3.highlightedIndex,
1941
+ var highlightedIndex = _ref3.highlightedIndex,
1935
1942
  items = _ref3.items,
1936
1943
  environment = _ref3.environment,
1937
1944
  rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded$3);
1945
+ var isInitialMount = useIsInitialMount();
1938
1946
  // Sets a11y status message on changes in state.
1939
1947
  React.useEffect(function () {
1940
1948
  if (isInitialMount || false || !(environment != null && environment.document)) {
@@ -1979,11 +1987,11 @@ var useControlPropsValidator = noop;
1979
1987
  /* istanbul ignore next */
1980
1988
  if (process.env.NODE_ENV !== 'production') {
1981
1989
  useControlPropsValidator = function useControlPropsValidator(_ref5) {
1982
- var isInitialMount = _ref5.isInitialMount,
1983
- props = _ref5.props,
1990
+ var props = _ref5.props,
1984
1991
  state = _ref5.state;
1985
1992
  // used for checking when props are moving from controlled to uncontrolled.
1986
1993
  var prevPropsRef = React.useRef(props);
1994
+ var isInitialMount = useIsInitialMount();
1987
1995
  React.useEffect(function () {
1988
1996
  if (isInitialMount) {
1989
1997
  return;
@@ -2032,6 +2040,20 @@ function isDropdownsStateEqual(prevState, newState) {
2032
2040
  return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
2033
2041
  }
2034
2042
 
2043
+ /**
2044
+ * Tracks if it's the first render.
2045
+ */
2046
+ function useIsInitialMount() {
2047
+ var isInitialMountRef = React__default["default"].useRef(true);
2048
+ React__default["default"].useEffect(function () {
2049
+ isInitialMountRef.current = false;
2050
+ return function () {
2051
+ isInitialMountRef.current = true;
2052
+ };
2053
+ }, []);
2054
+ return isInitialMountRef.current;
2055
+ }
2056
+
2035
2057
  // Shared between all exports.
2036
2058
  var commonPropTypes = {
2037
2059
  environment: PropTypes__default["default"].shape({
@@ -2372,7 +2394,7 @@ function useSelect(userProps) {
2372
2394
  var elementIds = useElementIds(props);
2373
2395
  // used to keep track of how many items we had on previous cycle.
2374
2396
  var previousResultCountRef = React.useRef();
2375
- var isInitialMountRef = React.useRef(true);
2397
+ var isInitialMount = useIsInitialMount();
2376
2398
  // utility callback to get item element.
2377
2399
  var latest = useLatestRef({
2378
2400
  state: state,
@@ -2387,7 +2409,6 @@ function useSelect(userProps) {
2387
2409
  // Effects.
2388
2410
  // Sets a11y status message on changes in state.
2389
2411
  useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
2390
- isInitialMount: isInitialMountRef.current,
2391
2412
  previousResultCount: previousResultCountRef.current,
2392
2413
  items: items,
2393
2414
  environment: environment,
@@ -2395,7 +2416,6 @@ function useSelect(userProps) {
2395
2416
  }, state));
2396
2417
  // Sets a11y status message on changes in selectedItem.
2397
2418
  useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
2398
- isInitialMount: isInitialMountRef.current,
2399
2419
  previousResultCount: previousResultCountRef.current,
2400
2420
  items: items,
2401
2421
  environment: environment,
@@ -2435,12 +2455,11 @@ function useSelect(userProps) {
2435
2455
  clearTimeoutRef.current(dispatch);
2436
2456
  }, [dispatch, inputValue]);
2437
2457
  useControlPropsValidator({
2438
- isInitialMount: isInitialMountRef.current,
2439
2458
  props: props,
2440
2459
  state: state
2441
2460
  });
2442
2461
  React.useEffect(function () {
2443
- if (isInitialMountRef.current) {
2462
+ if (isInitialMount) {
2444
2463
  return;
2445
2464
  }
2446
2465
  previousResultCountRef.current = items.length;
@@ -2460,13 +2479,6 @@ function useSelect(userProps) {
2460
2479
  });
2461
2480
  });
2462
2481
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2463
- // Make initial ref false.
2464
- React.useEffect(function () {
2465
- isInitialMountRef.current = false;
2466
- return function () {
2467
- isInitialMountRef.current = true;
2468
- };
2469
- }, []);
2470
2482
  // Reset itemRefs on close.
2471
2483
  React.useEffect(function () {
2472
2484
  if (!isOpen) {
@@ -2694,7 +2706,7 @@ function useSelect(userProps) {
2694
2706
  index = _getItemAndIndex[1];
2695
2707
  var disabled = latestProps.isItemDisabled(item, index);
2696
2708
  var itemHandleMouseMove = function itemHandleMouseMove() {
2697
- if (index === latestState.highlightedIndex) {
2709
+ if (mouseAndTouchTrackersRef.current.isTouchEnd || index === latestState.highlightedIndex) {
2698
2710
  return;
2699
2711
  }
2700
2712
  shouldScrollRef.current = false;
@@ -2728,7 +2740,7 @@ function useSelect(userProps) {
2728
2740
  itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
2729
2741
  itemProps.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown);
2730
2742
  return itemProps;
2731
- }, [latest, elementIds, shouldScrollRef, dispatch]);
2743
+ }, [latest, elementIds, mouseAndTouchTrackersRef, shouldScrollRef, dispatch]);
2732
2744
  return {
2733
2745
  // prop getters.
2734
2746
  getToggleButtonProps: getToggleButtonProps,
@@ -2843,13 +2855,14 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
2843
2855
  var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
2844
2856
  state = _useEnhancedReducer[0],
2845
2857
  dispatch = _useEnhancedReducer[1];
2846
-
2847
- // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
2858
+ var isInitialMount = useIsInitialMount();
2848
2859
  React.useEffect(function () {
2849
2860
  if (!isControlledProp(props, 'selectedItem')) {
2850
2861
  return;
2851
2862
  }
2852
- if (props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem)) {
2863
+ if (!isInitialMount &&
2864
+ // on first mount we already have the proper inputValue for a initial selected item.
2865
+ props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem)) {
2853
2866
  dispatch({
2854
2867
  type: ControlledPropUpdatedSelectedItem,
2855
2868
  inputValue: props.itemToString(props.selectedItem)
@@ -3027,7 +3040,8 @@ function useCombobox(userProps) {
3027
3040
  var itemRefs = React.useRef({});
3028
3041
  var inputRef = React.useRef(null);
3029
3042
  var toggleButtonRef = React.useRef(null);
3030
- var isInitialMountRef = React.useRef(true);
3043
+ var isInitialMount = useIsInitialMount();
3044
+
3031
3045
  // prevent id re-generation between renders.
3032
3046
  var elementIds = useElementIds(props);
3033
3047
  // used to keep track of how many items we had on previous cycle.
@@ -3044,7 +3058,6 @@ function useCombobox(userProps) {
3044
3058
  // Effects.
3045
3059
  // Sets a11y status message on changes in state.
3046
3060
  useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
3047
- isInitialMount: isInitialMountRef.current,
3048
3061
  previousResultCount: previousResultCountRef.current,
3049
3062
  items: items,
3050
3063
  environment: environment,
@@ -3052,7 +3065,6 @@ function useCombobox(userProps) {
3052
3065
  }, state));
3053
3066
  // Sets a11y status message on changes in selectedItem.
3054
3067
  useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
3055
- isInitialMount: isInitialMountRef.current,
3056
3068
  previousResultCount: previousResultCountRef.current,
3057
3069
  items: items,
3058
3070
  environment: environment,
@@ -3068,7 +3080,6 @@ function useCombobox(userProps) {
3068
3080
  getItemNodeFromIndex: getItemNodeFromIndex
3069
3081
  });
3070
3082
  useControlPropsValidator({
3071
- isInitialMount: isInitialMountRef.current,
3072
3083
  props: props,
3073
3084
  state: state
3074
3085
  });
@@ -3081,10 +3092,9 @@ function useCombobox(userProps) {
3081
3092
  // eslint-disable-next-line react-hooks/exhaustive-deps
3082
3093
  }, []);
3083
3094
  React.useEffect(function () {
3084
- if (isInitialMountRef.current) {
3085
- return;
3095
+ if (!isInitialMount) {
3096
+ previousResultCountRef.current = items.length;
3086
3097
  }
3087
- previousResultCountRef.current = items.length;
3088
3098
  });
3089
3099
  // Add mouse/touch events to document.
3090
3100
  var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, function () {
@@ -3094,13 +3104,6 @@ function useCombobox(userProps) {
3094
3104
  });
3095
3105
  });
3096
3106
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3097
- // Make initial ref false.
3098
- React.useEffect(function () {
3099
- isInitialMountRef.current = false;
3100
- return function () {
3101
- isInitialMountRef.current = true;
3102
- };
3103
- }, []);
3104
3107
  // Reset itemRefs on close.
3105
3108
  React.useEffect(function () {
3106
3109
  if (!isOpen) {
@@ -3247,7 +3250,7 @@ function useCombobox(userProps) {
3247
3250
  var onSelectKey = /* istanbul ignore next (react-native) */'onPress' ;
3248
3251
  var customClickHandler = onClick;
3249
3252
  var itemHandleMouseMove = function itemHandleMouseMove() {
3250
- if (index === latestState.highlightedIndex) {
3253
+ if (mouseAndTouchTrackersRef.current.isTouchEnd || index === latestState.highlightedIndex) {
3251
3254
  return;
3252
3255
  }
3253
3256
  shouldScrollRef.current = false;
@@ -3275,7 +3278,7 @@ function useCombobox(userProps) {
3275
3278
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3276
3279
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3277
3280
  }, rest);
3278
- }, [dispatch, latest, shouldScrollRef, elementIds]);
3281
+ }, [dispatch, elementIds, latest, mouseAndTouchTrackersRef, shouldScrollRef]);
3279
3282
  var getToggleButtonProps = React.useCallback(function (_temp4) {
3280
3283
  var _extends4;
3281
3284
  var _ref5 = _temp4 === void 0 ? {} : _temp4;
@@ -3707,7 +3710,7 @@ function useMultipleSelection(userProps) {
3707
3710
  selectedItems = state.selectedItems;
3708
3711
 
3709
3712
  // Refs.
3710
- var isInitialMountRef = React.useRef(true);
3713
+ var isInitialMount = useIsInitialMount();
3711
3714
  var dropdownRef = React.useRef(null);
3712
3715
  var previousSelectedItemsRef = React.useRef(selectedItems);
3713
3716
  var selectedItemRefs = React.useRef();
@@ -3720,7 +3723,7 @@ function useMultipleSelection(userProps) {
3720
3723
  // Effects.
3721
3724
  /* Sets a11y status message on changes in selectedItem. */
3722
3725
  React.useEffect(function () {
3723
- if (isInitialMountRef.current || false || !(environment != null && environment.document)) {
3726
+ if (isInitialMount || false || !(environment != null && environment.document)) {
3724
3727
  return;
3725
3728
  }
3726
3729
  if (selectedItems.length < previousSelectedItemsRef.current.length) {
@@ -3741,7 +3744,7 @@ function useMultipleSelection(userProps) {
3741
3744
  }, [selectedItems.length]);
3742
3745
  // Sets focus on active item.
3743
3746
  React.useEffect(function () {
3744
- if (isInitialMountRef.current) {
3747
+ if (isInitialMount) {
3745
3748
  return;
3746
3749
  }
3747
3750
  if (activeIndex === -1 && dropdownRef.current) {
@@ -3749,20 +3752,12 @@ function useMultipleSelection(userProps) {
3749
3752
  } else if (selectedItemRefs.current[activeIndex]) {
3750
3753
  selectedItemRefs.current[activeIndex].focus();
3751
3754
  }
3752
- }, [activeIndex]);
3755
+ }, [activeIndex, isInitialMount]);
3753
3756
  useControlPropsValidator({
3754
- isInitialMount: isInitialMountRef.current,
3755
3757
  props: props,
3756
3758
  state: state
3757
3759
  });
3758
3760
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
3759
- // Make initial ref false.
3760
- React.useEffect(function () {
3761
- isInitialMountRef.current = false;
3762
- return function () {
3763
- isInitialMountRef.current = true;
3764
- };
3765
- }, []);
3766
3761
 
3767
3762
  // Event handler functions.
3768
3763
  var selectedItemKeyDownHandlers = React.useMemo(function () {