Menu

Confirming an English word with Enter sent the chat
📰

Confirming an English word with Enter sent the chat

DEV Community: javascript·Kenji·18 days ago
#GP14VnYp
#devtojavascript#devto#dev#enter#keydown
Reading 0:00
15s threshold

The chat sends on Enter. Shift+Enter inserts a newline. With a Chinese IME, Enter is how you keep an English word you typed in that mode, instead of a converted candidate. The field still receives a keydown whose key is Enter. The handler called send, and the word went out as a message.

This is the textarea (or input ) event, not a component API. compositionstart , compositionend , blur , and keydown are on the element. A React prop with the same name is just that listener.

isComposing on the keydown is enough in Chromium. The keydown that confirms the composition still has it set, so the handler can return and let the IME write the string. Safari runs the events the other way. compositionend happens first, and the Enter keydown after it already has isComposing false. A check that only reads the event treats that keydown as a normal send.

Keep a flag, set true on compositionstart . On compositionend , clear it with setTimeout(0) , not in the listener itself.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.