by greggman3 · 5y ago · 0 comments
Another issue I run into is forms that dismiss via keydown and escape. I type in Japanese which means I'm using an IME. An IME, or at least the Japanese IME, you type characters and they appear with possible completions. They haven't actually been given to the app yet. Pressing Escape cancels the completions. But webpages that cancel some model form dialog via escape means that if I press ESC to cancel IME completion (which is common) I also cancel the dialog and lose all input had previously entered into the form.
I'd think this would been solved at the browser level, if the IME is active then don't pass keys to the app but for probably valid reasons that's not what happens.
TL;DR don't use escape to cancel a model form!
edit: apparently there's the 'isComposting' property on the KeyboardEvent to find out if the user is currently using the IME
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve...
If you follow these three rules feel free to use the esc to close the dialog. I just tested logging `event.key` with hiragana Mozc input device and every keydown while selecting the correct kanji registers as `Process` even cancelling the input with Esc just adds another Process keydown event. I admit it can be frustrating if you double tab Esc accidentally to close the input (second Esc will close the dialog), but that is where rule one comes in, and the accident will only cause the user a minor annoyance.
In this scenario, the "current interaction" is IME input. The bug is that the page intercepts Esc keypresses intended to be handled by it.
The article mentions an open-source example that does it this way and works fine on international layouts: Discourse
https://developer.mozilla.org/en-US/docs/Web/API/Document/ke...
1: https://developer.mozilla.org/en-US/docs/Web/API/Element/key...
2: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve...