Skip to content

Commit c4a41f7

Browse files
committed
docs: set emoji on ':' keystroke
1 parent 3ef7237 commit c4a41f7

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

docs/src/examples/EmojiEditor.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default function App() {
3232

3333
const suggestions = useMemo(() => {
3434
if (!open) return [];
35-
// A trailing ":" (as in ":smile:") is part of the query - drop it.
36-
const q = query.replace(/:$/, '').toLowerCase();
37-
return EMOJIS.filter(emoji => emoji.shortcode.startsWith(q));
35+
return EMOJIS.filter(emoji =>
36+
emoji.shortcode.startsWith(query.toLowerCase())
37+
);
3838
}, [open, query]);
3939

4040
const openPicker = () => {
@@ -50,6 +50,16 @@ export default function App() {
5050
const updateQuery = ({ text }: OnChangeMentionEvent) => {
5151
setOpen(true);
5252
setQuery(text);
53+
54+
if (text.endsWith(':')) {
55+
const strippedQuery = text.slice(0, text.length - 1);
56+
const autoChosenEmoji = EMOJIS.find(
57+
emoji => emoji.shortcode === strippedQuery
58+
);
59+
if (autoChosenEmoji) {
60+
pick(autoChosenEmoji);
61+
}
62+
}
5363
};
5464

5565
const pick = (emoji: Emoji) => {

0 commit comments

Comments
 (0)