@@ -2,7 +2,6 @@ import { useState, useEffect, useContext } from "react";
2
2
import { Stack , TextField } from "@fluentui/react" ;
3
3
import { Button , Tooltip } from "@fluentui/react-components" ;
4
4
import { Send28Filled } from "@fluentui/react-icons" ;
5
- import { useMsal } from "@azure/msal-react" ;
6
5
7
6
import styles from "./QuestionInput.module.css" ;
8
7
import { SpeechInput } from "./SpeechInput" ;
@@ -21,6 +20,7 @@ interface Props {
21
20
export const QuestionInput = ( { onSend, disabled, placeholder, clearOnSend, initQuestion, showSpeechInput } : Props ) => {
22
21
const [ question , setQuestion ] = useState < string > ( "" ) ;
23
22
const { loggedIn } = useContext ( LoginContext ) ;
23
+ const [ isComposing , setIsComposing ] = useState ( false ) ;
24
24
25
25
useEffect ( ( ) => {
26
26
initQuestion && setQuestion ( initQuestion ) ;
@@ -39,12 +39,21 @@ export const QuestionInput = ({ onSend, disabled, placeholder, clearOnSend, init
39
39
} ;
40
40
41
41
const onEnterPress = ( ev : React . KeyboardEvent < Element > ) => {
42
+ if ( isComposing ) return ;
43
+
42
44
if ( ev . key === "Enter" && ! ev . shiftKey ) {
43
45
ev . preventDefault ( ) ;
44
46
sendQuestion ( ) ;
45
47
}
46
48
} ;
47
49
50
+ const handleCompositionStart = ( ) => {
51
+ setIsComposing ( true ) ;
52
+ } ;
53
+ const handleCompositionEnd = ( ) => {
54
+ setIsComposing ( false ) ;
55
+ } ;
56
+
48
57
const onQuestionChange = ( _ev : React . FormEvent < HTMLInputElement | HTMLTextAreaElement > , newValue ?: string ) => {
49
58
if ( ! newValue ) {
50
59
setQuestion ( "" ) ;
@@ -72,6 +81,8 @@ export const QuestionInput = ({ onSend, disabled, placeholder, clearOnSend, init
72
81
value = { question }
73
82
onChange = { onQuestionChange }
74
83
onKeyDown = { onEnterPress }
84
+ onCompositionStart = { handleCompositionStart }
85
+ onCompositionEnd = { handleCompositionEnd }
75
86
/>
76
87
< div className = { styles . questionInputButtonsContainer } >
77
88
< Tooltip content = "Submit question" relationship = "label" >
0 commit comments