Skip to content

Commit

Permalink
add comments submit with ctrl,cmd+Enter Close #1260
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano committed Jan 18, 2017
1 parent 7184a51 commit 14aed55
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {Component} from 'react'
import {findDOMNode} from 'react-dom'

export default class AutoGrowTextarea extends Component {
componentDidMount () {
Expand All @@ -15,14 +14,14 @@ export default class AutoGrowTextarea extends Component {
}

recomputeSize = () => {
const node = findDOMNode(this)
const node = this.refs.textarea
node.style.minHeight = 'auto'
node.style.minHeight = `${node.scrollHeight}px`
}

render () {
return (
<textarea onChange={this.handleChange} {...this.props} />
<textarea onChange={this.handleChange} {...this.props} ref='textarea' />
)
}
}
12 changes: 11 additions & 1 deletion lib/site/topic-layout/topic-article/comments/form/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ class CommentsForm extends Component {
}

handleTextChange = (evt) => {
const text = evt.currentTarget.value || ''

this.setState({
text: evt.currentTarget.value || ''
text: text,
focused: text ? true : this.state.focused
})
}

handleKeyDown = (evt) => {
if ((evt.ctrlKey || evt.metaKey) && evt.key === 'Enter') {
this.handleSubmit(evt)
}
}

handleSubmit = (evt) => {
evt.preventDefault()
this.setState({error: ''})
Expand Down Expand Up @@ -94,6 +103,7 @@ class CommentsForm extends Component {
onChange={this.handleTextChange}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
placeholder={t('comments.create.placeholder')}
maxLength='4096'
minLength='1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ class RepliesForm extends Component {
}

handleTextChange = (evt) => {
const text = evt.currentTarget.value || ''

this.setState({
text: evt.currentTarget.value || ''
text: text,
focused: text ? true : this.state.focused
})
}

handleKeyDown = (evt) => {
if ((evt.ctrlKey || evt.metaKey) && evt.key === 'Enter') {
this.handleSubmit(evt)
}
}

handleSubmit = (evt) => {
evt.preventDefault()
this.setState({error: ''})
Expand Down Expand Up @@ -94,6 +103,7 @@ class RepliesForm extends Component {
onChange={this.handleTextChange}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
onKeyDown={this.handleKeyDown}
placeholder={t('comments.arguments.reply')}
maxLength='4096'
minLength='1'
Expand Down

0 comments on commit 14aed55

Please sign in to comment.