Skip to content

Instantly share code, notes, and snippets.

@dorianmariecom
Last active June 8, 2021 20:18
Show Gist options
  • Save dorianmariecom/8aa3338c7583d38ffff0339fe441c463 to your computer and use it in GitHub Desktop.
Save dorianmariecom/8aa3338c7583d38ffff0339fe441c463 to your computer and use it in GitHub Desktop.
Stimulus-based auto-expanding textarea
import { Controller } from "stimulus"
export default class extends Controller {
handle(event) {
event.target.rows = event.target.value.split("\n").map((row) => {
return Math.ceil((row.length + 1) / event.target.cols)
}).reduce((acc, el) => acc + el)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment