A Lazy Sequence

DOM input events

Sometimes web API changes slip by you: Today I learned that the DOM now has a dedicated input event for text entry on input and textarea elements (and contentEditable, but who wants to be touching that, yikes!) that is raised whenever the value has changed.

This is different from the change event, which is only raised when the value has changed and the widget is blurred (defocused).

Previously, the if change wasn’t granular enough, a developer would resort to keyup or keypress which may seem like a near enough match for behaviour, but that’s only true for langauges such as English where each keypress is exactly equal to one character. In a langauge with that use an IME multiple keypresses are required to produce a single character (Japanese for example), you will instead be getting an invalid partial state.

Related to input is beforeinput which is raised just before the value changes.

Proper handling of input composition with IMEs is also handled with CompositionEvent now.

14 April 2023