Skip to content

Commit bbe09e5

Browse files
authored
fix: make character composition possible in textarea (#2762)
1 parent ff43179 commit bbe09e5

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/components/MessageInput/__tests__/EditMessageForm.test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,14 @@ describe(`EditMessageForm`, () => {
12751275
customChannel,
12761276
customClient,
12771277
});
1278-
await quotedMessagePreviewIsDisplayedCorrectly(mainListMessage);
1278+
await quotedMessagePreviewIsDisplayedCorrectly(
1279+
messageWithQuotedMessage.quoted_message,
1280+
);
1281+
await waitFor(() => {
1282+
const textarea = screen.getByPlaceholderText(inputPlaceholder);
1283+
expect(textarea).toBeInTheDocument();
1284+
expect(textarea.value).toBe(messageWithQuotedMessage.text);
1285+
});
12791286
});
12801287

12811288
it('renders proper markdown (through default renderText fn)', async () => {
@@ -1344,7 +1351,14 @@ describe(`EditMessageForm`, () => {
13441351
customChannel,
13451352
);
13461353
});
1347-
await quotedMessagePreviewIsDisplayedCorrectly(mainListMessage);
1354+
await quotedMessagePreviewIsDisplayedCorrectly(
1355+
messageWithQuotedMessage.quoted_message,
1356+
);
1357+
await waitFor(() => {
1358+
const textarea = screen.getByPlaceholderText(inputPlaceholder);
1359+
expect(textarea).toBeInTheDocument();
1360+
expect(textarea.value).toBe(messageWithQuotedMessage.text);
1361+
});
13481362
});
13491363

13501364
it('is closed on original message delete', async () => {

src/components/TextareaComposer/TextareaComposer.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,19 @@ export const TextareaComposer = ({
259259
textareaRef.current.focus();
260260
}, [attachments, focus, quotedMessage, textareaRef]);
261261

262+
useEffect(() => {
263+
/**
264+
* The textarea value has to be overridden outside the render cycle so that the events like compositionend can be triggered.
265+
* If we have overridden the value during the component rendering, the compositionend event would not be triggered, and
266+
* it would not be possible to type composed characters (ô).
267+
* On the other hand, just removing the value override via prop (value={text}) would not allow us to change the text based on
268+
* middleware results (e.g. replace characters with emojis)
269+
*/
270+
const textarea = textareaRef.current;
271+
if (!textarea) return;
272+
textarea.value = text;
273+
}, [textareaRef, text]);
274+
262275
return (
263276
<div
264277
className={clsx(
@@ -295,7 +308,6 @@ export const TextareaComposer = ({
295308
ref={(ref) => {
296309
textareaRef.current = ref;
297310
}}
298-
value={text}
299311
/>
300312
{/* todo: X document the layout change for the accessibility purpose (tabIndex) */}
301313
{!isComposing && (

0 commit comments

Comments
 (0)