Last active
September 2, 2019 11:43
-
-
Save alonbardavid/65bfd0447739bb6ca5003acf6ebabcff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function myComponent(selector,label,value,onChange){ | |
let element = document.querySelector(selector); | |
element.innerHTML=``` | |
<div class="my-element"> | |
<label>${label}</label> | |
<input></input> | |
</div> | |
``` | |
let input = element.querySelector('input'); | |
input.value = value; | |
input.addEventListener('keydown', e=>{ | |
e.preventDefault(); //stops the input from accepting the change | |
input.value = onChange(input.value + e.key); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment