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