]> cat aescling's git repositories - mastodon.git/commitdiff
autoscroll emoji suggestions box
authorOndřej Hruška <ondra@ondrovo.com>
Thu, 21 Sep 2017 13:31:24 +0000 (15:31 +0200)
committerOndřej Hruška <ondra@ondrovo.com>
Thu, 21 Sep 2017 13:31:24 +0000 (15:31 +0200)
app/javascript/mastodon/components/autosuggest_textarea.js

index e94900c828bd61392858c1bd16fd24f825ccf06a..1c7ffe1968d34e017c40400948462529ccbf4002 100644 (file)
@@ -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}
This page took 0.026992 seconds and 3 git commands to generate.