Created
February 6, 2020 02:09
-
-
Save leastbad/825919a9a6b7213fd5959da88a02cbb2 to your computer and use it in GitHub Desktop.
My autosize implementation
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
import { Controller } from 'stimulus' | |
export default class extends Controller { | |
initialize () { | |
this.setInputAttributes() | |
this.update() | |
} | |
update () { | |
this.element.style.height = 'auto' | |
this.element.style.height = `${this.element.scrollHeight}px` | |
} | |
setInputAttributes () { | |
this.element.setAttribute( | |
'style', | |
`height: ${this.element.scrollHeight}px; overflow-y: hidden;` | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment