@@ -9,7 +9,9 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
99import Textarea from 'react-textarea-autosize' ;
1010import { useMessageComposer } from '../MessageInput' ;
1111import type {
12+ AttachmentManagerState ,
1213 MessageComposerConfig ,
14+ MessageComposerState ,
1315 SearchSourceState ,
1416 TextComposerState ,
1517} from 'stream-chat' ;
@@ -36,6 +38,14 @@ const configStateSelector = (state: MessageComposerConfig) => ({
3638 enabled : state . text . enabled ,
3739} ) ;
3840
41+ const messageComposerStateSelector = ( state : MessageComposerState ) => ( {
42+ quotedMessage : state . quotedMessage ,
43+ } ) ;
44+
45+ const attachmentManagerStateSelector = ( state : AttachmentManagerState ) => ( {
46+ attachments : state . attachments ,
47+ } ) ;
48+
3949/**
4050 * isComposing prevents double submissions in Korean and other languages.
4151 * starting point for a read:
@@ -78,14 +88,14 @@ export const TextareaComposer = ({
7888 const {
7989 additionalTextareaProps,
8090 cooldownRemaining,
91+ focus,
8192 handleSubmit,
8293 maxRows : maxRowsContext ,
8394 minRows : minRowsContext ,
8495 onPaste,
8596 shouldSubmit : shouldSubmitContext ,
8697 textareaRef,
8798 } = useMessageInputContext ( ) ;
88-
8999 const maxRows = maxRowsProp ?? maxRowsContext ?? 1 ;
90100 const minRows = minRowsProp ?? minRowsContext ;
91101 const placeholder = placeholderProp ?? additionalTextareaProps ?. placeholder ;
@@ -99,6 +109,14 @@ export const TextareaComposer = ({
99109 ) ;
100110
101111 const { enabled } = useStateStore ( messageComposer . configState , configStateSelector ) ;
112+ const { quotedMessage } = useStateStore (
113+ messageComposer . state ,
114+ messageComposerStateSelector ,
115+ ) ;
116+ const { attachments } = useStateStore (
117+ messageComposer . attachmentManager . state ,
118+ attachmentManagerStateSelector ,
119+ ) ;
102120
103121 const { isLoadingItems } =
104122 useStateStore ( suggestions ?. searchSource . state , searchSourceStateSelector ) ?? { } ;
@@ -235,6 +253,12 @@ export const TextareaComposer = ({
235253 }
236254 } , [ textComposer . suggestions ] ) ;
237255
256+ useEffect ( ( ) => {
257+ const textareaIsFocused = textareaRef . current ?. matches ( ':focus' ) ;
258+ if ( ! textareaRef . current || textareaIsFocused || ! focus ) return ;
259+ textareaRef . current . focus ( ) ;
260+ } , [ attachments , focus , quotedMessage , textareaRef ] ) ;
261+
238262 return (
239263 < div
240264 className = { clsx (
0 commit comments