JSFiddle - React, Tailwind, and code Playground

by Abhishek Kumar

HTML

<textarea id="ta" rows="2" data-maxrows="5"></textarea>

JavaScript

var ta = document.getElementById('ta');
ta.addEventListener('keypress', function(ev) {
  //var that = document.getElementById(ev.target.id);
  var that = ev.target;
  if (ev.keyCode == 13 && that.value.split(/\r*\n/).length >= that.getAttribute('data-maxrows')) {
    ev.preventDefault();
  }
});