Skip to content

Commit 7c4e5a8

Browse files
authored
Ignore ENTER while in text composition mode (#5462)
* Ignore ENTER while in text composition mode * Update PR number
1 parent 3c5c640 commit 7c4e5a8

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
209209
- Improved focus management for scroll to end button
210210
- Fixed [#5439](https://github.com/microsoft/BotFramework-WebChat/issues/5439). Fixed batched livestream activities are not recognized in the same session, in PR [#5440](https://github.com/microsoft/BotFramework-WebChat/pull/5440), by [@compulim](https://github.com/compulim)
211211
- Fixed [#5452](https://github.com/microsoft/BotFramework-WebChat/issues/5452). With Fluent/Copilot theme, the typing indicator padding should not be squashed, in PR [#5453](https://github.com/microsoft/BotFramework-WebChat/pull/5453), by [@compulim](https://github.com/compulim)
212+
- Fixed [#5461](https://github.com/microsoft/BotFramework-WebChat/issues/5461). On macOS and Fluent skinpack applied, using Japanese IME to input some Japanese text should not send them immediately, in PR [#5462](https://github.com/microsoft/BotFramework-WebChat/pull/5462), by [@compulim](https://github.com/compulim)
212213

213214
# Removed
214215

packages/fluent-theme/src/components/sendBox/TextArea.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { hooks } from 'botframework-webchat-api';
22
import cx from 'classnames';
3-
import React, { forwardRef, Fragment, useCallback, type FormEventHandler, type KeyboardEventHandler } from 'react';
3+
import React, {
4+
forwardRef,
5+
Fragment,
6+
useCallback,
7+
useRef,
8+
type FormEventHandler,
9+
type KeyboardEventHandler
10+
} from 'react';
411
import { useStyles } from '../../styles';
512
import styles from './TextArea.module.css';
613

@@ -30,13 +37,22 @@ const TextArea = forwardRef<
3037
>((props, ref) => {
3138
const [uiState] = useUIState();
3239
const classNames = useStyles(styles);
40+
const isInCompositionRef = useRef<boolean>(false);
3341

3442
const disabled = uiState === 'disabled';
3543

44+
const handleCompositionEnd = useCallback(() => {
45+
isInCompositionRef.current = false;
46+
}, [isInCompositionRef]);
47+
48+
const handleCompositionStart = useCallback(() => {
49+
isInCompositionRef.current = true;
50+
}, [isInCompositionRef]);
51+
3652
const handleKeyDown = useCallback<KeyboardEventHandler<HTMLTextAreaElement>>(event => {
3753
// Shift+Enter adds a new line
3854
// Enter requests related form submission
39-
if (!event.shiftKey && event.key === 'Enter') {
55+
if (!event.shiftKey && event.key === 'Enter' && !isInCompositionRef.current) {
4056
event.preventDefault();
4157

4258
if ('form' in event.target && event.target.form instanceof HTMLFormElement) {
@@ -84,6 +100,8 @@ const TextArea = forwardRef<
84100
classNames['sendbox__text-area-shared']
85101
)}
86102
data-testid={props['data-testid']}
103+
onCompositionEnd={handleCompositionEnd}
104+
onCompositionStart={handleCompositionStart}
87105
onInput={props.onInput}
88106
onKeyDown={handleKeyDown}
89107
placeholder={props.placeholder}

0 commit comments

Comments
 (0)