require-ime-safe-enter-handler
Preserve IME composition before Enter submits or blurs a native text control.
Why
The Enter key confirms Japanese, Chinese and Korean composition as well as triggering custom actions. An unguarded native form submission or blur interrupts composing text.
Fix
Check the native keyboard event composition state before the action. Retain the Safari keyCode 229 or composition-timestamp fallback required by the browser policy; offer a native submit button.
Examples
<textarea onKeyDown={(e) => { if (e.key === "Enter") e.currentTarget.form?.requestSubmit(); }}/>;<textarea onKeyDown={(e) => { if (e.nativeEvent.isComposing || e.nativeEvent.keyCode === 229) return; if (e.key === "Enter") { e.preventDefault(); e.currentTarget.form?.requestSubmit(); } }}/>;