From 29d8313b28ee5a0f6e18141028185e757035b547 Mon Sep 17 00:00:00 2001 From: fusshi- Date: Wed, 10 May 2017 09:51:43 +0900 Subject: [PATCH] Disabled auto focus on toot form when search results are shown. (#2942) --- .../mastodon/components/autosuggest_textarea.js | 9 +++++++-- .../features/compose/components/compose_form.js | 10 ++++++++-- .../compose/containers/compose_form_container.js | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/components/autosuggest_textarea.js b/app/javascript/mastodon/components/autosuggest_textarea.js index 6d8d3b2a34..4d8f2882c9 100644 --- a/app/javascript/mastodon/components/autosuggest_textarea.js +++ b/app/javascript/mastodon/components/autosuggest_textarea.js @@ -153,7 +153,7 @@ class AutosuggestTextarea extends ImmutablePureComponent { } render () { - const { value, suggestions, disabled, placeholder, onKeyUp } = this.props; + const { value, suggestions, disabled, placeholder, onKeyUp, autoFocus } = this.props; const { suggestionsHidden, selectedSuggestion } = this.state; const style = { direction: 'ltr' }; @@ -168,7 +168,7 @@ class AutosuggestTextarea extends ImmutablePureComponent { className='autosuggest-textarea__textarea' disabled={disabled} placeholder={placeholder} - autoFocus={true} + autoFocus={autoFocus} value={value} onChange={this.onChange} onKeyDown={this.onKeyDown} @@ -208,6 +208,11 @@ AutosuggestTextarea.propTypes = { onKeyUp: PropTypes.func, onKeyDown: PropTypes.func, onPaste: PropTypes.func.isRequired, + autoFocus: PropTypes.bool +}; + +AutosuggestTextarea.defaultProps = { + autoFucus: true, }; export default AutosuggestTextarea; diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index 2a93f2e437..68179244a2 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -118,7 +118,7 @@ class ComposeForm extends ImmutablePureComponent { } render () { - const { intl, onPaste } = this.props; + const { intl, onPaste, showSearch } = this.props; const disabled = this.props.is_submitting; const text = [this.props.spoiler_text, this.props.text].join(''); @@ -156,6 +156,7 @@ class ComposeForm extends ImmutablePureComponent { onSuggestionsClearRequested={this.onSuggestionsClearRequested} onSuggestionSelected={this.onSuggestionSelected} onPaste={onPaste} + autoFocus={!showSearch} /> @@ -204,7 +205,12 @@ ComposeForm.propTypes = { onSuggestionSelected: PropTypes.func.isRequired, onChangeSpoilerText: PropTypes.func.isRequired, onPaste: PropTypes.func.isRequired, - onPickEmoji: PropTypes.func.isRequired + onPickEmoji: PropTypes.func.isRequired, + showSearch: PropTypes.bool, +}; + +ComposeForm.defaultProps = { + showSearch: false }; export default injectIntl(ComposeForm); diff --git a/app/javascript/mastodon/features/compose/containers/compose_form_container.js b/app/javascript/mastodon/features/compose/containers/compose_form_container.js index 892183b831..33ad65be5d 100644 --- a/app/javascript/mastodon/features/compose/containers/compose_form_container.js +++ b/app/javascript/mastodon/features/compose/containers/compose_form_container.js @@ -22,7 +22,8 @@ const mapStateToProps = state => ({ preselectDate: state.getIn(['compose', 'preselectDate']), is_submitting: state.getIn(['compose', 'is_submitting']), is_uploading: state.getIn(['compose', 'is_uploading']), - me: state.getIn(['compose', 'me']) + me: state.getIn(['compose', 'me']), + showSearch: state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) }); const mapDispatchToProps = (dispatch) => ({