emoji-picker-react 4.13.2 → 4.13.3

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.
@@ -0,0 +1,2 @@
1
+ declare const browserSupportsCssHas: boolean;
2
+ export default browserSupportsCssHas;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.13.2",
2
+ "version": "4.13.3",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -64,9 +64,7 @@ export function Search() {
64
64
  placeholder={placeholder}
65
65
  onChange={event => {
66
66
  setInc(inc + 1);
67
- setTimeout(() => {
68
- onChange(event?.target?.value ?? value);
69
- });
67
+ onChange(event?.target?.value ?? value);
70
68
  }}
71
69
  ref={SearchInputRef}
72
70
  />
@@ -0,0 +1,16 @@
1
+ function doesBrowserSupportCssHas(): boolean {
2
+ // if env is not browser:
3
+ if (typeof window === 'undefined' || typeof window.CSS === 'undefined') {
4
+ return false;
5
+ }
6
+
7
+ try {
8
+ return CSS.supports('selector(:has(*))');
9
+ } catch (e) {
10
+ return false;
11
+ }
12
+ }
13
+
14
+ const browserSupportsCssHas = doesBrowserSupportCssHas();
15
+
16
+ export default browserSupportsCssHas;
@@ -11,6 +11,7 @@ import {
11
11
  import { useSearchResultsConfig } from '../config/useConfig';
12
12
  import { DataEmoji } from '../dataUtils/DataTypes';
13
13
  import { emojiNames } from '../dataUtils/emojiSelectors';
14
+ import doesBrowserSupportCssHas from '../globals/doesBrowserSupportCssHas';
14
15
 
15
16
  import { useFocusSearchInput } from './useFocus';
16
17
 
@@ -77,28 +78,34 @@ export function useFilter() {
77
78
  };
78
79
 
79
80
  function onChange(inputValue: string) {
80
- const filter = filterRef.current;
81
+ if (doesBrowserSupportCssHas) {
82
+ return;
83
+ }
81
84
 
82
- const nextValue = inputValue.toLowerCase();
85
+ setTimeout(() => {
86
+ const filter = filterRef.current;
83
87
 
84
- if (filter?.[nextValue] || nextValue.length <= 1) {
85
- return applySearch(nextValue);
86
- }
88
+ const nextValue = inputValue.toLowerCase();
87
89
 
88
- const longestMatch = findLongestMatch(nextValue, filter);
90
+ if (filter?.[nextValue] || nextValue.length <= 1) {
91
+ return applySearch(nextValue);
92
+ }
89
93
 
90
- if (!longestMatch) {
91
- // Can we even get here?
92
- // If so, we need to search among all emojis
93
- return applySearch(nextValue);
94
- }
94
+ const longestMatch = findLongestMatch(nextValue, filter);
95
95
 
96
- setFilterRef(current =>
97
- Object.assign(current, {
98
- [nextValue]: filterEmojiObjectByKeyword(longestMatch, nextValue)
99
- })
100
- );
101
- applySearch(nextValue);
96
+ if (!longestMatch) {
97
+ // Can we even get here?
98
+ // If so, we need to search among all emojis
99
+ return applySearch(nextValue);
100
+ }
101
+
102
+ setFilterRef(current =>
103
+ Object.assign(current, {
104
+ [nextValue]: filterEmojiObjectByKeyword(longestMatch, nextValue)
105
+ })
106
+ );
107
+ applySearch(nextValue);
108
+ });
102
109
  }
103
110
  }
104
111