I am trying to submit my form while in a textarea when they hit enter. If they hit Enter + Shift then I want to make a new line in the textarea.
I also want to prevent a postback when enter is hit and this is what I am having a problem with.
<form ref={el => this.myFormRef = el} onSubmit={this.searchClick} autoComplete="off">
<textarea
ref={input => input && input.focus()}
className="textarea"
name="search-area"
rows={this.rowCount}
value={this.searchValue}
onChange={this.onChange}
onKeyDown={this.onKeyDown}
/>
</form>
@action
searchClick = (event) => {
event.preventDefault();
event.stopPropagation();
}
@action
onKeyDown = event => {
if (event.key == 'Enter' && event.shiftKey == false) {
this.myFormRef.submit();
event.preventDefault();
event.stopPropagation();
}
this.searchValue = event.target.value;
};