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.
- package/README.md +15 -15
- package/dist/emoji-picker-react.cjs.development.js +34 -18
- package/dist/emoji-picker-react.cjs.development.js.map +1 -1
- package/dist/emoji-picker-react.cjs.production.min.js +1 -1
- package/dist/emoji-picker-react.cjs.production.min.js.map +1 -1
- package/dist/emoji-picker-react.esm.js +34 -18
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/dist/globals/doesBrowserSupportCssHas.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/header/Search/Search.tsx +1 -3
- package/src/globals/doesBrowserSupportCssHas.ts +16 -0
- package/src/hooks/useFilter.ts +24 -17
package/package.json
CHANGED
|
@@ -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;
|
package/src/hooks/useFilter.ts
CHANGED
|
@@ -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
|
-
|
|
81
|
+
if (doesBrowserSupportCssHas) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
const filter = filterRef.current;
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
return applySearch(nextValue);
|
|
86
|
-
}
|
|
88
|
+
const nextValue = inputValue.toLowerCase();
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
if (filter?.[nextValue] || nextValue.length <= 1) {
|
|
91
|
+
return applySearch(nextValue);
|
|
92
|
+
}
|
|
89
93
|
|
|
90
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|