-
-
Save kobitoDevelopment/523a641849028db6f9324de3d6b88a7b 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
| .auto-resize { | |
| max-width: 640px; | |
| width: 100%; | |
| max-height: 320px; | |
| resize: none; | |
| overflow-y: auto; | |
| } |
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
| <textarea class="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
| document.addEventListener('DOMContentLoaded', () => { | |
| const textarea = document.querySelector('.auto-resize'); | |
| function adjustHeight() { | |
| textarea.style.height = 'auto'; | |
| textarea.style.height = textarea.scrollHeight + 'px'; | |
| } | |
| textarea.addEventListener('input', adjustHeight); | |
| window.addEventListener('resize', adjustHeight); | |
| adjustHeight(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment