about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOndřej Hruška <ondra@ondrovo.com>2017-09-21 15:31:24 +0200
committerOndřej Hruška <ondra@ondrovo.com>2017-09-21 15:31:24 +0200
commitc89cce0219646502b4d338213d112a528373bdc4 (patch)
tree9a9e24096e1344f32c7397734831563800a473cf
parentfa3587645da228e93767b245eeadbd668bc6cd38 (diff)
autoscroll emoji suggestions box
-rw-r--r--app/javascript/mastodon/components/autosuggest_textarea.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/javascript/mastodon/components/autosuggest_textarea.js b/app/javascript/mastodon/components/autosuggest_textarea.js
index e94900c82..1c7ffe196 100644
--- a/app/javascript/mastodon/components/autosuggest_textarea.js
+++ b/app/javascript/mastodon/components/autosuggest_textarea.js
@@ -162,6 +162,15 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
     }
   }
 
+  componentDidUpdate () {
+    if (this.refs.selected) {
+      if (this.refs.selected.scrollIntoViewIfNeeded)
+        this.refs.selected.scrollIntoViewIfNeeded();
+      else
+        this.refs.selected.scrollIntoView({ behavior: 'auto', block: 'nearest' });
+    }
+  }
+
   render () {
     const { value, suggestions, disabled, placeholder, onKeyUp, autoFocus } = this.props;
     const { suggestionsHidden, selectedSuggestion } = this.state;
@@ -202,6 +211,7 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
         <div className={`autosuggest-textarea__suggestions ${suggestionsHidden || suggestions.isEmpty() ? '' : 'autosuggest-textarea__suggestions--visible'}`}>
           {suggestions.map((suggestion, i) => (
             <div
+              ref={i === selectedSuggestion ? 'selected' : null}
               role='button'
               tabIndex='0'
               key={suggestion}