downshift 5.2.1 → 5.2.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.
@@ -3543,25 +3543,26 @@
3543
3543
 
3544
3544
  var toggleButtonRef = react.useRef(null);
3545
3545
  var menuRef = react.useRef(null);
3546
- var isInitialMount = react.useRef(true);
3547
- var shouldScroll = react.useRef(true);
3548
- var clearTimeout = react.useRef(null);
3549
- var mouseAndTouchTrackers = react.useRef({
3546
+ var isInitialMountRef = react.useRef(true);
3547
+ var shouldScrollRef = react.useRef(true);
3548
+ var shouldBlurRef = react.useRef(true);
3549
+ var clearTimeoutRef = react.useRef(null);
3550
+ var mouseAndTouchTrackersRef = react.useRef({
3550
3551
  isMouseDown: false,
3551
3552
  isTouchMove: false
3552
3553
  });
3553
- var elementIds = react.useRef(getElementIds(props));
3554
+ var elementIdsRef = react.useRef(getElementIds(props));
3554
3555
  var previousResultCountRef = react.useRef(); // Some utils.
3555
3556
 
3556
3557
  var getItemNodeFromIndex = function (index) {
3557
- return environment.document.getElementById(elementIds.current.getItemId(index));
3558
+ return environment.document.getElementById(elementIdsRef.current.getItemId(index));
3558
3559
  }; // Effects.
3559
3560
 
3560
3561
  /* Sets a11y status message on changes in state. */
3561
3562
 
3562
3563
 
3563
3564
  react.useEffect(function () {
3564
- if (isInitialMount.current) {
3565
+ if (isInitialMountRef.current) {
3565
3566
  return;
3566
3567
  }
3567
3568
 
@@ -3582,7 +3583,7 @@
3582
3583
  /* Sets a11y status message on changes in selectedItem. */
3583
3584
 
3584
3585
  react.useEffect(function () {
3585
- if (isInitialMount.current) {
3586
+ if (isInitialMountRef.current) {
3586
3587
  return;
3587
3588
  }
3588
3589
 
@@ -3604,8 +3605,8 @@
3604
3605
 
3605
3606
  react.useEffect(function () {
3606
3607
  // init the clean function here as we need access to dispatch.
3607
- if (isInitialMount.current) {
3608
- clearTimeout.current = debounce(function (outerDispatch) {
3608
+ if (isInitialMountRef.current) {
3609
+ clearTimeoutRef.current = debounce(function (outerDispatch) {
3609
3610
  outerDispatch({
3610
3611
  type: FunctionSetInputValue,
3611
3612
  inputValue: ''
@@ -3617,13 +3618,13 @@
3617
3618
  return;
3618
3619
  }
3619
3620
 
3620
- clearTimeout.current(dispatch); // eslint-disable-next-line react-hooks/exhaustive-deps
3621
+ clearTimeoutRef.current(dispatch); // eslint-disable-next-line react-hooks/exhaustive-deps
3621
3622
  }, [inputValue]);
3622
3623
  /* Controls the focus on the menu or the toggle button. */
3623
3624
 
3624
3625
  react.useEffect(function () {
3625
3626
  // Don't focus menu on first render.
3626
- if (isInitialMount.current) {
3627
+ if (isInitialMountRef.current) {
3627
3628
  // Unless it was initialised as open.
3628
3629
  if ((initialIsOpen || defaultIsOpen || isOpen) && menuRef.current) {
3629
3630
  menuRef.current.focus();
@@ -3631,13 +3632,23 @@
3631
3632
 
3632
3633
  return;
3633
3634
  } // Focus menu on open.
3634
- // istanbul ignore next
3635
3635
 
3636
3636
 
3637
- if (isOpen && menuRef.current) {
3638
- menuRef.current.focus(); // Focus toggleButton on close.
3639
- } else if (environment.document.activeElement === menuRef.current && toggleButtonRef.current) {
3640
- toggleButtonRef.current.focus();
3637
+ if (isOpen) {
3638
+ // istanbul ignore else
3639
+ if (menuRef.current) {
3640
+ menuRef.current.focus();
3641
+ return;
3642
+ }
3643
+ } // Focus toggleButton on close, but on if was closed with (Shift+)Tab.
3644
+
3645
+
3646
+ if (environment.document.activeElement === menuRef.current) {
3647
+ // istanbul ignore else
3648
+ if (toggleButtonRef.current) {
3649
+ shouldBlurRef.current = false;
3650
+ toggleButtonRef.current.focus();
3651
+ }
3641
3652
  } // eslint-disable-next-line react-hooks/exhaustive-deps
3642
3653
 
3643
3654
  }, [isOpen]);
@@ -3648,15 +3659,15 @@
3648
3659
  return;
3649
3660
  }
3650
3661
 
3651
- if (shouldScroll.current === false) {
3652
- shouldScroll.current = true;
3662
+ if (shouldScrollRef.current === false) {
3663
+ shouldScrollRef.current = true;
3653
3664
  } else {
3654
3665
  scrollIntoView(getItemNodeFromIndex(highlightedIndex), menuRef.current);
3655
3666
  } // eslint-disable-next-line react-hooks/exhaustive-deps
3656
3667
 
3657
3668
  }, [highlightedIndex]);
3658
3669
  react.useEffect(function () {
3659
- if (isInitialMount.current) {
3670
+ if (isInitialMountRef.current) {
3660
3671
  return;
3661
3672
  }
3662
3673
 
@@ -3665,7 +3676,7 @@
3665
3676
  /* Make initial ref false. */
3666
3677
 
3667
3678
  react.useEffect(function () {
3668
- isInitialMount.current = false;
3679
+ isInitialMountRef.current = false;
3669
3680
  }, []);
3670
3681
  /* Add mouse/touch events to document. */
3671
3682
 
@@ -3673,11 +3684,11 @@
3673
3684
  // The same strategy for checking if a click occurred inside or outside downsift
3674
3685
  // as in downshift.js.
3675
3686
  var onMouseDown = function () {
3676
- mouseAndTouchTrackers.current.isMouseDown = true;
3687
+ mouseAndTouchTrackersRef.current.isMouseDown = true;
3677
3688
  };
3678
3689
 
3679
3690
  var onMouseUp = function (event) {
3680
- mouseAndTouchTrackers.current.isMouseDown = false;
3691
+ mouseAndTouchTrackersRef.current.isMouseDown = false;
3681
3692
 
3682
3693
  if (isOpen && !targetWithinDownshift(event.target, [toggleButtonRef.current, menuRef.current], environment.document)) {
3683
3694
  dispatch({
@@ -3687,15 +3698,15 @@
3687
3698
  };
3688
3699
 
3689
3700
  var onTouchStart = function () {
3690
- mouseAndTouchTrackers.current.isTouchMove = false;
3701
+ mouseAndTouchTrackersRef.current.isTouchMove = false;
3691
3702
  };
3692
3703
 
3693
3704
  var onTouchMove = function () {
3694
- mouseAndTouchTrackers.current.isTouchMove = true;
3705
+ mouseAndTouchTrackersRef.current.isTouchMove = true;
3695
3706
  };
3696
3707
 
3697
3708
  var onTouchEnd = function (event) {
3698
- if (isOpen && !mouseAndTouchTrackers.current.isTouchMove && !targetWithinDownshift(event.target, [toggleButtonRef.current, menuRef.current], environment.document, false)) {
3709
+ if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, [toggleButtonRef.current, menuRef.current], environment.document, false)) {
3699
3710
  dispatch({
3700
3711
  type: MenuBlur
3701
3712
  });
@@ -3799,7 +3810,13 @@
3799
3810
  };
3800
3811
 
3801
3812
  var menuHandleBlur = function () {
3802
- var shouldBlur = !mouseAndTouchTrackers.current.isMouseDown;
3813
+ // if the blur was a result of selection, we don't trigger this action.
3814
+ if (shouldBlurRef.current === false) {
3815
+ shouldBlurRef.current = true;
3816
+ return;
3817
+ }
3818
+
3819
+ var shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
3803
3820
  /* istanbul ignore else */
3804
3821
 
3805
3822
  if (shouldBlur) {
@@ -3840,7 +3857,7 @@
3840
3857
  return;
3841
3858
  }
3842
3859
 
3843
- shouldScroll.current = false;
3860
+ shouldScrollRef.current = false;
3844
3861
  dispatch({
3845
3862
  type: ItemMouseMove,
3846
3863
  index: index
@@ -3870,7 +3887,7 @@
3870
3887
 
3871
3888
  var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
3872
3889
  toggleButtonRef.current = toggleButtonNode;
3873
- }), _extends3.id = elementIds.current.toggleButtonId, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-expanded'] = isOpen, _extends3['aria-labelledby'] = elementIds.current.labelId + " " + elementIds.current.toggleButtonId, _extends3), rest);
3890
+ }), _extends3.id = elementIdsRef.current.toggleButtonId, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-expanded'] = isOpen, _extends3['aria-labelledby'] = elementIdsRef.current.labelId + " " + elementIdsRef.current.toggleButtonId, _extends3), rest);
3874
3891
 
3875
3892
  if (!rest.disabled) {
3876
3893
  toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
@@ -3881,8 +3898,8 @@
3881
3898
  },
3882
3899
  getLabelProps: function getLabelProps(labelProps) {
3883
3900
  return _extends({
3884
- id: elementIds.current.labelId,
3885
- htmlFor: elementIds.current.toggleButtonId
3901
+ id: elementIdsRef.current.labelId,
3902
+ htmlFor: elementIdsRef.current.toggleButtonId
3886
3903
  }, labelProps);
3887
3904
  },
3888
3905
  getMenuProps: function getMenuProps(_temp) {
@@ -3899,8 +3916,8 @@
3899
3916
 
3900
3917
  return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3901
3918
  menuRef.current = menuNode;
3902
- }), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.tabIndex = -1, _extends2), isOpen && highlightedIndex > -1 && {
3903
- 'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
3919
+ }), _extends2.id = elementIdsRef.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIdsRef.current.labelId, _extends2.tabIndex = -1, _extends2), isOpen && highlightedIndex > -1 && {
3920
+ 'aria-activedescendant': elementIdsRef.current.getItemId(highlightedIndex)
3904
3921
  }, {
3905
3922
  onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
3906
3923
  onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
@@ -3924,7 +3941,7 @@
3924
3941
  var itemProps = _extends({
3925
3942
  role: 'option',
3926
3943
  'aria-selected': "" + (itemIndex === highlightedIndex),
3927
- id: elementIds.current.getItemId(itemIndex)
3944
+ id: elementIdsRef.current.getItemId(itemIndex)
3928
3945
  }, rest);
3929
3946
 
3930
3947
  if (!rest.disabled) {