From 1e88ad8226ea2a9592864b0267c8698f12c5defb Mon Sep 17 00:00:00 2001 From: Nguyen Luc Date: Fri, 17 Apr 2026 09:19:13 +0700 Subject: [PATCH 1/2] Auto focus chat input after sending buzz mesage --- .../ModalInputMessageBuzz/index.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx b/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx index 98e0ed9e13..0848fa8492 100644 --- a/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx +++ b/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx @@ -3,7 +3,7 @@ import type { DirectEntity } from '@mezon/store'; import { selectTheme } from '@mezon/store'; import { Icons } from '@mezon/ui'; import type { IEmojiOnMessage, RequestInput } from '@mezon/utils'; -import { EmojiPlaces, MAX_LENGTH_MESSAGE_BUZZ, ThemeApp, TypeMessage, generateE2eId } from '@mezon/utils'; +import { CHANNEL_INPUT_ID, EmojiPlaces, GENERAL_INPUT_ID, MAX_LENGTH_MESSAGE_BUZZ, ThemeApp, TypeMessage, generateE2eId } from '@mezon/utils'; import type { ApiChannelDescription } from 'mezon-js/api'; import { useCallback, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -85,6 +85,24 @@ const ModalInputMessageBuzz: React.FC = ({ currentCh if (inputRequest.content.trim()) { sendMessage({ t: inputRequest.content.trim(), ej: emojiArr }, [], [], [], undefined, undefined, undefined, TypeMessage.MessageBuzz); handleClosePopup(); + setTimeout(() => { + const editor = document.getElementById(CHANNEL_INPUT_ID) || document.getElementById(GENERAL_INPUT_ID); + if (editor) { + editor.focus(); + if (typeof window.getSelection !== 'undefined' && typeof document.createRange !== 'undefined') { + try { + const range = document.createRange(); + range.selectNodeContents(editor); + range.collapse(false); + const sel = window.getSelection(); + sel?.removeAllRanges(); + sel?.addRange(range); + } catch (e) { + // ignore + } + } + } + }, 100); } }, [handleClosePopup, inputRequest.content, inputRequest.mentionRaw, sendMessage]); From 7a7b3f304c0499077c467f703ae0a8a116a45110 Mon Sep 17 00:00:00 2001 From: Nguyen Luc Date: Mon, 20 Apr 2026 00:12:12 +0700 Subject: [PATCH 2/2] fix comment --- .../ModalInputMessageBuzz/index.tsx | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx b/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx index 0848fa8492..2e8709ed81 100644 --- a/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx +++ b/libs/components/src/lib/components/ModalInputMessageBuzz/index.tsx @@ -72,6 +72,25 @@ const ModalInputMessageBuzz: React.FC = ({ currentCh setInputRequest({ ...newRequest }); }; + const focusChatInput = () => { + const editor = document.getElementById(CHANNEL_INPUT_ID) || document.getElementById(GENERAL_INPUT_ID); + if (editor) { + editor.focus(); + if (typeof window.getSelection !== 'undefined' && typeof document.createRange !== 'undefined') { + try { + const range = document.createRange(); + range.selectNodeContents(editor); + range.collapse(false); + const sel = window.getSelection(); + sel?.removeAllRanges(); + sel?.addRange(range); + } catch (e) { + // ignore + } + } + } + }; + const handleSendBuzzMsg = useCallback(() => { const emojiArr: IEmojiOnMessage[] = []; inputRequest.mentionRaw?.forEach((item) => { @@ -85,24 +104,9 @@ const ModalInputMessageBuzz: React.FC = ({ currentCh if (inputRequest.content.trim()) { sendMessage({ t: inputRequest.content.trim(), ej: emojiArr }, [], [], [], undefined, undefined, undefined, TypeMessage.MessageBuzz); handleClosePopup(); - setTimeout(() => { - const editor = document.getElementById(CHANNEL_INPUT_ID) || document.getElementById(GENERAL_INPUT_ID); - if (editor) { - editor.focus(); - if (typeof window.getSelection !== 'undefined' && typeof document.createRange !== 'undefined') { - try { - const range = document.createRange(); - range.selectNodeContents(editor); - range.collapse(false); - const sel = window.getSelection(); - sel?.removeAllRanges(); - sel?.addRange(range); - } catch (e) { - // ignore - } - } - } - }, 100); + requestAnimationFrame(() => { + focusChatInput(); + }); } }, [handleClosePopup, inputRequest.content, inputRequest.mentionRaw, sendMessage]);