Просмотр исходного кода

set search emoji input

https://youtrack.weseek.co.jp/issue/GW-7782
- Set search emoji input and trigger search
I Komang Mudana 4 лет назад
Родитель
Сommit
3dd334b89c
1 измененных файлов с 13 добавлено и 1 удалено
  1. 13 1
      packages/app/src/components/PageEditor/EmojiPicker.tsx

+ 13 - 1
packages/app/src/components/PageEditor/EmojiPicker.tsx

@@ -20,6 +20,18 @@ const EmojiPicker: FC<Props> = (props: Props) => {
     onClose, emojiSearchText, emojiPickerHelper, isOpen,
   } = props;
 
+  // Set search emoji input and trigger search
+  const searchEmoji = () => {
+    if (emojiSearchText !== null) {
+      const input = window.document.querySelector('[id^="emoji-mart-search"]') as HTMLInputElement;
+      const valueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value')?.set;
+      valueSetter?.call(input, emojiSearchText);
+      const event = new Event('input', { bubbles: true });
+      input.dispatchEvent(event);
+      input.focus();
+    }
+  };
+
   const selectEmoji = (emoji) => {
     if (emojiSearchText !== null) {
       emojiPickerHelper.addEmojiOnSearch(emoji);
@@ -72,7 +84,7 @@ const EmojiPicker: FC<Props> = (props: Props) => {
 
   const translation = getEmojiTranslation();
   return (
-    <Modal isOpen={isOpen} toggle={onClose}>
+    <Modal isOpen={isOpen} toggle={onClose} onOpened={searchEmoji}>
       <Picker
         onSelect={selectEmoji}
         i18n={translation}