downshift 9.0.7-alpha.0 → 9.0.7-alpha.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.
@@ -1786,7 +1786,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1786
1786
  function getInitialState$2(props) {
1787
1787
  var selectedItem = getInitialValue$1(props, 'selectedItem');
1788
1788
  var isOpen = getInitialValue$1(props, 'isOpen');
1789
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1789
+ var highlightedIndex = getInitialHighlightedIndex(props);
1790
1790
  var inputValue = getInitialValue$1(props, 'inputValue');
1791
1791
  return {
1792
1792
  highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
@@ -1801,6 +1801,7 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1801
1801
  var items = props.items,
1802
1802
  initialHighlightedIndex = props.initialHighlightedIndex,
1803
1803
  defaultHighlightedIndex = props.defaultHighlightedIndex,
1804
+ isItemDisabled = props.isItemDisabled,
1804
1805
  itemToKey = props.itemToKey;
1805
1806
  var selectedItem = state.selectedItem,
1806
1807
  highlightedIndex = state.highlightedIndex;
@@ -1809,10 +1810,10 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1809
1810
  }
1810
1811
 
1811
1812
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
1812
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex) {
1813
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1813
1814
  return initialHighlightedIndex;
1814
1815
  }
1815
- if (defaultHighlightedIndex !== undefined) {
1816
+ if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1816
1817
  return defaultHighlightedIndex;
1817
1818
  }
1818
1819
  if (selectedItem) {
@@ -1820,20 +1821,23 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1820
1821
  return itemToKey(selectedItem) === itemToKey(item);
1821
1822
  });
1822
1823
  }
1823
- if (offset === 0) {
1824
- return -1;
1824
+ if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1825
+ return items.length - 1;
1826
+ }
1827
+ if (offset > 0 && !isItemDisabled(items[0], 0)) {
1828
+ return 0;
1825
1829
  }
1826
- return offset < 0 ? items.length - 1 : 0;
1830
+ return -1;
1827
1831
  }
1828
1832
  /**
1829
1833
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
1830
1834
  *
1831
- * @param {Object} environment The environment to add the event listeners to, for instance window.
1832
- * @param {Array<HTMLElement>} downshiftElementRefs The refs for the element that should not trigger a blur action from mouseDown or touchEnd.
1833
- * @param {Function} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1834
- * @returns {Object} The mouse and touch events information, if any of are happening.
1835
+ * @param {Window} environment The environment to add the event listeners to, for instance window.
1836
+ * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1837
+ * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
1838
+ * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
1835
1839
  */
1836
- function useMouseAndTouchTracker(environment, downshiftElementRefs, handleBlur) {
1840
+ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs) {
1837
1841
  var mouseAndTouchTrackersRef = React.useRef({
1838
1842
  isMouseDown: false,
1839
1843
  isTouchMove: false,
@@ -1843,7 +1847,7 @@ function useMouseAndTouchTracker(environment, downshiftElementRefs, handleBlur)
1843
1847
  if (!environment) {
1844
1848
  return noop;
1845
1849
  }
1846
- var downshiftElements = downshiftElementRefs.map(function (ref) {
1850
+ var downshiftElements = downshiftElementsRefs.map(function (ref) {
1847
1851
  return ref.current;
1848
1852
  });
1849
1853
  function onMouseDown() {
@@ -1881,8 +1885,7 @@ function useMouseAndTouchTracker(environment, downshiftElementRefs, handleBlur)
1881
1885
  environment.removeEventListener('touchmove', onTouchMove);
1882
1886
  environment.removeEventListener('touchend', onTouchEnd);
1883
1887
  };
1884
- // eslint-disable-next-line react-hooks/exhaustive-deps -- refs don't change
1885
- }, [environment, handleBlur]);
1888
+ }, [downshiftElementsRefs, environment, handleBlur]);
1886
1889
  return mouseAndTouchTrackersRef.current;
1887
1890
  }
1888
1891
 
@@ -1962,7 +1965,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
1962
1965
  updateA11yStatus(status, document);
1963
1966
 
1964
1967
  // eslint-disable-next-line react-hooks/exhaustive-deps
1965
- }, [dependencyArray]);
1968
+ }, dependencyArray);
1966
1969
 
1967
1970
  // Cleanup the status message container.
1968
1971
  React.useEffect(function () {
@@ -2068,6 +2071,34 @@ function useIsInitialMount() {
2068
2071
  return isInitialMountRef.current;
2069
2072
  }
2070
2073
 
2074
+ /**
2075
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2076
+ *
2077
+ * @param {Object} props Props from useCombobox or useSelect.
2078
+ * @returns {number} The highlighted index.
2079
+ */
2080
+ function getDefaultHighlightedIndex(props) {
2081
+ var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex');
2082
+ if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2083
+ return -1;
2084
+ }
2085
+ return highlightedIndex;
2086
+ }
2087
+
2088
+ /**
2089
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2090
+ *
2091
+ * @param {Object} props Props from useCombobox or useSelect.
2092
+ * @returns {number} The highlighted index.
2093
+ */
2094
+ function getInitialHighlightedIndex(props) {
2095
+ var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
2096
+ if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2097
+ return -1;
2098
+ }
2099
+ return highlightedIndex;
2100
+ }
2101
+
2071
2102
  // Shared between all exports.
2072
2103
  var commonPropTypes = {
2073
2104
  environment: PropTypes__default["default"].shape({
@@ -2145,7 +2176,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
2145
2176
  break;
2146
2177
  case stateChangeTypes.FunctionSetHighlightedIndex:
2147
2178
  changes = {
2148
- highlightedIndex: action.highlightedIndex
2179
+ highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
2149
2180
  };
2150
2181
  break;
2151
2182
  case stateChangeTypes.FunctionSetInputValue:
@@ -2155,7 +2186,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
2155
2186
  break;
2156
2187
  case stateChangeTypes.FunctionReset:
2157
2188
  changes = {
2158
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2189
+ highlightedIndex: getDefaultHighlightedIndex(props),
2159
2190
  isOpen: getDefaultValue$1(props, 'isOpen'),
2160
2191
  selectedItem: getDefaultValue$1(props, 'selectedItem'),
2161
2192
  inputValue: getDefaultValue$1(props, 'inputValue')
@@ -2256,7 +2287,7 @@ function downshiftSelectReducer(state, action) {
2256
2287
  case ItemClick$1:
2257
2288
  changes = {
2258
2289
  isOpen: getDefaultValue$1(props, 'isOpen'),
2259
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2290
+ highlightedIndex: getDefaultHighlightedIndex(props),
2260
2291
  selectedItem: props.items[action.index]
2261
2292
  };
2262
2293
  break;
@@ -2381,6 +2412,7 @@ function useSelect(userProps) {
2381
2412
  var toggleButtonRef = React.useRef(null);
2382
2413
  var menuRef = React.useRef(null);
2383
2414
  var itemRefs = React.useRef({});
2415
+
2384
2416
  // used to keep the inputValue clearTimeout object between renders.
2385
2417
  var clearTimeoutRef = React.useRef(null);
2386
2418
  // prevent id re-generation between renders.
@@ -2442,13 +2474,15 @@ function useSelect(userProps) {
2442
2474
  }
2443
2475
  // eslint-disable-next-line react-hooks/exhaustive-deps
2444
2476
  }, []);
2445
- var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, [toggleButtonRef, menuRef], React.useCallback(function handleBlur() {
2477
+ var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, React.useCallback(function handleBlur() {
2446
2478
  if (latest.current.state.isOpen) {
2447
2479
  dispatch({
2448
2480
  type: ToggleButtonBlur
2449
2481
  });
2450
2482
  }
2451
- }, [dispatch, latest]));
2483
+ }, [dispatch, latest]), React.useMemo(function () {
2484
+ return [menuRef, toggleButtonRef];
2485
+ }, []));
2452
2486
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2453
2487
  // Reset itemRefs on close.
2454
2488
  React.useEffect(function () {
@@ -2713,7 +2747,7 @@ function useSelect(userProps) {
2713
2747
  if (itemNode) {
2714
2748
  itemRefs.current[elementIds.getItemId(index)] = itemNode;
2715
2749
  }
2716
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = "" + (item === latestState.selectedItem), _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2750
+ }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2717
2751
  if (!disabled) {
2718
2752
  /* istanbul ignore next (react-native) */
2719
2753
  {
@@ -2882,7 +2916,7 @@ function downshiftUseComboboxReducer(state, action) {
2882
2916
  case ItemClick:
2883
2917
  changes = {
2884
2918
  isOpen: getDefaultValue$1(props, 'isOpen'),
2885
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2919
+ highlightedIndex: getDefaultHighlightedIndex(props),
2886
2920
  selectedItem: props.items[action.index],
2887
2921
  inputValue: props.itemToString(props.items[action.index])
2888
2922
  };
@@ -2959,7 +2993,7 @@ function downshiftUseComboboxReducer(state, action) {
2959
2993
  case InputChange:
2960
2994
  changes = {
2961
2995
  isOpen: true,
2962
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2996
+ highlightedIndex: getDefaultHighlightedIndex(props),
2963
2997
  inputValue: action.inputValue
2964
2998
  };
2965
2999
  break;
@@ -3061,14 +3095,16 @@ function useCombobox(userProps) {
3061
3095
  previousResultCountRef.current = items.length;
3062
3096
  }
3063
3097
  });
3064
- var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, [toggleButtonRef, menuRef, inputRef], React.useCallback(function handleBlur() {
3098
+ var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, React.useCallback(function handleBlur() {
3065
3099
  if (latest.current.state.isOpen) {
3066
3100
  dispatch({
3067
3101
  type: InputBlur,
3068
3102
  selectItem: false
3069
3103
  });
3070
3104
  }
3071
- }, [dispatch, latest]));
3105
+ }, [dispatch, latest]), React.useMemo(function () {
3106
+ return [menuRef, toggleButtonRef, inputRef];
3107
+ }, []));
3072
3108
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3073
3109
  // Reset itemRefs on close.
3074
3110
  React.useEffect(function () {
@@ -3240,7 +3276,7 @@ function useCombobox(userProps) {
3240
3276
  if (itemNode) {
3241
3277
  itemRefs.current[elementIds.getItemId(index)] = itemNode;
3242
3278
  }
3243
- }), _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), {
3279
+ }), _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), {
3244
3280
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3245
3281
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3246
3282
  }, rest);
@@ -1773,7 +1773,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1773
1773
  function getInitialState$2(props) {
1774
1774
  var selectedItem = getInitialValue$1(props, 'selectedItem');
1775
1775
  var isOpen = getInitialValue$1(props, 'isOpen');
1776
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1776
+ var highlightedIndex = getInitialHighlightedIndex(props);
1777
1777
  var inputValue = getInitialValue$1(props, 'inputValue');
1778
1778
  return {
1779
1779
  highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
@@ -1788,6 +1788,7 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1788
1788
  var items = props.items,
1789
1789
  initialHighlightedIndex = props.initialHighlightedIndex,
1790
1790
  defaultHighlightedIndex = props.defaultHighlightedIndex,
1791
+ isItemDisabled = props.isItemDisabled,
1791
1792
  itemToKey = props.itemToKey;
1792
1793
  var selectedItem = state.selectedItem,
1793
1794
  highlightedIndex = state.highlightedIndex;
@@ -1796,10 +1797,10 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1796
1797
  }
1797
1798
 
1798
1799
  // initialHighlightedIndex will give value to highlightedIndex on initial state only.
1799
- if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex) {
1800
+ if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
1800
1801
  return initialHighlightedIndex;
1801
1802
  }
1802
- if (defaultHighlightedIndex !== undefined) {
1803
+ if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
1803
1804
  return defaultHighlightedIndex;
1804
1805
  }
1805
1806
  if (selectedItem) {
@@ -1807,20 +1808,23 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1807
1808
  return itemToKey(selectedItem) === itemToKey(item);
1808
1809
  });
1809
1810
  }
1810
- if (offset === 0) {
1811
- return -1;
1811
+ if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
1812
+ return items.length - 1;
1813
+ }
1814
+ if (offset > 0 && !isItemDisabled(items[0], 0)) {
1815
+ return 0;
1812
1816
  }
1813
- return offset < 0 ? items.length - 1 : 0;
1817
+ return -1;
1814
1818
  }
1815
1819
  /**
1816
1820
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
1817
1821
  *
1818
- * @param {Object} environment The environment to add the event listeners to, for instance window.
1819
- * @param {Array<HTMLElement>} downshiftElementRefs The refs for the element that should not trigger a blur action from mouseDown or touchEnd.
1820
- * @param {Function} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1821
- * @returns {Object} The mouse and touch events information, if any of are happening.
1822
+ * @param {Window} environment The environment to add the event listeners to, for instance window.
1823
+ * @param {() => void} handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
1824
+ * @param {Array<{current: HTMLElement}>} downshiftElementsRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
1825
+ * @returns {{isMouseDown: boolean, isTouchMove: boolean, isTouchEnd: boolean}} The mouse and touch events information, if any of are happening.
1822
1826
  */
1823
- function useMouseAndTouchTracker(environment, downshiftElementRefs, handleBlur) {
1827
+ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs) {
1824
1828
  var mouseAndTouchTrackersRef = useRef({
1825
1829
  isMouseDown: false,
1826
1830
  isTouchMove: false,
@@ -1830,7 +1834,7 @@ function useMouseAndTouchTracker(environment, downshiftElementRefs, handleBlur)
1830
1834
  if (!environment) {
1831
1835
  return noop;
1832
1836
  }
1833
- var downshiftElements = downshiftElementRefs.map(function (ref) {
1837
+ var downshiftElements = downshiftElementsRefs.map(function (ref) {
1834
1838
  return ref.current;
1835
1839
  });
1836
1840
  function onMouseDown() {
@@ -1868,8 +1872,7 @@ function useMouseAndTouchTracker(environment, downshiftElementRefs, handleBlur)
1868
1872
  environment.removeEventListener('touchmove', onTouchMove);
1869
1873
  environment.removeEventListener('touchend', onTouchEnd);
1870
1874
  };
1871
- // eslint-disable-next-line react-hooks/exhaustive-deps -- refs don't change
1872
- }, [environment, handleBlur]);
1875
+ }, [downshiftElementsRefs, environment, handleBlur]);
1873
1876
  return mouseAndTouchTrackersRef.current;
1874
1877
  }
1875
1878
 
@@ -1949,7 +1952,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
1949
1952
  updateA11yStatus(status, document);
1950
1953
 
1951
1954
  // eslint-disable-next-line react-hooks/exhaustive-deps
1952
- }, [dependencyArray]);
1955
+ }, dependencyArray);
1953
1956
 
1954
1957
  // Cleanup the status message container.
1955
1958
  useEffect(function () {
@@ -2055,6 +2058,34 @@ function useIsInitialMount() {
2055
2058
  return isInitialMountRef.current;
2056
2059
  }
2057
2060
 
2061
+ /**
2062
+ * Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
2063
+ *
2064
+ * @param {Object} props Props from useCombobox or useSelect.
2065
+ * @returns {number} The highlighted index.
2066
+ */
2067
+ function getDefaultHighlightedIndex(props) {
2068
+ var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex');
2069
+ if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2070
+ return -1;
2071
+ }
2072
+ return highlightedIndex;
2073
+ }
2074
+
2075
+ /**
2076
+ * Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
2077
+ *
2078
+ * @param {Object} props Props from useCombobox or useSelect.
2079
+ * @returns {number} The highlighted index.
2080
+ */
2081
+ function getInitialHighlightedIndex(props) {
2082
+ var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
2083
+ if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
2084
+ return -1;
2085
+ }
2086
+ return highlightedIndex;
2087
+ }
2088
+
2058
2089
  // Shared between all exports.
2059
2090
  var commonPropTypes = {
2060
2091
  environment: PropTypes.shape({
@@ -2132,7 +2163,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
2132
2163
  break;
2133
2164
  case stateChangeTypes.FunctionSetHighlightedIndex:
2134
2165
  changes = {
2135
- highlightedIndex: action.highlightedIndex
2166
+ highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
2136
2167
  };
2137
2168
  break;
2138
2169
  case stateChangeTypes.FunctionSetInputValue:
@@ -2142,7 +2173,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
2142
2173
  break;
2143
2174
  case stateChangeTypes.FunctionReset:
2144
2175
  changes = {
2145
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2176
+ highlightedIndex: getDefaultHighlightedIndex(props),
2146
2177
  isOpen: getDefaultValue$1(props, 'isOpen'),
2147
2178
  selectedItem: getDefaultValue$1(props, 'selectedItem'),
2148
2179
  inputValue: getDefaultValue$1(props, 'inputValue')
@@ -2243,7 +2274,7 @@ function downshiftSelectReducer(state, action) {
2243
2274
  case ItemClick$1:
2244
2275
  changes = {
2245
2276
  isOpen: getDefaultValue$1(props, 'isOpen'),
2246
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2277
+ highlightedIndex: getDefaultHighlightedIndex(props),
2247
2278
  selectedItem: props.items[action.index]
2248
2279
  };
2249
2280
  break;
@@ -2368,6 +2399,7 @@ function useSelect(userProps) {
2368
2399
  var toggleButtonRef = useRef(null);
2369
2400
  var menuRef = useRef(null);
2370
2401
  var itemRefs = useRef({});
2402
+
2371
2403
  // used to keep the inputValue clearTimeout object between renders.
2372
2404
  var clearTimeoutRef = useRef(null);
2373
2405
  // prevent id re-generation between renders.
@@ -2429,13 +2461,15 @@ function useSelect(userProps) {
2429
2461
  }
2430
2462
  // eslint-disable-next-line react-hooks/exhaustive-deps
2431
2463
  }, []);
2432
- var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, [toggleButtonRef, menuRef], useCallback(function handleBlur() {
2464
+ var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, useCallback(function handleBlur() {
2433
2465
  if (latest.current.state.isOpen) {
2434
2466
  dispatch({
2435
2467
  type: ToggleButtonBlur
2436
2468
  });
2437
2469
  }
2438
- }, [dispatch, latest]));
2470
+ }, [dispatch, latest]), useMemo(function () {
2471
+ return [menuRef, toggleButtonRef];
2472
+ }, []));
2439
2473
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2440
2474
  // Reset itemRefs on close.
2441
2475
  useEffect(function () {
@@ -2700,7 +2734,7 @@ function useSelect(userProps) {
2700
2734
  if (itemNode) {
2701
2735
  itemRefs.current[elementIds.getItemId(index)] = itemNode;
2702
2736
  }
2703
- }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = "" + (item === latestState.selectedItem), _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2737
+ }), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
2704
2738
  if (!disabled) {
2705
2739
  /* istanbul ignore next (react-native) */
2706
2740
  {
@@ -2869,7 +2903,7 @@ function downshiftUseComboboxReducer(state, action) {
2869
2903
  case ItemClick:
2870
2904
  changes = {
2871
2905
  isOpen: getDefaultValue$1(props, 'isOpen'),
2872
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2906
+ highlightedIndex: getDefaultHighlightedIndex(props),
2873
2907
  selectedItem: props.items[action.index],
2874
2908
  inputValue: props.itemToString(props.items[action.index])
2875
2909
  };
@@ -2946,7 +2980,7 @@ function downshiftUseComboboxReducer(state, action) {
2946
2980
  case InputChange:
2947
2981
  changes = {
2948
2982
  isOpen: true,
2949
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2983
+ highlightedIndex: getDefaultHighlightedIndex(props),
2950
2984
  inputValue: action.inputValue
2951
2985
  };
2952
2986
  break;
@@ -3048,14 +3082,16 @@ function useCombobox(userProps) {
3048
3082
  previousResultCountRef.current = items.length;
3049
3083
  }
3050
3084
  });
3051
- var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, [toggleButtonRef, menuRef, inputRef], useCallback(function handleBlur() {
3085
+ var mouseAndTouchTrackers = useMouseAndTouchTracker(environment, useCallback(function handleBlur() {
3052
3086
  if (latest.current.state.isOpen) {
3053
3087
  dispatch({
3054
3088
  type: InputBlur,
3055
3089
  selectItem: false
3056
3090
  });
3057
3091
  }
3058
- }, [dispatch, latest]));
3092
+ }, [dispatch, latest]), useMemo(function () {
3093
+ return [menuRef, toggleButtonRef, inputRef];
3094
+ }, []));
3059
3095
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3060
3096
  // Reset itemRefs on close.
3061
3097
  useEffect(function () {
@@ -3227,7 +3263,7 @@ function useCombobox(userProps) {
3227
3263
  if (itemNode) {
3228
3264
  itemRefs.current[elementIds.getItemId(index)] = itemNode;
3229
3265
  }
3230
- }), _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), {
3266
+ }), _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), {
3231
3267
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3232
3268
  onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3233
3269
  }, rest);