emoji-picker-react 4.20.7 → 4.20.8

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.
@@ -27362,11 +27362,16 @@ function useIsSearchMode() {
27362
27362
  return !!searchTerm;
27363
27363
  }
27364
27364
 
27365
- function focusElement(element) {
27365
+ function focusElement(element, shouldFocus) {
27366
27366
  if (!element) {
27367
27367
  return;
27368
27368
  }
27369
27369
  requestAnimationFrame(function () {
27370
+ // Rechecked here rather than at call time: focus may have moved in the
27371
+ // meantime (e.g. hover scheduled focus, then the user tabbed out).
27372
+ if (shouldFocus && !shouldFocus()) {
27373
+ return;
27374
+ }
27370
27375
  element.focus();
27371
27376
  });
27372
27377
  }
@@ -29965,18 +29970,9 @@ var styles$a = /*#__PURE__*/stylesheet.create({
29965
29970
  }
29966
29971
  });
29967
29972
 
29968
- function detectEmojyPartiallyBelowFold(button, bodyRef) {
29969
- if (!button || !bodyRef) {
29970
- return 0;
29971
- }
29972
- var buttonRect = button.getBoundingClientRect();
29973
- var bodyRect = bodyRef.getBoundingClientRect();
29974
- // If the element is obscured by at least half of its size
29975
- return bodyRect.height - (buttonRect.y - bodyRect.y);
29976
- }
29977
-
29978
29973
  function useEmojiPreviewEvents(allow, setPreviewEmoji) {
29979
29974
  var BodyRef = useBodyRef();
29975
+ var PickerMainRef = usePickerMainRef();
29980
29976
  var isMouseDisallowed = useIsMouseDisallowed();
29981
29977
  var allowMouseMove = useAllowMouseMove();
29982
29978
  useEffect(function () {
@@ -30028,15 +30024,38 @@ function useEmojiPreviewEvents(allow, setPreviewEmoji) {
30028
30024
  return;
30029
30025
  }
30030
30026
  var button = buttonFromTarget(e.target);
30031
- if (button) {
30032
- var belowFoldByPx = detectEmojyPartiallyBelowFold(button, bodyRef);
30033
- var buttonHeight = button.getBoundingClientRect().height;
30034
- if (belowFoldByPx < buttonHeight) {
30035
- return handlePartiallyVisibleElementFocus(button, setPreviewEmoji);
30036
- }
30037
- focusElement(button);
30027
+ if (!button) {
30028
+ return;
30029
+ }
30030
+ var _allUnifiedFromEmojiE2 = allUnifiedFromEmojiElement(button),
30031
+ unified = _allUnifiedFromEmojiE2.unified,
30032
+ originalUnified = _allUnifiedFromEmojiE2.originalUnified;
30033
+ if (!unified || !originalUnified) {
30034
+ return;
30035
+ }
30036
+ setPreviewEmoji({
30037
+ unified: unified,
30038
+ originalUnified: originalUnified
30039
+ });
30040
+ // Let arrow-key navigation continue from the hovered emoji, but only
30041
+ // when focus is already inside the picker (or nowhere meaningful).
30042
+ // Pulling focus out of an external element steals the caret from
30043
+ // host-app inputs (issue #320). The guard runs again inside the
30044
+ // deferred callback in case focus moved out after this event.
30045
+ if (!isExternalElementFocused()) {
30046
+ focusElement(button, function () {
30047
+ return !isExternalElementFocused();
30048
+ });
30038
30049
  }
30039
30050
  }
30051
+ function isExternalElementFocused() {
30052
+ var _PickerMainRef$curren;
30053
+ var active = document.activeElement;
30054
+ if (!active || active === document.body || active === document.documentElement) {
30055
+ return false;
30056
+ }
30057
+ return !((_PickerMainRef$curren = PickerMainRef.current) != null && _PickerMainRef$curren.contains(active));
30058
+ }
30040
30059
  return function () {
30041
30060
  bodyRef == null ? void 0 : bodyRef.removeEventListener('mouseover', onMouseOver);
30042
30061
  bodyRef == null ? void 0 : bodyRef.removeEventListener('mouseout', onLeave);
@@ -30046,20 +30065,6 @@ function useEmojiPreviewEvents(allow, setPreviewEmoji) {
30046
30065
  };
30047
30066
  }, [BodyRef, allow, setPreviewEmoji, isMouseDisallowed, allowMouseMove]);
30048
30067
  }
30049
- function handlePartiallyVisibleElementFocus(button, setPreviewEmoji) {
30050
- var _document$activeEleme;
30051
- var _allUnifiedFromEmojiE2 = allUnifiedFromEmojiElement(button),
30052
- unified = _allUnifiedFromEmojiE2.unified,
30053
- originalUnified = _allUnifiedFromEmojiE2.originalUnified;
30054
- if (!unified || !originalUnified) {
30055
- return;
30056
- }
30057
- (_document$activeEleme = document.activeElement) == null ? void 0 : _document$activeEleme.blur == null ? void 0 : _document$activeEleme.blur();
30058
- setPreviewEmoji({
30059
- unified: unified,
30060
- originalUnified: originalUnified
30061
- });
30062
- }
30063
30068
 
30064
30069
  var _stylesheet$create;
30065
30070
  var FlexDirection;