]> cat aescling's git repositories - mastodon.git/commitdiff
Scroll to compose form when focus (#10970)
authorJeong Arm <kjwonmail@gmail.com>
Wed, 5 Jun 2019 13:29:45 +0000 (22:29 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 5 Jun 2019 13:29:45 +0000 (15:29 +0200)
* Scroll to compose form when focus

* Get rid of constructor

app/javascript/mastodon/components/autosuggest_textarea.js
app/javascript/mastodon/features/compose/components/compose_form.js

index 5cad43e821477b20799910f446ed0136c1490c62..4c50294baee512af48ddff2bf548fdcc9c64997e 100644 (file)
@@ -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) => {
index eff193929d462aa9395c9d77aae9411b31fdc102..fb0c75fd36c217dc6946d41484ee74a4dc3f833a 100644 (file)
@@ -33,6 +33,10 @@ const messages = defineMessages({
 export default @injectIntl
 class ComposeForm extends ImmutablePureComponent {
 
+  setRef = c => {
+    this.composeForm = c;
+  };
+
   static contextTypes = {
     router: PropTypes.object,
   };
@@ -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,
@@ -177,7 +185,7 @@ class ComposeForm extends ImmutablePureComponent {
     }
 
     return (
-      <div className='compose-form'>
+      <div className='compose-form' ref={this.setRef}>
         <WarningContainer />
 
         <ReplyIndicatorContainer />
@@ -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}