[🐴] Support Japanese (et al.) IME in message input on web (#4159)

* support japanese et al. IME

* update comment

* nit
zio/stable
Hailey 2024-05-21 13:37:16 -07:00 committed by GitHub
parent 866b0b9121
commit cbfb69dd15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 1 deletions

View File

@ -26,6 +26,7 @@ export function MessageInput({
const [message, setMessage] = React.useState(getDraft) const [message, setMessage] = React.useState(getDraft)
const inputStyles = useSharedInputStyles() const inputStyles = useSharedInputStyles()
const isComposing = React.useRef(false)
const [isFocused, setIsFocused] = React.useState(false) const [isFocused, setIsFocused] = React.useState(false)
const [isHovered, setIsHovered] = React.useState(false) const [isHovered, setIsHovered] = React.useState(false)
@ -44,13 +45,15 @@ export function MessageInput({
const onKeyDown = React.useCallback( const onKeyDown = React.useCallback(
(e: React.KeyboardEvent<HTMLTextAreaElement>) => { (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
// Don't submit the form when the Japanese or any other IME is composing
if (isComposing.current) return
if (e.key === 'Enter') { if (e.key === 'Enter') {
if (e.shiftKey) return if (e.shiftKey) return
e.preventDefault() e.preventDefault()
onSubmit() onSubmit()
} }
}, },
[onSubmit], [onSubmit, isComposing],
) )
const onChange = React.useCallback( const onChange = React.useCallback(
@ -102,6 +105,12 @@ export function MessageInput({
autoFocus={true} autoFocus={true}
onFocus={() => setIsFocused(true)} onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)} onBlur={() => setIsFocused(false)}
onCompositionStart={() => {
isComposing.current = true
}}
onCompositionEnd={() => {
isComposing.current = false
}}
onChange={onChange} onChange={onChange}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
/> />