Last active
January 19, 2019 23:54
-
-
Save jsejcksn/8fdc3b23ec563ac4061f547d49253da1 to your computer and use it in GitHub Desktop.
Auto-resize textarea
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
for (const tx of document.getElementsByTagName('textarea')) { | |
tx.style.setProperty('height', `${tx.scrollHeight}px`); | |
tx.style.setProperty('overflow-y', 'hidden'); | |
tx.addEventListener('input', (ev) => { | |
ev.target.style.setProperty('height', 'auto'); | |
ev.target.style.setProperty('height', `${ev.target.scrollHeight}px`); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment