JSFiddle - React, Tailwind, and code Playground
HTML
<textarea rows="10" cols="15"></textarea>
JavaScript
$(function(){
$('textarea').on('keypress', function (event) {
var text = $('textarea').val();
var lines = text.split("\n");
var currentLine = this.value.substr(0, this.selectionStart).split("\n").length;
console.log(lines);
console.log(currentLine);
console.log(lines[currentLine - 1]);
if (event.keyCode == 13) {
if (lines.length >= $(this).attr('rows')) return false;
} else {
if (lines[currentLine - 1].length >= ($(this).attr('cols') - 1)) {
$('textarea').val($('textarea').val() + "-\n");
// return false; // prevent characters from appearing
}
}
});
});