Skip to content

Commit d8bd671

Browse files
committed
Merge branch 'master' into fix/text-composer-composed-symbols
# Conflicts: # src/components/TextareaComposer/TextareaComposer.tsx
2 parents 756c1ff + e6d5a7f commit d8bd671

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/components/MessageInput/EditMessageForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const EditMessageModal = ({
8686
>
8787
<MessageInput
8888
clearEditingState={clearEditingState}
89+
focus
8990
hideSendButton
9091
Input={EditMessageInput}
9192
{...additionalMessageInputProps}

src/components/Poll/PollCreationDialog/MultipleAnswersField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const MultipleAnswersField = () => {
6767
);
6868
}}
6969
placeholder={t('Maximum number of votes (from 2 to 10)')}
70-
type='number'
70+
type='text'
7171
value={max_votes_allowed}
7272
/>
7373
</div>

src/components/TextareaComposer/TextareaComposer.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
99
import Textarea from 'react-textarea-autosize';
1010
import { useMessageComposer } from '../MessageInput';
1111
import 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
useEffect(() => {
239263
/**
240264
* The textarea value has to be overridden outside the render cycle so that the events like compositionend can be triggered.

0 commit comments

Comments
 (0)