From 62c291dab86ae642be8ac4cd66ba871e8cf54367 Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Thu, 28 Jun 2018 03:24:34 +0200 Subject: [PATCH] compose: Make topic text input uncontrolled Fixes #2589 Remove the `value={topic}` from topic text input making it an uncontrolled component. To replicate the previous behavior: * initialze at the start in `componentDidMount` * make sure the topic input text is updated when we focus on a the message input (it is invisible until then) * change the text on picking a topic autocomplete suggestion --- src/compose/ComposeBox.android.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/compose/ComposeBox.android.js b/src/compose/ComposeBox.android.js index 5303a1cc8ce..37739c6a4ed 100644 --- a/src/compose/ComposeBox.android.js +++ b/src/compose/ComposeBox.android.js @@ -120,6 +120,11 @@ class ComposeBox extends PureComponent { this.handleMessageChange(message); }; + setTopicInputValue = (topic: string) => { + updateTextInput(this.topicInput, topic); + this.handleTopicChange(topic); + }; + handleComposeMenuToggle = () => { this.setState(({ isMenuExpanded }) => ({ isMenuExpanded: !isMenuExpanded, @@ -136,6 +141,10 @@ class ComposeBox extends PureComponent { this.setState({ topic, isMenuExpanded: false }); }; + handleTopicAutocomplete = (topic: string) => { + this.setTopicInputValue(topic); + }; + handleMessageChange = (message: string) => { this.setState({ message, isMenuExpanded: false }); const { dispatch, narrow } = this.props; @@ -159,7 +168,7 @@ class ComposeBox extends PureComponent { isMenuExpanded: false, }); setTimeout(() => { - this.handleTopicChange(topic || lastMessageTopic); + this.setTopicInputValue(topic || lastMessageTopic); }, 200); }; @@ -237,9 +246,10 @@ class ComposeBox extends PureComponent { }; componentDidMount() { - const { message } = this.state; + const { message, topic } = this.state; updateTextInput(this.messageInput, message); + updateTextInput(this.topicInput, topic); } componentWillUnmount() { @@ -254,7 +264,7 @@ class ComposeBox extends PureComponent { : ''; const message = nextProps.editMessage ? nextProps.editMessage.content : ''; this.setMessageInputValue(message); - this.handleTopicChange(topic); + this.setTopicInputValue(topic); if (this.messageInput) { this.messageInput.focus(); } @@ -299,7 +309,7 @@ class ComposeBox extends PureComponent { narrow={narrow} topicText={topic} onMessageAutocomplete={this.handleMessageAutocomplete} - onTopicAutocomplete={this.handleTopicChange} + onTopicAutocomplete={this.handleTopicAutocomplete} /> @@ -323,7 +333,6 @@ class ComposeBox extends PureComponent { onFocus={this.handleTopicFocus} onBlur={this.handleTopicBlur} onTouchStart={this.handleInputTouchStart} - value={topic} /> )}