Skip to content

Instantly share code, notes, and snippets.

@gossi
Created May 3, 2019 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gossi/f11f2c36c83e435c76116633169a39c6 to your computer and use it in GitHub Desktop.
Save gossi/f11f2c36c83e435c76116633169a39c6 to your computer and use it in GitHub Desktop.
Event Support: Demo
import { CompatibleInputEvent, IS_INPUT_SUPPORTED, normalizeInputEvent } from 'event-support';
// assuming `element` is a reference to an <input> elem
element.addEventListener('keydown', (event: KeyboardEvent) => {
const e = normalizeInputEvent(event);
if (!IS_INPUT_SUPPORTED || event.key.length > 1) {
handleEvent(e);
}
}, false);
element.addEventListener('input', (event: InputEvent) => {
if (IS_INPUT_SUPPORTED) {
handleEvent(normalizeInputEvent(event));
}
}, false);
function handleEvent(e: CompatibleInputEvent) {
// your business logic here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment