Files
myep-team/assets/controllers/textarea_autosize_controller.js
T
2026-08-11 16:25:53 +02:00

19 lines
622 B
JavaScript

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`
}
}