downshift 9.0.10 → 9.0.11

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
@@ -1832,20 +1832,24 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1832
1832
  isTouchMove: false,
1833
1833
  isTouchEnd: false
1834
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
+ }
1835
1842
  React.useEffect(function () {
1836
1843
  if (!environment) {
1837
1844
  return noop;
1838
1845
  }
1839
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
1840
- return ref.current;
1841
- });
1842
1846
  function onMouseDown() {
1843
1847
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
1844
1848
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1845
1849
  }
1846
1850
  function onMouseUp(event) {
1847
1851
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1848
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
1852
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
1849
1853
  handleBlur();
1850
1854
  }
1851
1855
  }
@@ -1858,7 +1862,7 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1858
1862
  }
1859
1863
  function onTouchEnd(event) {
1860
1864
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
1861
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
1865
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
1862
1866
  handleBlur();
1863
1867
  }
1864
1868
  }
@@ -2470,7 +2474,9 @@ function useSelect(userProps) {
2470
2474
  }
2471
2475
  }, [dispatch, latest]), React.useMemo(function () {
2472
2476
  return [menuRef, toggleButtonRef];
2473
- }, [menuRef.current, toggleButtonRef.current]));
2477
+ },
2478
+ // dependencies can be left empty because refs are getting mutated
2479
+ []));
2474
2480
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2475
2481
  // Reset itemRefs on close.
2476
2482
  React.useEffect(function () {
@@ -3092,7 +3098,9 @@ function useCombobox(userProps) {
3092
3098
  }
3093
3099
  }, [dispatch, latest]), React.useMemo(function () {
3094
3100
  return [menuRef, toggleButtonRef, inputRef];
3095
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
3101
+ },
3102
+ // dependencies can be left empty because refs are getting mutated
3103
+ []));
3096
3104
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3097
3105
  // Reset itemRefs on close.
3098
3106
  React.useEffect(function () {
@@ -1828,20 +1828,24 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1828
1828
  isTouchMove: false,
1829
1829
  isTouchEnd: false
1830
1830
  });
1831
+
1832
+ // the elements should be retrieved the moment they are required because these are refs - they can be mutated
1833
+ function getDownshiftElements() {
1834
+ return downshiftElementsRefs.map(function (ref) {
1835
+ return ref.current;
1836
+ });
1837
+ }
1831
1838
  useEffect(function () {
1832
1839
  if (!environment) {
1833
1840
  return noop;
1834
1841
  }
1835
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
1836
- return ref.current;
1837
- });
1838
1842
  function onMouseDown() {
1839
1843
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
1840
1844
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1841
1845
  }
1842
1846
  function onMouseUp(event) {
1843
1847
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1844
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
1848
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
1845
1849
  handleBlur();
1846
1850
  }
1847
1851
  }
@@ -1854,7 +1858,7 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1854
1858
  }
1855
1859
  function onTouchEnd(event) {
1856
1860
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
1857
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
1861
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
1858
1862
  handleBlur();
1859
1863
  }
1860
1864
  }
@@ -2466,7 +2470,9 @@ function useSelect(userProps) {
2466
2470
  }
2467
2471
  }, [dispatch, latest]), useMemo(function () {
2468
2472
  return [menuRef, toggleButtonRef];
2469
- }, [menuRef.current, toggleButtonRef.current]));
2473
+ },
2474
+ // dependencies can be left empty because refs are getting mutated
2475
+ []));
2470
2476
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2471
2477
  // Reset itemRefs on close.
2472
2478
  useEffect(function () {
@@ -3088,7 +3094,9 @@ function useCombobox(userProps) {
3088
3094
  }
3089
3095
  }, [dispatch, latest]), useMemo(function () {
3090
3096
  return [menuRef, toggleButtonRef, inputRef];
3091
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
3097
+ },
3098
+ // dependencies can be left empty because refs are getting mutated
3099
+ []));
3092
3100
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3093
3101
  // Reset itemRefs on close.
3094
3102
  useEffect(function () {
@@ -2317,7 +2317,9 @@ function useSelect(userProps) {
2317
2317
  }
2318
2318
  }, [dispatch, latest]), React.useMemo(function () {
2319
2319
  return [menuRef, toggleButtonRef];
2320
- }, [menuRef.current, toggleButtonRef.current]));
2320
+ },
2321
+ // dependencies can be left empty because refs are getting mutated
2322
+ []));
2321
2323
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2322
2324
  // Reset itemRefs on close.
2323
2325
  React.useEffect(function () {
@@ -2927,7 +2929,9 @@ function useCombobox(userProps) {
2927
2929
  }
2928
2930
  }, [dispatch, latest]), React.useMemo(function () {
2929
2931
  return [menuRef, toggleButtonRef, inputRef];
2930
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
2932
+ },
2933
+ // dependencies can be left empty because refs are getting mutated
2934
+ []));
2931
2935
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
2932
2936
  // Reset itemRefs on close.
2933
2937
  React.useEffect(function () {
@@ -1827,20 +1827,24 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1827
1827
  isTouchMove: false,
1828
1828
  isTouchEnd: false
1829
1829
  });
1830
+
1831
+ // the elements should be retrieved the moment they are required because these are refs - they can be mutated
1832
+ function getDownshiftElements() {
1833
+ return downshiftElementsRefs.map(function (ref) {
1834
+ return ref.current;
1835
+ });
1836
+ }
1830
1837
  React.useEffect(function () {
1831
1838
  if (!environment) {
1832
1839
  return noop;
1833
1840
  }
1834
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
1835
- return ref.current;
1836
- });
1837
1841
  function onMouseDown() {
1838
1842
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
1839
1843
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1840
1844
  }
1841
1845
  function onMouseUp(event) {
1842
1846
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1843
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
1847
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
1844
1848
  handleBlur();
1845
1849
  }
1846
1850
  }
@@ -1853,7 +1857,7 @@ function useMouseAndTouchTracker(environment, handleBlur, downshiftElementsRefs)
1853
1857
  }
1854
1858
  function onTouchEnd(event) {
1855
1859
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
1856
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
1860
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
1857
1861
  handleBlur();
1858
1862
  }
1859
1863
  }
@@ -2465,7 +2469,9 @@ function useSelect(userProps) {
2465
2469
  }
2466
2470
  }, [dispatch, latest]), React.useMemo(function () {
2467
2471
  return [menuRef, toggleButtonRef];
2468
- }, [menuRef.current, toggleButtonRef.current]));
2472
+ },
2473
+ // dependencies can be left empty because refs are getting mutated
2474
+ []));
2469
2475
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2470
2476
  // Reset itemRefs on close.
2471
2477
  React.useEffect(function () {
@@ -3075,7 +3081,9 @@ function useCombobox(userProps) {
3075
3081
  }
3076
3082
  }, [dispatch, latest]), React.useMemo(function () {
3077
3083
  return [menuRef, toggleButtonRef, inputRef];
3078
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
3084
+ },
3085
+ // dependencies can be left empty because refs are getting mutated
3086
+ []));
3079
3087
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3080
3088
  // Reset itemRefs on close.
3081
3089
  React.useEffect(function () {
@@ -3169,20 +3169,24 @@
3169
3169
  isTouchMove: false,
3170
3170
  isTouchEnd: false
3171
3171
  });
3172
+
3173
+ // the elements should be retrieved the moment they are required because these are refs - they can be mutated
3174
+ function getDownshiftElements() {
3175
+ return downshiftElementsRefs.map(function (ref) {
3176
+ return ref.current;
3177
+ });
3178
+ }
3172
3179
  React.useEffect(function () {
3173
3180
  if (!environment) {
3174
3181
  return noop;
3175
3182
  }
3176
- var downshiftElements = downshiftElementsRefs.map(function (ref) {
3177
- return ref.current;
3178
- });
3179
3183
  function onMouseDown() {
3180
3184
  mouseAndTouchTrackersRef.current.isTouchEnd = false; // reset this one.
3181
3185
  mouseAndTouchTrackersRef.current.isMouseDown = true;
3182
3186
  }
3183
3187
  function onMouseUp(event) {
3184
3188
  mouseAndTouchTrackersRef.current.isMouseDown = false;
3185
- if (!targetWithinDownshift(event.target, downshiftElements, environment)) {
3189
+ if (!targetWithinDownshift(event.target, getDownshiftElements(), environment)) {
3186
3190
  handleBlur();
3187
3191
  }
3188
3192
  }
@@ -3195,7 +3199,7 @@
3195
3199
  }
3196
3200
  function onTouchEnd(event) {
3197
3201
  mouseAndTouchTrackersRef.current.isTouchEnd = true;
3198
- if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElements, environment, false)) {
3202
+ if (!mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, getDownshiftElements(), environment, false)) {
3199
3203
  handleBlur();
3200
3204
  }
3201
3205
  }
@@ -3840,7 +3844,9 @@
3840
3844
  }
3841
3845
  }, [dispatch, latest]), React.useMemo(function () {
3842
3846
  return [menuRef, toggleButtonRef];
3843
- }, [menuRef.current, toggleButtonRef.current]));
3847
+ },
3848
+ // dependencies can be left empty because refs are getting mutated
3849
+ []));
3844
3850
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
3845
3851
  // Reset itemRefs on close.
3846
3852
  React.useEffect(function () {
@@ -4462,7 +4468,9 @@
4462
4468
  }
4463
4469
  }, [dispatch, latest]), React.useMemo(function () {
4464
4470
  return [menuRef, toggleButtonRef, inputRef];
4465
- }, [menuRef.current, toggleButtonRef.current, inputRef.current]));
4471
+ },
4472
+ // dependencies can be left empty because refs are getting mutated
4473
+ []));
4466
4474
  var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
4467
4475
  // Reset itemRefs on close.
4468
4476
  React.useEffect(function () {