diff options
author | Jeong Arm <kjwonmail@gmail.com> | 2019-06-05 22:29:45 +0900 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-06-07 17:39:46 +0200 |
commit | b32a62fe957c9c81e03ea3970705ff5eb46abf72 (patch) | |
tree | 5fdc8d5476c9b18e8b8e7d4668c12ad79fe2a045 /app/javascript/flavours/glitch | |
parent | 01aae33a5f6e69942da0a3028dded2621f1d4c81 (diff) |
[Glitch] Scroll to compose form when focus
Port 8f3c32e29cf13a84b2f0a58da0ab0c99a88caad5 to glitch-soc Signed-off-by: Thibaut Girka <thib@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours/glitch')
-rw-r--r-- | app/javascript/flavours/glitch/components/autosuggest_textarea.js | 5 | ||||
-rw-r--r-- | app/javascript/flavours/glitch/features/compose/components/compose_form.js | 11 |
2 files changed, 14 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/components/autosuggest_textarea.js b/app/javascript/flavours/glitch/components/autosuggest_textarea.js index e1ded2b3a..cf3907fbf 100644 --- a/app/javascript/flavours/glitch/components/autosuggest_textarea.js +++ b/app/javascript/flavours/glitch/components/autosuggest_textarea.js @@ -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) => { diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.js b/app/javascript/flavours/glitch/features/compose/components/compose_form.js index cc82a50d4..0120be28f 100644 --- a/app/javascript/flavours/glitch/features/compose/components/compose_form.js +++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.js @@ -28,6 +28,10 @@ const messages = defineMessages({ export default @injectIntl class ComposeForm extends ImmutablePureComponent { + setRef = c => { + this.composeForm = c; + }; + static contextTypes = { router: PropTypes.object, }; @@ -208,6 +212,10 @@ class ComposeForm extends ImmutablePureComponent { } } + handleFocus = () => { + this.composeForm.scrollIntoView(); + } + // This statement does several things: // - If we're beginning a reply, and, // - Replying to zero or one users, places the cursor at the end @@ -302,7 +310,7 @@ class ComposeForm extends ImmutablePureComponent { let disabledButton = isSubmitting || isUploading || isChangingUpload || (!text.trim().length && !anyMedia); return ( - <div className='composer'> + <div className='composer' ref={this.setRef}> <WarningContainer /> <ReplyIndicatorContainer /> @@ -337,6 +345,7 @@ class ComposeForm extends ImmutablePureComponent { value={this.props.text} onChange={this.handleChange} suggestions={this.props.suggestions} + onFocus={this.handleFocus} onKeyDown={this.handleKeyDown} onSuggestionsFetchRequested={onFetchSuggestions} onSuggestionsClearRequested={onClearSuggestions} |