当他们在回车时,我正在尝试在文本区域中提交表单。如果他们按Enter + Shift键,那么我想在文本区域中换行。
我也想防止在回车被击中时回发,这就是我遇到的问题。
<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;
};