Last active
June 8, 2021 20:18
-
-
Save dorianmariecom/8aa3338c7583d38ffff0339fe441c463 to your computer and use it in GitHub Desktop.
Stimulus-based auto-expanding textarea
This file contains 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 { | |
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