Last active
April 5, 2018 20:43
-
-
Save aymanalzarrad/efa6ee52af9a19274ff9001e8f8e7116 to your computer and use it in GitHub Desktop.
Auto-grow / Auto-shrink Textarea element.
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
let textarea = document.getElementById('textarea'); | |
textarea.style.resize = 'none'; | |
textarea.style.overflow = 'hidden'; | |
textarea.addEventListener('input', () => { | |
textarea.style.height = ''; | |
if( textarea.clientHeight !== textarea.scrollHeight ){ | |
textarea.style.height = (textarea.scrollHeight + 'px'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment