Skip to content

Commit

Permalink
Scroll to compose form when focus (mastodon#10970)
Browse files Browse the repository at this point in the history
* Scroll to compose form when focus

* Get rid of constructor
  • Loading branch information
tribela authored and hiyuki2578 committed Oct 2, 2019
1 parent b9a2010 commit 0a19c54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/javascript/mastodon/components/autosuggest_textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
this.setState({ suggestionsHidden: true, focused: false });
}

onFocus = () => {
onFocus = (e) => {
this.setState({ focused: true });
if (this.props.onFocus) {
this.props.onFocus(e);
}
}

onSuggestionClick = (e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const messages = defineMessages({
export default @injectIntl
class ComposeForm extends ImmutablePureComponent {

setRef = c => {
this.composeForm = c;
};

static contextTypes = {
router: PropTypes.object,
};
Expand Down Expand Up @@ -114,6 +118,10 @@ class ComposeForm extends ImmutablePureComponent {
this.props.onChangeSpoilerText(e.target.value);
}

handleFocus = () => {
this.composeForm.scrollIntoView();
}

componentDidUpdate (prevProps) {
// This statement does several things:
// - If we're beginning a reply, and,
Expand Down Expand Up @@ -177,7 +185,7 @@ class ComposeForm extends ImmutablePureComponent {
}

return (
<div className='compose-form'>
<div className='compose-form' ref={this.setRef}>
<WarningContainer />

<ReplyIndicatorContainer />
Expand Down Expand Up @@ -211,6 +219,7 @@ class ComposeForm extends ImmutablePureComponent {
value={this.props.text}
onChange={this.handleChange}
suggestions={this.props.suggestions}
onFocus={this.handleFocus}
onKeyDown={this.handleKeyDown}
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
Expand Down

0 comments on commit 0a19c54

Please sign in to comment.