How can I make a form submit when a user pressed Enter in a <textarea>? The default behaviour is to insert a linebreak into the <textarea>.
<form className="" onSubmit={newComment}>
<textarea type="text" rows="3" name="body" />
<button className="btn" type="submit">
Comment
</button>
</form>
Should I have an onChange event on the <textarea>, and in a function test to see if the Enter key was pressed? This is how I would do it with vanilla JavaScript but I couldn't find the key event in React's synthetic event.
onKeyDownhandler and check forevent.keyCode, it will work. Working Fiddle