emoji-picker-react 4.4.3 → 4.4.5

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.3",
2
+ "version": "4.4.5",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -15,7 +15,8 @@ export enum ClassNames {
15
15
  emojiPicker = 'EmojiPickerReact',
16
16
  open = 'epr-open',
17
17
  vertical = 'epr-vertical',
18
- horizontal = 'epr-horizontal'
18
+ horizontal = 'epr-horizontal',
19
+ variationPicker = 'epr-emoji-variation-picker'
19
20
  }
20
21
 
21
22
  export function asSelectors(...classNames: ClassNames[]): string {
@@ -2,6 +2,7 @@ import { useCallback } from 'react';
2
2
 
3
3
  import { useBodyRef } from '../components/context/ElementRefContext';
4
4
 
5
+ import { asSelectors, ClassNames } from './classNames';
5
6
  import {
6
7
  categoryLabelHeight,
7
8
  closestCategory,
@@ -52,7 +53,11 @@ export function useScrollTo() {
52
53
  }
53
54
 
54
55
  export function scrollEmojiAboveLabel(emoji: NullableElement) {
55
- if (!isEmojiBehindLabel(emoji)) {
56
+ if (!emoji || !isEmojiBehindLabel(emoji)) {
57
+ return;
58
+ }
59
+
60
+ if (emoji.closest(asSelectors(ClassNames.variationPicker))) {
56
61
  return;
57
62
  }
58
63
 
@@ -1,29 +1,30 @@
1
1
  import clsx from 'clsx';
2
2
  import * as React from 'react';
3
+ import { useEffect } from 'react';
3
4
 
4
5
  import { ClassNames } from '../../DomUtils/classNames';
5
- import { focusElement } from '../../DomUtils/focusElement';
6
+ import { focusFirstVisibleEmoji } from '../../DomUtils/keyboardNavigation';
6
7
  import {
7
8
  buttonFromTarget,
8
9
  elementHeight,
9
10
  emojiTrueOffsetTop,
10
- emojiTruOffsetLeft,
11
+ emojiTruOffsetLeft
11
12
  } from '../../DomUtils/selectors';
12
13
  import {
13
14
  useEmojiStyleConfig,
14
- useGetEmojiUrlConfig,
15
+ useGetEmojiUrlConfig
15
16
  } from '../../config/useConfig';
16
17
  import { asEmoji } from '../../dataUtils/asEmoji';
17
18
  import {
18
19
  emojiHasVariations,
19
20
  emojiUnified,
20
- emojiVariations,
21
+ emojiVariations
21
22
  } from '../../dataUtils/emojiSelectors';
22
23
  import {
23
24
  useAnchoredEmojiRef,
24
25
  useBodyRef,
25
26
  useSetAnchoredEmojiRef,
26
- useVariationPickerRef,
27
+ useVariationPickerRef
27
28
  } from '../context/ElementRefContext';
28
29
  import { useEmojiVariationPickerState } from '../context/PickerContext';
29
30
  import { ClickableEmoji } from '../emoji/Emoji';
@@ -31,7 +32,7 @@ import './EmojiVariationPicker.css';
31
32
 
32
33
  enum Direction {
33
34
  Up,
34
- Down,
35
+ Down
35
36
  }
36
37
 
37
38
  export function EmojiVariationPicker() {
@@ -39,6 +40,7 @@ export function EmojiVariationPicker() {
39
40
  const VariationPickerRef = useVariationPickerRef();
40
41
  const [emoji] = useEmojiVariationPickerState();
41
42
  const emojiStyle = useEmojiStyleConfig();
43
+
42
44
  const { getTop, getMenuDirection } = useVariationPickerTop(
43
45
  VariationPickerRef
44
46
  );
@@ -54,10 +56,17 @@ export function EmojiVariationPicker() {
54
56
  emojiHasVariations(emoji) &&
55
57
  button.classList.contains(ClassNames.emojiHasVariatios);
56
58
 
59
+ useEffect(() => {
60
+ if (!visible) {
61
+ return;
62
+ }
63
+
64
+ focusFirstVisibleEmoji(VariationPickerRef.current);
65
+ }, [VariationPickerRef, visible, AnchoredEmojiRef]);
66
+
57
67
  let top, pointerStyle;
58
68
 
59
69
  if (!visible && AnchoredEmojiRef.current) {
60
- focusElement(AnchoredEmojiRef.current);
61
70
  setAnchoredEmojiRef(null);
62
71
  } else {
63
72
  top = getTop();
@@ -69,9 +78,9 @@ export function EmojiVariationPicker() {
69
78
  return (
70
79
  <div
71
80
  ref={VariationPickerRef}
72
- className={clsx('epr-emoji-variation-picker', {
81
+ className={clsx(ClassNames.variationPicker, {
73
82
  visible,
74
- 'pointing-up': getMenuDirection() === Direction.Down,
83
+ 'pointing-up': getMenuDirection() === Direction.Down
75
84
  })}
76
85
  style={{ top }}
77
86
  >
@@ -79,7 +88,7 @@ export function EmojiVariationPicker() {
79
88
  ? [emojiUnified(safeEmoji)]
80
89
  .concat(emojiVariations(safeEmoji))
81
90
  .slice(0, 6)
82
- .map((unified) => (
91
+ .map(unified => (
83
92
  <ClickableEmoji
84
93
  key={unified}
85
94
  emoji={safeEmoji}
@@ -129,7 +138,7 @@ function useVariationPickerTop(
129
138
 
130
139
  return {
131
140
  getMenuDirection,
132
- getTop,
141
+ getTop
133
142
  };
134
143
 
135
144
  function getMenuDirection() {
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
 
3
+ import { focusElement } from '../../DomUtils/focusElement';
3
4
  import { NullableElement } from '../../DomUtils/selectors';
4
5
 
5
6
  export function ElementRefContextProvider({
@@ -71,6 +72,10 @@ export function useAnchoredEmojiRef() {
71
72
  export function useSetAnchoredEmojiRef(): (target: NullableElement) => void {
72
73
  const AnchoredEmojiRef = useAnchoredEmojiRef();
73
74
  return (target: NullableElement) => {
75
+ if (target === null && AnchoredEmojiRef.current !== null) {
76
+ focusElement(AnchoredEmojiRef.current);
77
+ }
78
+
74
79
  AnchoredEmojiRef.current = target;
75
80
  };
76
81
  }
@@ -154,7 +154,8 @@ function useSearchInputKeyboardEvents() {
154
154
  focusSkinTonePicker,
155
155
  goDownFromSearchInput,
156
156
  setSkinToneFanOpenState,
157
- BodyRef
157
+ BodyRef,
158
+ isSkinToneInSearch
158
159
  ]
159
160
  );
160
161
 
@@ -1,15 +1,10 @@
1
- import { focusFirstVisibleEmoji } from '../DomUtils/keyboardNavigation';
2
1
  import { emojiFromElement, NullableElement } from '../DomUtils/selectors';
3
- import {
4
- useSetAnchoredEmojiRef,
5
- useVariationPickerRef
6
- } from '../components/context/ElementRefContext';
2
+ import { useSetAnchoredEmojiRef } from '../components/context/ElementRefContext';
7
3
  import { useEmojiVariationPickerState } from '../components/context/PickerContext';
8
4
 
9
5
  export default function useSetVariationPicker() {
10
6
  const setAnchoredEmojiRef = useSetAnchoredEmojiRef();
11
7
  const [, setEmojiVariationPicker] = useEmojiVariationPickerState();
12
- const VariationPickerRef = useVariationPickerRef();
13
8
 
14
9
  return function setVariationPicker(element: NullableElement) {
15
10
  const [emoji] = emojiFromElement(element);
@@ -20,9 +15,5 @@ export default function useSetVariationPicker() {
20
15
 
21
16
  setAnchoredEmojiRef(element);
22
17
  setEmojiVariationPicker(emoji);
23
-
24
- requestAnimationFrame(() => {
25
- focusFirstVisibleEmoji(VariationPickerRef.current);
26
- });
27
18
  };
28
19
  }