autoresize textarea

This commit is contained in:
Alex Turchyn
2023-07-01 01:09:44 +03:00
parent 50e9222216
commit e55b5b47cd
4 changed files with 29 additions and 5 deletions
@@ -0,0 +1,17 @@
export default class extends HTMLElement {
connectedCallback () {
this.resize()
this.textarea.addEventListener('input', () => this.resize())
}
resize () {
if (this.textarea.clientHeight < this.textarea.scrollHeight) {
this.textarea.style.height = `${this.textarea.scrollHeight}px`
}
}
get textarea () {
return this.querySelector('textarea')
}
}