Created
May 3, 2019 12:50
-
-
Save gossi/f11f2c36c83e435c76116633169a39c6 to your computer and use it in GitHub Desktop.
Event Support: Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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