Skip to content

Instantly share code, notes, and snippets.

@leastbad
Created February 6, 2020 02:09
Show Gist options
  • Save leastbad/825919a9a6b7213fd5959da88a02cbb2 to your computer and use it in GitHub Desktop.
Save leastbad/825919a9a6b7213fd5959da88a02cbb2 to your computer and use it in GitHub Desktop.
My autosize implementation
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