I think the keypress event is being deprecated, have you tried keydown instead?
I also use document
instead of window
, although not sure if that matters. Technically, you should use the injected DOM
element instead of globals.
You can then check the target of the event to make sure the user is clicking on your custom element?
Lastly, I think you can just use something like
attached(){
document.addEventListener('keydown', this.keyPress.bind(this), false);
}
instead of creating a field in the constructor.