emoji-picker-react 4.9.0 → 4.9.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.9.0",
2
+ "version": "4.9.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -143,7 +143,8 @@ export function getElementInPrevRow(
143
143
 
144
144
  export function firstVisibleElementInContainer(
145
145
  parent: NullableElement,
146
- elements: HTMLElement[]
146
+ elements: HTMLElement[],
147
+ maxVisibilityDiffThreshold = 0
147
148
  ): NullableElement {
148
149
  if (!parent || !elements.length) {
149
150
  return null;
@@ -151,20 +152,27 @@ export function firstVisibleElementInContainer(
151
152
 
152
153
  const parentTop = parent.getBoundingClientRect().top;
153
154
  const parentBottom = parent.getBoundingClientRect().bottom;
154
-
155
- const parentTopWithLabel = parentTop + getLabelHight(parent);
155
+ const parentTopWithLabel = parentTop + getLabelHeight(parent);
156
156
 
157
157
  const visibleElements = elements.find(element => {
158
158
  const elementTop = element.getBoundingClientRect().top;
159
159
  const elementBottom = element.getBoundingClientRect().bottom;
160
+ const maxVisibilityDiffPixels =
161
+ element.clientHeight * maxVisibilityDiffThreshold;
160
162
 
161
- if (elementTop < parentTopWithLabel) {
163
+ const elementTopWithAllowedDiff = elementTop + maxVisibilityDiffPixels;
164
+ const elementBottomWithAllowedDiff =
165
+ elementBottom - maxVisibilityDiffPixels;
166
+
167
+ if (elementTopWithAllowedDiff < parentTopWithLabel) {
162
168
  return false;
163
169
  }
164
170
 
165
171
  return (
166
- (elementTop >= parentTop && elementTop <= parentBottom) ||
167
- (elementBottom >= parentTop && elementBottom <= parentBottom)
172
+ (elementTopWithAllowedDiff >= parentTop &&
173
+ elementTopWithAllowedDiff <= parentBottom) ||
174
+ (elementBottomWithAllowedDiff >= parentTop &&
175
+ elementBottomWithAllowedDiff <= parentBottom)
168
176
  );
169
177
  });
170
178
 
@@ -175,10 +183,18 @@ export function hasNextElementSibling(element: HTMLElement) {
175
183
  return !!element.nextElementSibling;
176
184
  }
177
185
 
178
- function getLabelHight(parentNode: HTMLElement) {
179
- return (
180
- parentNode
181
- .querySelector(asSelectors(ClassNames.label))
182
- ?.getBoundingClientRect().height ?? DEFAULT_LABEL_HEIGHT /* default */
186
+ function getLabelHeight(parentNode: HTMLElement) {
187
+ const labels = Array.from(
188
+ parentNode.querySelectorAll(asSelectors(ClassNames.label))
183
189
  );
190
+
191
+ for (const label of labels) {
192
+ const height = label.getBoundingClientRect().height;
193
+ // return height if label is not hidden
194
+ if (height > 0) {
195
+ return height;
196
+ }
197
+ }
198
+
199
+ return DEFAULT_LABEL_HEIGHT;
184
200
  }
@@ -21,7 +21,7 @@ export function scrollTo(root: NullableElement, top: number = 0) {
21
21
  }
22
22
 
23
23
  requestAnimationFrame(() => {
24
- $eprBody.scrollTop = top + 1;
24
+ $eprBody.scrollTop = top;
25
25
  });
26
26
  }
27
27
 
@@ -264,7 +264,7 @@ export function firstVisibleEmoji(parent: NullableElement) {
264
264
 
265
265
  const allEmojis = allVisibleEmojis(parent);
266
266
 
267
- return firstVisibleElementInContainer(parent, allEmojis);
267
+ return firstVisibleElementInContainer(parent, allEmojis, 0.1);
268
268
  }
269
269
 
270
270
  export function prevCategory(element: NullableElement): NullableElement {
@@ -46,7 +46,7 @@ export function ClickableEmojiButton({
46
46
  className
47
47
  )}
48
48
  data-unified={unified}
49
- aria-label={emojiNames[0]}
49
+ aria-label={getAriaLabel(emojiNames)}
50
50
  data-full-name={emojiNames}
51
51
  >
52
52
  {children}
@@ -54,6 +54,12 @@ export function ClickableEmojiButton({
54
54
  );
55
55
  }
56
56
 
57
+ function getAriaLabel(emojiNames: string[]) {
58
+ return emojiNames[0].match('flag-')
59
+ ? emojiNames[1] ?? emojiNames[0]
60
+ : emojiNames[0];
61
+ }
62
+
57
63
  const styles = stylesheet.create({
58
64
  emoji: {
59
65
  '.': ClassNames.emoji,