submit on enter for whisper

This commit is contained in:
Jonathan Rainville 2018-08-15 13:15:40 -04:00 committed by Iuri Matias
parent bf06163d30
commit 3c08b575df
1 changed files with 10 additions and 2 deletions

View File

@ -22,6 +22,14 @@ class Whisper extends React.Component {
this.setState(this.state);
}
checkEnter(e, func) {
if (e.key !== 'Enter') {
return;
}
e.preventDefault();
func.apply(this, [e]);
}
sendMessage (e) {
e.preventDefault();
EmbarkJS.Messages.sendMessage({topic: this.state.channel, data: this.state.message});
@ -68,7 +76,7 @@ class Whisper extends React.Component {
</React.Fragment> : ''
}
<h3>Listen To channel</h3>
<Form inline>
<Form inline onKeyDown={(e) => this.checkEnter(e, this.listenToChannel)}>
<FormGroup>
<FormControl
type="text"
@ -87,7 +95,7 @@ class Whisper extends React.Component {
</Form>
<h3>Send Message</h3>
<Form inline>
<Form inline onKeyDown={(e) => this.checkEnter(e, this.sendMessage)}>
<FormGroup>
<FormControl
type="text"