Skip to content

Instantly share code, notes, and snippets.

@web-padawan
Created November 10, 2020 13:31
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 web-padawan/363db6abff5a0e8291fa316456173bf4 to your computer and use it in GitHub Desktop.
Save web-padawan/363db6abff5a0e8291fa316456173bf4 to your computer and use it in GitHub Desktop.
class MyElement extends HTMLElement {
constructor() {
super();
this.addEventListener('keydown', this);
}
handleEvent(e) {
// trigger click on Enter or Space
if (e.keyCode === 13 || e.keyCode === 32) {
this.click();
}
}
}
customElements.define('my-element', MyElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment