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