Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancelable/default action for keydown, composition*, beforeinput, textInput, input #361

Open
zcorpan opened this issue Nov 23, 2023 · 1 comment

Comments

@zcorpan
Copy link
Member

zcorpan commented Nov 23, 2023

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

If the key is associated with a character, the default action MUST be to dispatch a beforeinput event followed by an input event.

However, in Chrome, Safari and Firefox, if you cancel a beforeinput event, no input event is fired.

Chrome and Safari support textInput, and if you cancel that event, no input event is fired.

So, assuming the correct event order for typing a single non-composing character in a text field is:

  1. keydown
  2. keypress
  3. beforeinput
  4. textInput
  5. input
  6. keyup

...the default actions should be:

event default action
keydown fire keypress
keypress fire beforeinput
beforeinput fire textInput
textInput update DOM; fire input
input none
keyup none

During composition I think beforeinput isn't cancelable as implemented (try typing ¨ in the demo), and keypress isn't fired.

The spec also says that compositionupdate and compositionend are not cancelable, but in Chrome and Safari they are. In Firefox they are not cancelable, and compositionstart is also not cancelable.

@zcorpan zcorpan mentioned this issue Dec 5, 2023
5 tasks
@zcorpan
Copy link
Member Author

zcorpan commented Jan 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant