Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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