Open zcorpan opened 10 months ago
I forgot about keypress
.
https://software.hixie.ch/utilities/js/live-dom-viewer/saved/12264
The spec says:
The keypress event type MUST be dispatched after the beforeinput event and before the input event associated with the same key.
https://w3c.github.io/uievents/#keypress-event-order
However Chrome, Safari, Firefox all fire keypress
right after keydown
when typing "a" in <input>
or contenteditable
element.
While trying to figure out what spec text to propose for the
textInput
event (#353) I found that the spec doesn't seem to match implementations for the default action for the keydown, composition*, beforeinput, textInput, input events, and whether/when they're cancelable.Demo: https://software.hixie.ch/utilities/js/live-dom-viewer/saved/12161
For example, https://w3c.github.io/uievents/#keydown says
However, in Chrome, Safari and Firefox, if you cancel a
beforeinput
event, noinput
event is fired.Chrome and Safari support
textInput
, and if you cancel that event, noinput
event is fired.So, assuming the correct event order for typing a single non-composing character in a text field is:
...the default actions should be:
During composition I think beforeinput isn't cancelable as implemented (try typing
¨
in the demo), andkeypress
isn't fired.The spec also says that
compositionupdate
andcompositionend
are not cancelable, but in Chrome and Safari they are. In Firefox they are not cancelable, andcompositionstart
is also not cancelable.