Skip to content

Commit 8a932f0

Browse files
committed
fix: return possibility to compose characters
1 parent c5dc373 commit 8a932f0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/components/TextareaComposer/TextareaComposer.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ export const TextareaComposer = ({
255255
const textarea = textareaRef.current;
256256
if (!textarea || isComposing) return;
257257

258+
/**
259+
* The textarea value has to be overridden outside the render cycle so that the events like compositionend can be triggered.
260+
* If we have overridden the value during the component rendering, the compositionend event would not be triggered, and
261+
* it would not be possible to type composed characters (ô).
262+
* On the other hand, just removing the value override via prop (value={text}) would not allow us to change the text based on
263+
* middleware results (e.g. replace characters with emojis)
264+
*/
265+
if (textarea.value !== text) {
266+
textarea.value = text;
267+
}
268+
258269
const length = textarea.value.length;
259270
const start = Math.max(0, Math.min(selection.start, length));
260271
const end = Math.max(start, Math.min(selection.end, length));
@@ -300,7 +311,6 @@ export const TextareaComposer = ({
300311
ref={(ref) => {
301312
textareaRef.current = ref;
302313
}}
303-
value={text}
304314
/>
305315
{/* todo: X document the layout change for the accessibility purpose (tabIndex) */}
306316
{!isComposing && (

0 commit comments

Comments
 (0)