Updated compose_form to account for if compose modal open

fixes #9
since there are multiple compose_form on the page (on top of timeline = shouldCondense) and within the modal when replying. if isModalOpen and is the compose form that's on top of timeline then dont set the ref so we can set the cursor on the textarea of the compose modal after the existing reply content.
This commit is contained in:
mgabdev 2019-07-12 12:22:05 -04:00
parent 1e68c5d4fe
commit 4e9b22640c
2 changed files with 6 additions and 2 deletions

View File

@ -68,6 +68,7 @@ class ComposeForm extends ImmutablePureComponent {
anyMedia: PropTypes.bool, anyMedia: PropTypes.bool,
shouldCondense: PropTypes.bool, shouldCondense: PropTypes.bool,
autoFocus: PropTypes.bool, autoFocus: PropTypes.bool,
isModalOpen: PropTypes.bool,
}; };
static defaultProps = { static defaultProps = {
@ -150,6 +151,8 @@ class ComposeForm extends ImmutablePureComponent {
} }
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {
if (!this.autosuggestTextarea) return;
// This statement does several things: // This statement does several things:
// - If we're beginning a reply, and, // - If we're beginning a reply, and,
// - Replying to zero or one users, places the cursor at the end of the textbox. // - Replying to zero or one users, places the cursor at the end of the textbox.
@ -203,7 +206,7 @@ class ComposeForm extends ImmutablePureComponent {
} }
render () { render () {
const { intl, onPaste, showSearch, anyMedia, shouldCondense, autoFocus } = this.props; const { intl, onPaste, showSearch, anyMedia, shouldCondense, autoFocus, isModalOpen } = this.props;
const condensed = shouldCondense && !this.props.text && !this.state.composeFocused; const condensed = shouldCondense && !this.props.text && !this.state.composeFocused;
const disabled = this.props.isSubmitting; const disabled = this.props.isSubmitting;
const text = [this.props.spoilerText, countableText(this.props.text)].join(''); const text = [this.props.spoilerText, countableText(this.props.text)].join('');
@ -252,7 +255,7 @@ class ComposeForm extends ImmutablePureComponent {
</div> </div>
<AutosuggestTextarea <AutosuggestTextarea
ref={this.setAutosuggestTextarea} ref={(isModalOpen && shouldCondense) ? null : this.setAutosuggestTextarea}
placeholder={intl.formatMessage(messages.placeholder)} placeholder={intl.formatMessage(messages.placeholder)}
disabled={disabled} disabled={disabled}
value={this.props.text} value={this.props.text}

View File

@ -25,6 +25,7 @@ const mapStateToProps = state => ({
isUploading: state.getIn(['compose', 'is_uploading']), isUploading: state.getIn(['compose', 'is_uploading']),
showSearch: state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']), showSearch: state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']),
anyMedia: state.getIn(['compose', 'media_attachments']).size > 0, anyMedia: state.getIn(['compose', 'media_attachments']).size > 0,
isModalOpen: state.get('modal').modalType === 'COMPOSE',
}); });
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({