downshift 7.6.0 → 7.6.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.
package/README.md CHANGED
@@ -70,6 +70,15 @@ to the hook you need by using the links in the list above.
70
70
  For examples on how to use the hooks or the Downshift component, check out our
71
71
  [docsite][docsite]!
72
72
 
73
+ **🚨 Use the Downshift hooks 🚨**
74
+
75
+ If you are new to the library, consider the _useSelect_ and _useCombobox_ hooks
76
+ as the first option. As mentioned above, the hooks benefit from the updated ARIA
77
+ patterns and are actively maintained and improved. If there are use cases that
78
+ are supported by the _Downshift_ component and not by the hooks, please create
79
+ an issue in our repo. The _Downshift_ component is going to be removed
80
+ completely once the hooks become mature.
81
+
73
82
  ### Downshift
74
83
 
75
84
  This is a component that controls user interactions and state for you so you can
@@ -1498,7 +1507,7 @@ MIT
1498
1507
  [react-training]: https://reacttraining.com/
1499
1508
  [advanced-react]: https://courses.reacttraining.com/courses/enrolled/200086
1500
1509
  [use-a-render-prop]:
1501
- https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce
1510
+ https://medium.com/@mjackson/use-a-render-prop-50de598f11ce
1502
1511
  [semver]: http://semver.org/
1503
1512
  [hooks-readme]: https://github.com/downshift-js/downshift/blob/master/src/hooks
1504
1513
  [useselect-readme]:
@@ -3068,7 +3068,7 @@ function useCombobox(userProps) {
3068
3068
  itemRefs.current = {};
3069
3069
  } else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
3070
3070
  var _inputRef$current;
3071
- inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3071
+ inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3072
3072
  }
3073
3073
  }, [isOpen, environment]);
3074
3074
 
@@ -3285,9 +3285,10 @@ function useCombobox(userProps) {
3285
3285
  var inputHandleBlur = function inputHandleBlur(event) {
3286
3286
  /* istanbul ignore else */
3287
3287
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3288
+ var isBlurByTabChange = event.relatedTarget === null && environment.document.activeElement !== environment.document.body;
3288
3289
  dispatch({
3289
3290
  type: InputBlur,
3290
- selectItem: event.relatedTarget !== null
3291
+ selectItem: !isBlurByTabChange
3291
3292
  });
3292
3293
  }
3293
3294
  };
@@ -3309,7 +3310,7 @@ function useCombobox(userProps) {
3309
3310
  return _extends__default["default"]((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3310
3311
  inputRef.current = inputNode;
3311
3312
  }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
3312
- }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3313
+ }, [setGetterPropCallInfo, latest, elementIds, inputKeyDownHandlers, dispatch, mouseAndTouchTrackersRef, environment]);
3313
3314
 
3314
3315
  // returns
3315
3316
  var toggleMenu = react.useCallback(function () {
@@ -3055,7 +3055,7 @@ function useCombobox(userProps) {
3055
3055
  itemRefs.current = {};
3056
3056
  } else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
3057
3057
  var _inputRef$current;
3058
- inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3058
+ inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3059
3059
  }
3060
3060
  }, [isOpen, environment]);
3061
3061
 
@@ -3272,9 +3272,10 @@ function useCombobox(userProps) {
3272
3272
  var inputHandleBlur = function inputHandleBlur(event) {
3273
3273
  /* istanbul ignore else */
3274
3274
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3275
+ var isBlurByTabChange = event.relatedTarget === null && environment.document.activeElement !== environment.document.body;
3275
3276
  dispatch({
3276
3277
  type: InputBlur,
3277
- selectItem: event.relatedTarget !== null
3278
+ selectItem: !isBlurByTabChange
3278
3279
  });
3279
3280
  }
3280
3281
  };
@@ -3296,7 +3297,7 @@ function useCombobox(userProps) {
3296
3297
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3297
3298
  inputRef.current = inputNode;
3298
3299
  }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
3299
- }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3300
+ }, [setGetterPropCallInfo, latest, elementIds, inputKeyDownHandlers, dispatch, mouseAndTouchTrackersRef, environment]);
3300
3301
 
3301
3302
  // returns
3302
3303
  var toggleMenu = useCallback(function () {
@@ -2990,7 +2990,7 @@ function useCombobox(userProps) {
2990
2990
  itemRefs.current = {};
2991
2991
  } else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
2992
2992
  var _inputRef$current;
2993
- inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
2993
+ inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
2994
2994
  }
2995
2995
  }, [isOpen, environment]);
2996
2996
 
@@ -3207,9 +3207,10 @@ function useCombobox(userProps) {
3207
3207
  var inputHandleBlur = function inputHandleBlur(event) {
3208
3208
  /* istanbul ignore else */
3209
3209
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3210
+ var isBlurByTabChange = event.relatedTarget === null && environment.document.activeElement !== environment.document.body;
3210
3211
  dispatch({
3211
3212
  type: InputBlur,
3212
- selectItem: event.relatedTarget !== null
3213
+ selectItem: !isBlurByTabChange
3213
3214
  });
3214
3215
  }
3215
3216
  };
@@ -3243,7 +3244,7 @@ function useCombobox(userProps) {
3243
3244
  return _extends__default["default"]((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3244
3245
  inputRef.current = inputNode;
3245
3246
  }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
3246
- }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3247
+ }, [setGetterPropCallInfo, latest, elementIds, inputKeyDownHandlers, dispatch, mouseAndTouchTrackersRef, environment]);
3247
3248
 
3248
3249
  // returns
3249
3250
  var toggleMenu = react.useCallback(function () {
@@ -3050,7 +3050,7 @@ function useCombobox(userProps) {
3050
3050
  itemRefs.current = {};
3051
3051
  } else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
3052
3052
  var _inputRef$current;
3053
- inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3053
+ inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3054
3054
  }
3055
3055
  }, [isOpen, environment]);
3056
3056
 
@@ -3267,9 +3267,10 @@ function useCombobox(userProps) {
3267
3267
  var inputHandleBlur = function inputHandleBlur(event) {
3268
3268
  /* istanbul ignore else */
3269
3269
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3270
+ var isBlurByTabChange = event.relatedTarget === null && environment.document.activeElement !== environment.document.body;
3270
3271
  dispatch({
3271
3272
  type: InputBlur,
3272
- selectItem: event.relatedTarget !== null
3273
+ selectItem: !isBlurByTabChange
3273
3274
  });
3274
3275
  }
3275
3276
  };
@@ -3291,7 +3292,7 @@ function useCombobox(userProps) {
3291
3292
  return _extends__default["default"]((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3292
3293
  inputRef.current = inputNode;
3293
3294
  }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
3294
- }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3295
+ }, [setGetterPropCallInfo, latest, elementIds, inputKeyDownHandlers, dispatch, mouseAndTouchTrackersRef, environment]);
3295
3296
 
3296
3297
  // returns
3297
3298
  var toggleMenu = react.useCallback(function () {
@@ -3314,30 +3314,35 @@
3314
3314
  }
3315
3315
  /* eslint-enable complexity */
3316
3316
 
3317
- /******************************************************************************
3318
- Copyright (c) Microsoft Corporation.
3319
-
3320
- Permission to use, copy, modify, and/or distribute this software for any
3321
- purpose with or without fee is hereby granted.
3322
-
3323
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3324
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3325
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3326
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3327
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3328
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3329
- PERFORMANCE OF THIS SOFTWARE.
3330
- ***************************************************************************** */
3331
-
3332
- var __assign = function() {
3333
- __assign = Object.assign || function __assign(t) {
3334
- for (var s, i = 1, n = arguments.length; i < n; i++) {
3335
- s = arguments[i];
3336
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
3337
- }
3338
- return t;
3339
- };
3340
- return __assign.apply(this, arguments);
3317
+ /******************************************************************************
3318
+ Copyright (c) Microsoft Corporation.
3319
+
3320
+ Permission to use, copy, modify, and/or distribute this software for any
3321
+ purpose with or without fee is hereby granted.
3322
+
3323
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3324
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3325
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3326
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3327
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3328
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3329
+ PERFORMANCE OF THIS SOFTWARE.
3330
+ ***************************************************************************** */
3331
+
3332
+ var __assign = function() {
3333
+ __assign = Object.assign || function __assign(t) {
3334
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3335
+ s = arguments[i];
3336
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
3337
+ }
3338
+ return t;
3339
+ };
3340
+ return __assign.apply(this, arguments);
3341
+ };
3342
+
3343
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3344
+ var e = new Error(message);
3345
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3341
3346
  };
3342
3347
 
3343
3348
  function getItemIndexByCharacterKey(_a) {
@@ -4380,7 +4385,7 @@
4380
4385
  itemRefs.current = {};
4381
4386
  } else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
4382
4387
  var _inputRef$current;
4383
- inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
4388
+ inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
4384
4389
  }
4385
4390
  }, [isOpen, environment]);
4386
4391
 
@@ -4597,9 +4602,10 @@
4597
4602
  var inputHandleBlur = function inputHandleBlur(event) {
4598
4603
  /* istanbul ignore else */
4599
4604
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
4605
+ var isBlurByTabChange = event.relatedTarget === null && environment.document.activeElement !== environment.document.body;
4600
4606
  dispatch({
4601
4607
  type: InputBlur,
4602
- selectItem: event.relatedTarget !== null
4608
+ selectItem: !isBlurByTabChange
4603
4609
  });
4604
4610
  }
4605
4611
  };
@@ -4621,7 +4627,7 @@
4621
4627
  return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
4622
4628
  inputRef.current = inputNode;
4623
4629
  }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = rest && rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
4624
- }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
4630
+ }, [setGetterPropCallInfo, latest, elementIds, inputKeyDownHandlers, dispatch, mouseAndTouchTrackersRef, environment]);
4625
4631
 
4626
4632
  // returns
4627
4633
  var toggleMenu = react.useCallback(function () {