diff options
Diffstat (limited to 'webapp/components/create_comment.jsx')
-rw-r--r-- | webapp/components/create_comment.jsx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/webapp/components/create_comment.jsx b/webapp/components/create_comment.jsx index a34ce0b8a..2aa85265a 100644 --- a/webapp/components/create_comment.jsx +++ b/webapp/components/create_comment.jsx @@ -37,6 +37,7 @@ export default class CreateComment extends React.Component { this.commentMsgKeyPress = this.commentMsgKeyPress.bind(this); this.handleChange = this.handleChange.bind(this); this.handleKeyDown = this.handleKeyDown.bind(this); + this.handleBlur = this.handleBlur.bind(this); this.handleUploadClick = this.handleUploadClick.bind(this); this.handleUploadStart = this.handleUploadStart.bind(this); this.handleFileUploadComplete = this.handleFileUploadComplete.bind(this); @@ -58,7 +59,8 @@ export default class CreateComment extends React.Component { fileInfos: draft.fileInfos, submitting: false, ctrlSend: PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'), - showPostDeletedModal: false + showPostDeletedModal: false, + lastBlurAt: 0 }; } @@ -166,6 +168,10 @@ export default class CreateComment extends React.Component { fileInfos: [], serverError: null }); + + const fasterThanHumanWillClick = 150; + const forceFocus = (Date.now() - this.state.lastBlurAt < fasterThanHumanWillClick); + this.focusTextbox(forceFocus); } commentMsgKeyPress(e) { @@ -316,8 +322,8 @@ export default class CreateComment extends React.Component { return this.state.fileInfos.length + this.state.uploadsInProgress.length; } - focusTextbox() { - if (!Utils.isMobile()) { + focusTextbox(keepFocus = false) { + if (keepFocus || !Utils.isMobile()) { this.refs.textbox.focus(); } } @@ -334,6 +340,10 @@ export default class CreateComment extends React.Component { }); } + handleBlur() { + this.setState({lastBlurAt: Date.now()}); + } + render() { let serverError = null; if (this.state.serverError) { @@ -397,6 +407,7 @@ export default class CreateComment extends React.Component { onKeyPress={this.commentMsgKeyPress} onKeyDown={this.handleKeyDown} value={this.state.message} + onBlur={this.handleBlur} createMessage={Utils.localizeMessage('create_comment.addComment', 'Add a comment...')} initialText='' supportsCommands={false} |