1- import React , { useMemo } from 'react' ;
1+ import React , { useEffect , useMemo } from 'react' ;
22
33import { CloseIcon } from './icons' ;
44import { Attachment as DefaultAttachment } from '../Attachment' ;
@@ -12,6 +12,7 @@ import { useTranslationContext } from '../../context/TranslationContext';
1212import { useStateStore } from '../../store' ;
1313import { useMessageComposer } from './hooks' ;
1414import { renderText as defaultRenderText } from '../Message/renderText' ;
15+ import { useMessageInputContext } from '../../context' ;
1516import type { MessageComposerState , TranslationLanguages } from 'stream-chat' ;
1617import type { MessageContextValue } from '../../context' ;
1718
@@ -56,6 +57,7 @@ export const QuotedMessagePreview = ({
5657 const { Attachment = DefaultAttachment , Avatar = DefaultAvatar } =
5758 useComponentContext ( 'QuotedMessagePreview' ) ;
5859 const { userLanguage } = useTranslationContext ( 'QuotedMessagePreview' ) ;
60+ const { focus, textareaRef } = useMessageInputContext ( ) ;
5961 const messageComposer = useMessageComposer ( ) ;
6062 const { quotedMessage } = useStateStore (
6163 messageComposer . state ,
@@ -82,6 +84,12 @@ export const QuotedMessagePreview = ({
8284
8385 const poll = quotedMessage ?. poll_id && client . polls . fromState ( quotedMessage . poll_id ) ;
8486
87+ useEffect ( ( ) => {
88+ const textareaIsFocused = textareaRef . current ?. matches ( ':focus' ) ;
89+ if ( ! textareaRef . current || textareaIsFocused || ! focus ) return ;
90+ textareaRef . current . focus ( ) ;
91+ } , [ focus , quotedMessage , textareaRef ] ) ;
92+
8593 if ( ! quotedMessageText && ! quotedMessageAttachments . length && ! poll ) return null ;
8694
8795 return (
0 commit comments