downshift 9.0.10 → 9.0.12

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.
package/README.md CHANGED
@@ -1093,7 +1093,7 @@ platforms:
1093
1093
  > 🚨 We're in the process of moving all examples to the
1094
1094
  > [downshift-examples](https://github.com/downshift-js/downshift-examples) repo
1095
1095
  > (which you can open, interact with, and contribute back to live on
1096
- > [codesandbox](https://codesandbox.io/s/github/kentcdodds/downshift-examples))
1096
+ > [codesandbox](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Findex.js&moduleview=1))
1097
1097
 
1098
1098
  > 🚨 We're also in the process of updating our examples from the
1099
1099
  > [downshift-docs](https://github.com/downshift-js/downshift-docs) repo which is
@@ -1105,18 +1105,18 @@ platforms:
1105
1105
 
1106
1106
  If you're just learning downshift, review these in order:
1107
1107
 
1108
- 0. [basic automplete with getRootProps](https://codesandbox.io/s/github/kentcdodds/downshift-examples?file=/src/downshift/ordered-examples/00-get-root-props-example.js) -
1108
+ 0. [basic automplete with getRootProps](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fordered-examples%2F00-get-root-props-example.js%3A11%2C21&moduleview=1) -
1109
1109
  the same as example #1 but using the correct HTML structure as suggested by
1110
1110
  ARIA-WCAG.
1111
- 1. [basic autocomplete](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fordered-examples%2F01-basic-autocomplete.js&moduleview=1) -
1111
+ 1. [basic autocomplete](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fordered-examples%2F01-basic-autocomplete.js&moduleview=1) -
1112
1112
  very bare bones, not styled at all. Good place to start.
1113
- 2. [styled autocomplete](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fordered-examples%2F02-complete-autocomplete.js&moduleview=1) -
1113
+ 2. [styled autocomplete](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fordered-examples%2F02-complete-autocomplete.js&moduleview=1) -
1114
1114
  more complete autocomplete solution using emotion for styling and
1115
1115
  match-sorter for filtering the items.
1116
- 3. [typeahead](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fordered-examples%2F03-typeahead.js&moduleview=1) -
1116
+ 3. [typeahead](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fordered-examples%2F03-typeahead.js&moduleview=1) -
1117
1117
  Shows how to control the `selectedItem` so the selected item can be one of
1118
1118
  your items or whatever the user types.
1119
- 4. [multi-select](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fordered-examples%2F04-multi-select.js&moduleview=1) -
1119
+ 4. [multi-select](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fordered-examples%2F04-multi-select.js&moduleview=1) -
1120
1120
  Shows how to create a MultiDownshift component that allows for an array of
1121
1121
  selectedItems for multiple selection using a state reducer
1122
1122
 
@@ -1124,16 +1124,16 @@ If you're just learning downshift, review these in order:
1124
1124
 
1125
1125
  Check out these examples of more advanced use/edge cases:
1126
1126
 
1127
- - [dropdown with select by key](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fother-examples%2Fdropdown-select-by-key%2FCustomDropdown%2Findex.js) -
1127
+ - [dropdown with select by key](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fother-examples%2Fdropdown-select-by-key%2FCustomDropdown%2Findex.js&moduleview=1) -
1128
1128
  An example of using the render prop pattern to utilize a reusable component to
1129
1129
  provide the downshift dropdown component with the functionality of being able
1130
1130
  to highlight a selection item that starts with the key pressed.
1131
- - [using actions](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fother-examples%2Fusing-actions.js&moduleview=1) -
1131
+ - [using actions](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fother-examples%2Fusing-actions.js&moduleview=1) -
1132
1132
  An example of using one of downshift's actions as an event handler.
1133
- - [gmail's composition recipients field](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fother-examples%2Fgmail%2Findex.js&moduleview=1) -
1133
+ - [gmail's composition recipients field](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fother-examples%2Fgmail%2Findex.js&moduleview=1) -
1134
1134
  An example of a highly complex autocomplete component featuring asynchronously
1135
1135
  loading items, multiple selection, and windowing (with react-virtualized)
1136
- - [Downshift HOC and Compound Components](https://codesandbox.io/s/github/kentcdodds/downshift-examples/tree/master/?module=%2Fsrc%2Fother-examples%2Fhoc%2Findex.js&moduleview=1) -
1136
+ - [Downshift HOC and Compound Components](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fother-examples%2Fhoc%2Findex.js&moduleview=1) -
1137
1137
  An example of how to implementat compound components with
1138
1138
  `React.createContext` and a downshift higher order component. This is
1139
1139
  generally not recommended because the render prop API exported by downshift is
@@ -1144,7 +1144,7 @@ Check out these examples of more advanced use/edge cases:
1144
1144
 
1145
1145
  _🚨 This is a great contribution opportunity!_ These are examples that have not
1146
1146
  yet been migrated to
1147
- [downshift-examples](https://codesandbox.io/s/github/kentcdodds/downshift-examples).
1147
+ [downshift-examples](https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Findex.js&moduleview=1).
1148
1148
  You're more than welcome to make PRs to the examples repository to move these
1149
1149
  examples over there.
1150
1150
  [Watch this to learn how to contribute completely in the browser](https://www.youtube.com/watch?v=3PAQbhdkTtI&index=2&t=21s&list=PLV5CVI1eNcJgCrPH_e6d57KRUTiDZgs0u)
@@ -1526,8 +1526,8 @@ MIT
1526
1526
  https://www.w3.org/WAI/ARIA/apg/example-index/combobox/combobox-select-only.html
1527
1527
  [docsite]: https://downshift-js.com/
1528
1528
  [code-sandbox-try-it-out]:
1529
- https://codesandbox.io/s/github/kentcdodds/downshift-examples?file=/src/downshift/ordered-examples/00-get-root-props-example.js
1529
+ https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fordered-examples%2F00-get-root-props-example.js&moduleview=1
1530
1530
  [code-sandbox-no-get-root-props]:
1531
- https://codesandbox.io/s/github/kentcdodds/downshift-examples?file=/src/downshift/ordered-examples/01-basic-autocomplete.js
1531
+ https://codesandbox.io/p/sandbox/github/kentcdodds/downshift-examples?file=%2Fsrc%2Fdownshift%2Fordered-examples%2F01-basic-autocomplete.js&moduleview=1
1532
1532
  [migration-guide-v7]:
1533
1533
  https://github.com/downshift-js/downshift/tree/master/src/hooks/MIGRATION_V7.md
@@ -1616,16 +1616,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1616
1616
  if (!id) {
1617
1617
  id = reactId;
1618
1618
  }
1619
- var elementIdsRef = React.useRef({
1620
- labelId: labelId || id + "-label",
1621
- menuId: menuId || id + "-menu",
1622
- getItemId: getItemId || function (index) {
1623
- return id + "-item-" + index;
1624
- },
1625
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1626
- inputId: inputId || id + "-input"
1627
- });
1628
- return elementIdsRef.current;
1619
+ var elementIds = React.useMemo(function () {
1620
+ return {
1621
+ labelId: labelId || id + "-label",
1622
+ menuId: menuId || id + "-menu",
1623
+ getItemId: getItemId || function (index) {
1624
+ return id + "-item-" + index;
1625
+ },
1626
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1627
+ inputId: inputId || id + "-input"
1628
+ };
1629
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1630
+ return elementIds;
1629
1631
  } : function useElementIds(_ref2) {
1630
1632
  var _ref2$id = _ref2.id,
1631
1633
  id = _ref2$id === void 0 ? "downshift-" + generateId() : _ref2$id,
@@ -1634,16 +1636,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1634
1636
  getItemId = _ref2.getItemId,
1635
1637
  toggleButtonId = _ref2.toggleButtonId,
1636
1638
  inputId = _ref2.inputId;
1637
- var elementIdsRef = React.useRef({
1638
- labelId: labelId || id + "-label",
1639
- menuId: menuId || id + "-menu",
1640
- getItemId: getItemId || function (index) {
1641
- return id + "-item-" + index;
1642
- },
1643
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1644
- inputId: inputId || id + "-input"
1645
- });
1646
- return elementIdsRef.current;
1639
+ var elementIds = React.useMemo(function () {
1640
+ return {
1641
+ labelId: labelId || id + "-label",
1642
+ menuId: menuId || id + "-menu",
1643
+ getItemId: getItemId || function (index) {
1644
+ return id + "-item-" + index;
1645
+ },
1646
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1647
+ inputId: inputId || id + "-input"
1648
+ };
1649
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1650
+ return elementIds;
1647
1651
  };
1648
1652
  function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
1649
1653
  var item, index;
@@ -1832,20 +1836,24 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1832
1836
  isTouchMove: false,
1833
1837
  isTouchEnd: false
1834
1838
  });
1839
+
1840
+ // the elements should be retrieved the moment they are required because these are refs - they can be mutated
1841
+ function getDownshiftElements() {
1842
+ return downshiftElementsRefs.map(function (ref) {
1843
+ return ref.current;
1844
+ });
1845
+ }
1835
1846
  React.useEffect(function () {
1836
1847
  if (!environment) {
1837
1848
  return noop;
1838
1849
  }
1839
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
1840
- return ref.current;
1841
- });
1842
1850
  function onMouseDown() {
1843
1851
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
1844
1852
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1845
1853
  }
1846
1854
  function onMouseUp(event) {
1847
1855
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1848
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
1856
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
1849
1857
  handleBlur();
1850
1858
  }
1851
1859
  }
@@ -1858,7 +1866,7 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1858
1866
  }
1859
1867
  function onTouchEnd(event) {
1860
1868
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
1861
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
1869
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
1862
1870
  handleBlur();
1863
1871
  }
1864
1872
  }
@@ -2470,7 +2478,9 @@ function useSelect(userProps) {
2470
2478
  }
2471
2479
  }, [dispatch, latest]), React.useMemo(function () {
2472
2480
  return [menuRef, toggleButtonRef];
2473
- }, [menuRef.current, toggleButtonRef.current]));
2481
+ },
2482
+ // dependencies can be left empty because refs are getting mutated
2483
+ []));
2474
2484
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2475
2485
  // Reset itemRefs on close.
2476
2486
  React.useEffect(function () {
@@ -3092,7 +3102,9 @@ function useCombobox(userProps) {
3092
3102
  }
3093
3103
  }, [dispatch, latest]), React.useMemo(function () {
3094
3104
  return [menuRef, toggleButtonRef, inputRef];
3095
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
3105
+ },
3106
+ // dependencies can be left empty because refs are getting mutated
3107
+ []));
3096
3108
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3097
3109
  // Reset itemRefs on close.
3098
3110
  React.useEffect(function () {
@@ -2,7 +2,7 @@ import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWith
2
2
  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
- import React, { cloneElement, Component, useRef, useEffect, useLayoutEffect, useCallback, useReducer, useMemo } from 'react';
5
+ import React, { cloneElement, Component, useMemo, useRef, useEffect, useLayoutEffect, useCallback, useReducer } from 'react';
6
6
  import { isForwardRef } from 'react-is';
7
7
  import { compute } from 'compute-scroll-into-view';
8
8
  import { __assign } from 'tslib';
@@ -1612,16 +1612,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1612
1612
  if (!id) {
1613
1613
  id = reactId;
1614
1614
  }
1615
- var elementIdsRef = useRef({
1616
- labelId: labelId || id + "-label",
1617
- menuId: menuId || id + "-menu",
1618
- getItemId: getItemId || function (index) {
1619
- return id + "-item-" + index;
1620
- },
1621
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1622
- inputId: inputId || id + "-input"
1623
- });
1624
- return elementIdsRef.current;
1615
+ var elementIds = useMemo(function () {
1616
+ return {
1617
+ labelId: labelId || id + "-label",
1618
+ menuId: menuId || id + "-menu",
1619
+ getItemId: getItemId || function (index) {
1620
+ return id + "-item-" + index;
1621
+ },
1622
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1623
+ inputId: inputId || id + "-input"
1624
+ };
1625
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1626
+ return elementIds;
1625
1627
  } : function useElementIds(_ref2) {
1626
1628
  var _ref2$id = _ref2.id,
1627
1629
  id = _ref2$id === void 0 ? "downshift-" + generateId() : _ref2$id,
@@ -1630,16 +1632,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1630
1632
  getItemId = _ref2.getItemId,
1631
1633
  toggleButtonId = _ref2.toggleButtonId,
1632
1634
  inputId = _ref2.inputId;
1633
- var elementIdsRef = useRef({
1634
- labelId: labelId || id + "-label",
1635
- menuId: menuId || id + "-menu",
1636
- getItemId: getItemId || function (index) {
1637
- return id + "-item-" + index;
1638
- },
1639
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1640
- inputId: inputId || id + "-input"
1641
- });
1642
- return elementIdsRef.current;
1635
+ var elementIds = useMemo(function () {
1636
+ return {
1637
+ labelId: labelId || id + "-label",
1638
+ menuId: menuId || id + "-menu",
1639
+ getItemId: getItemId || function (index) {
1640
+ return id + "-item-" + index;
1641
+ },
1642
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1643
+ inputId: inputId || id + "-input"
1644
+ };
1645
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1646
+ return elementIds;
1643
1647
  };
1644
1648
  function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
1645
1649
  var item, index;
@@ -1828,20 +1832,24 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1828
1832
  isTouchMove: false,
1829
1833
  isTouchEnd: false
1830
1834
  });
1835
+
1836
+ // the elements should be retrieved the moment they are required because these are refs - they can be mutated
1837
+ function getDownshiftElements() {
1838
+ return downshiftElementsRefs.map(function (ref) {
1839
+ return ref.current;
1840
+ });
1841
+ }
1831
1842
  useEffect(function () {
1832
1843
  if (!environment) {
1833
1844
  return noop;
1834
1845
  }
1835
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
1836
- return ref.current;
1837
- });
1838
1846
  function onMouseDown() {
1839
1847
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
1840
1848
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1841
1849
  }
1842
1850
  function onMouseUp(event) {
1843
1851
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1844
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
1852
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
1845
1853
  handleBlur();
1846
1854
  }
1847
1855
  }
@@ -1854,7 +1862,7 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1854
1862
  }
1855
1863
  function onTouchEnd(event) {
1856
1864
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
1857
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
1865
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
1858
1866
  handleBlur();
1859
1867
  }
1860
1868
  }
@@ -2466,7 +2474,9 @@ function useSelect(userProps) {
2466
2474
  }
2467
2475
  }, [dispatch, latest]), useMemo(function () {
2468
2476
  return [menuRef, toggleButtonRef];
2469
- }, [menuRef.current, toggleButtonRef.current]));
2477
+ },
2478
+ // dependencies can be left empty because refs are getting mutated
2479
+ []));
2470
2480
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2471
2481
  // Reset itemRefs on close.
2472
2482
  useEffect(function () {
@@ -3088,7 +3098,9 @@ function useCombobox(userProps) {
3088
3098
  }
3089
3099
  }, [dispatch, latest]), useMemo(function () {
3090
3100
  return [menuRef, toggleButtonRef, inputRef];
3091
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
3101
+ },
3102
+ // dependencies can be left empty because refs are getting mutated
3103
+ []));
3092
3104
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3093
3105
  // Reset itemRefs on close.
3094
3106
  useEffect(function () {
@@ -1506,16 +1506,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1506
1506
  if (!id) {
1507
1507
  id = reactId;
1508
1508
  }
1509
- var elementIdsRef = React.useRef({
1510
- labelId: labelId || id + "-label",
1511
- menuId: menuId || id + "-menu",
1512
- getItemId: getItemId || function (index) {
1513
- return id + "-item-" + index;
1514
- },
1515
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1516
- inputId: inputId || id + "-input"
1517
- });
1518
- return elementIdsRef.current;
1509
+ var elementIds = React.useMemo(function () {
1510
+ return {
1511
+ labelId: labelId || id + "-label",
1512
+ menuId: menuId || id + "-menu",
1513
+ getItemId: getItemId || function (index) {
1514
+ return id + "-item-" + index;
1515
+ },
1516
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1517
+ inputId: inputId || id + "-input"
1518
+ };
1519
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1520
+ return elementIds;
1519
1521
  } : function useElementIds(_ref2) {
1520
1522
  var _ref2$id = _ref2.id,
1521
1523
  id = _ref2$id === void 0 ? "downshift-" + generateId() : _ref2$id,
@@ -1524,16 +1526,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1524
1526
  getItemId = _ref2.getItemId,
1525
1527
  toggleButtonId = _ref2.toggleButtonId,
1526
1528
  inputId = _ref2.inputId;
1527
- var elementIdsRef = React.useRef({
1528
- labelId: labelId || id + "-label",
1529
- menuId: menuId || id + "-menu",
1530
- getItemId: getItemId || function (index) {
1531
- return id + "-item-" + index;
1532
- },
1533
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1534
- inputId: inputId || id + "-input"
1535
- });
1536
- return elementIdsRef.current;
1529
+ var elementIds = React.useMemo(function () {
1530
+ return {
1531
+ labelId: labelId || id + "-label",
1532
+ menuId: menuId || id + "-menu",
1533
+ getItemId: getItemId || function (index) {
1534
+ return id + "-item-" + index;
1535
+ },
1536
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1537
+ inputId: inputId || id + "-input"
1538
+ };
1539
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1540
+ return elementIds;
1537
1541
  };
1538
1542
  function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
1539
1543
  var item, index;
@@ -2317,7 +2321,9 @@ function useSelect(userProps) {
2317
2321
  }
2318
2322
  }, [dispatch, latest]), React.useMemo(function () {
2319
2323
  return [menuRef, toggleButtonRef];
2320
- }, [menuRef.current, toggleButtonRef.current]));
2324
+ },
2325
+ // dependencies can be left empty because refs are getting mutated
2326
+ []));
2321
2327
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2322
2328
  // Reset itemRefs on close.
2323
2329
  React.useEffect(function () {
@@ -2927,7 +2933,9 @@ function useCombobox(userProps) {
2927
2933
  }
2928
2934
  }, [dispatch, latest]), React.useMemo(function () {
2929
2935
  return [menuRef, toggleButtonRef, inputRef];
2930
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
2936
+ },
2937
+ // dependencies can be left empty because refs are getting mutated
2938
+ []));
2931
2939
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
2932
2940
  // Reset itemRefs on close.
2933
2941
  React.useEffect(function () {
@@ -1614,16 +1614,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1614
1614
  if (!id) {
1615
1615
  id = reactId;
1616
1616
  }
1617
- var elementIdsRef = React.useRef({
1618
- labelId: labelId || id + "-label",
1619
- menuId: menuId || id + "-menu",
1620
- getItemId: getItemId || function (index) {
1621
- return id + "-item-" + index;
1622
- },
1623
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1624
- inputId: inputId || id + "-input"
1625
- });
1626
- return elementIdsRef.current;
1617
+ var elementIds = React.useMemo(function () {
1618
+ return {
1619
+ labelId: labelId || id + "-label",
1620
+ menuId: menuId || id + "-menu",
1621
+ getItemId: getItemId || function (index) {
1622
+ return id + "-item-" + index;
1623
+ },
1624
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1625
+ inputId: inputId || id + "-input"
1626
+ };
1627
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1628
+ return elementIds;
1627
1629
  } : function useElementIds(_ref2) {
1628
1630
  var _ref2$id = _ref2.id,
1629
1631
  id = _ref2$id === void 0 ? "downshift-" + generateId() : _ref2$id,
@@ -1632,16 +1634,18 @@ var useElementIds = 'useId' in React // Avoid conditional useId call
1632
1634
  getItemId = _ref2.getItemId,
1633
1635
  toggleButtonId = _ref2.toggleButtonId,
1634
1636
  inputId = _ref2.inputId;
1635
- var elementIdsRef = React.useRef({
1636
- labelId: labelId || id + "-label",
1637
- menuId: menuId || id + "-menu",
1638
- getItemId: getItemId || function (index) {
1639
- return id + "-item-" + index;
1640
- },
1641
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1642
- inputId: inputId || id + "-input"
1643
- });
1644
- return elementIdsRef.current;
1637
+ var elementIds = React.useMemo(function () {
1638
+ return {
1639
+ labelId: labelId || id + "-label",
1640
+ menuId: menuId || id + "-menu",
1641
+ getItemId: getItemId || function (index) {
1642
+ return id + "-item-" + index;
1643
+ },
1644
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
1645
+ inputId: inputId || id + "-input"
1646
+ };
1647
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
1648
+ return elementIds;
1645
1649
  };
1646
1650
  function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
1647
1651
  var item, index;
@@ -1827,20 +1831,24 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1827
1831
  isTouchMove: false,
1828
1832
  isTouchEnd: false
1829
1833
  });
1834
+
1835
+ // the elements should be retrieved the moment they are required because these are refs - they can be mutated
1836
+ function getDownshiftElements() {
1837
+ return downshiftElementsRefs.map(function (ref) {
1838
+ return ref.current;
1839
+ });
1840
+ }
1830
1841
  React.useEffect(function () {
1831
1842
  if (!environment) {
1832
1843
  return noop;
1833
1844
  }
1834
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
1835
- return ref.current;
1836
- });
1837
1845
  function onMouseDown() {
1838
1846
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
1839
1847
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1840
1848
  }
1841
1849
  function onMouseUp(event) {
1842
1850
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1843
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
1851
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
1844
1852
  handleBlur();
1845
1853
  }
1846
1854
  }
@@ -1853,7 +1861,7 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1853
1861
  }
1854
1862
  function onTouchEnd(event) {
1855
1863
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
1856
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
1864
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
1857
1865
  handleBlur();
1858
1866
  }
1859
1867
  }
@@ -2465,7 +2473,9 @@ function useSelect(userProps) {
2465
2473
  }
2466
2474
  }, [dispatch, latest]), React.useMemo(function () {
2467
2475
  return [menuRef, toggleButtonRef];
2468
- }, [menuRef.current, toggleButtonRef.current]));
2476
+ },
2477
+ // dependencies can be left empty because refs are getting mutated
2478
+ []));
2469
2479
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2470
2480
  // Reset itemRefs on close.
2471
2481
  React.useEffect(function () {
@@ -3075,7 +3085,9 @@ function useCombobox(userProps) {
3075
3085
  }
3076
3086
  }, [dispatch, latest]), React.useMemo(function () {
3077
3087
  return [menuRef, toggleButtonRef, inputRef];
3078
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
3088
+ },
3089
+ // dependencies can be left empty because refs are getting mutated
3090
+ []));
3079
3091
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3080
3092
  // Reset itemRefs on close.
3081
3093
  React.useEffect(function () {
@@ -2953,16 +2953,18 @@
2953
2953
  if (!id) {
2954
2954
  id = reactId;
2955
2955
  }
2956
- var elementIdsRef = React.useRef({
2957
- labelId: labelId || id + "-label",
2958
- menuId: menuId || id + "-menu",
2959
- getItemId: getItemId || function (index) {
2960
- return id + "-item-" + index;
2961
- },
2962
- toggleButtonId: toggleButtonId || id + "-toggle-button",
2963
- inputId: inputId || id + "-input"
2964
- });
2965
- return elementIdsRef.current;
2956
+ var elementIds = React.useMemo(function () {
2957
+ return {
2958
+ labelId: labelId || id + "-label",
2959
+ menuId: menuId || id + "-menu",
2960
+ getItemId: getItemId || function (index) {
2961
+ return id + "-item-" + index;
2962
+ },
2963
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
2964
+ inputId: inputId || id + "-input"
2965
+ };
2966
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2967
+ return elementIds;
2966
2968
  } : function useElementIds(_ref2) {
2967
2969
  var _ref2$id = _ref2.id,
2968
2970
  id = _ref2$id === void 0 ? "downshift-" + generateId() : _ref2$id,
@@ -2971,16 +2973,18 @@
2971
2973
  getItemId = _ref2.getItemId,
2972
2974
  toggleButtonId = _ref2.toggleButtonId,
2973
2975
  inputId = _ref2.inputId;
2974
- var elementIdsRef = React.useRef({
2975
- labelId: labelId || id + "-label",
2976
- menuId: menuId || id + "-menu",
2977
- getItemId: getItemId || function (index) {
2978
- return id + "-item-" + index;
2979
- },
2980
- toggleButtonId: toggleButtonId || id + "-toggle-button",
2981
- inputId: inputId || id + "-input"
2982
- });
2983
- return elementIdsRef.current;
2976
+ var elementIds = React.useMemo(function () {
2977
+ return {
2978
+ labelId: labelId || id + "-label",
2979
+ menuId: menuId || id + "-menu",
2980
+ getItemId: getItemId || function (index) {
2981
+ return id + "-item-" + index;
2982
+ },
2983
+ toggleButtonId: toggleButtonId || id + "-toggle-button",
2984
+ inputId: inputId || id + "-input"
2985
+ };
2986
+ }, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
2987
+ return elementIds;
2984
2988
  };
2985
2989
  function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
2986
2990
  var item, index;
@@ -3169,20 +3173,24 @@
3169
3173
  isTouchMove: false,
3170
3174
  isTouchEnd: false
3171
3175
  });
3176
+
3177
+ // the elements should be retrieved the moment they are required because these are refs - they can be mutated
3178
+ function getDownshiftElements() {
3179
+ return downshiftElementsRefs.map(function (ref) {
3180
+ return ref.current;
3181
+ });
3182
+ }
3172
3183
  React.useEffect(function () {
3173
3184
  if (!environment) {
3174
3185
  return noop;
3175
3186
  }
3176
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
3177
- return ref.current;
3178
- });
3179
3187
  function onMouseDown() {
3180
3188
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
3181
3189
  mouseAndTouchTrackersRef.current.isMouseDown = true;
3182
3190
  }
3183
3191
  function onMouseUp(event) {
3184
3192
  mouseAndTouchTrackersRef.current.isMouseDown = false;
3185
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
3193
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
3186
3194
  handleBlur();
3187
3195
  }
3188
3196
  }
@@ -3195,7 +3203,7 @@
3195
3203
  }
3196
3204
  function onTouchEnd(event) {
3197
3205
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
3198
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
3206
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
3199
3207
  handleBlur();
3200
3208
  }
3201
3209
  }
@@ -3840,7 +3848,9 @@
3840
3848
  }
3841
3849
  }, [dispatch, latest]), React.useMemo(function () {
3842
3850
  return [menuRef, toggleButtonRef];
3843
- }, [menuRef.current, toggleButtonRef.current]));
3851
+ },
3852
+ // dependencies can be left empty because refs are getting mutated
3853
+ []));
3844
3854
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
3845
3855
  // Reset itemRefs on close.
3846
3856
  React.useEffect(function () {
@@ -4462,7 +4472,9 @@
4462
4472
  }
4463
4473
  }, [dispatch, latest]), React.useMemo(function () {
4464
4474
  return [menuRef, toggleButtonRef, inputRef];
4465
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
4475
+ },
4476
+ // dependencies can be left empty because refs are getting mutated
4477
+ []));
4466
4478
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
4467
4479
  // Reset itemRefs on close.
4468
4480
  React.useEffect(function () {