import { Controller } from '@hotwired/stimulus' export default class extends Controller { // the default of one row keeps every existing textarea exactly as it was, fields that // are written into at length can ask for a taller floor to grow from static values = { minRows: { type: Number, default: 1 } } connect() { this.element.rows = this.minRowsValue this.minHeight = this.element.scrollHeight this.resize() } resize() { this.element.style.height = 'auto' this.element.style.height = `${Math.max(this.element.scrollHeight, this.minHeight)}px` } }