Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send button is active when message has spaces, but does not send it #8064

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class ReportActionCompose extends React.Component {

this.focus(false);
});
this.updateComment(this.comment);
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -307,7 +308,7 @@ class ReportActionCompose extends React.Component {
updateComment(newComment) {
this.textInput.setNativeProps({text: newComment});
this.setState({
isCommentEmpty: newComment.length === 0,
isCommentEmpty: newComment.trim().length === 0,
Comment on lines -310 to +311
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a regression #21920. We used to relay on isCommentEmpty state being actually empty (length is 0) to move on to edit mode. This change made it possible to go into edit mode while having content on the Composer.

Copy link
Contributor Author

@mollfpr mollfpr Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s77rt Could you elaborate on why that code causing the regression now? The code got changed on the next PR #8844

The logic has changed a lot since then, and the latest is !!newComment.match(/^(\s)*$/)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! The edit mode was accessible based on isCommentEmpty state. Before if the composer only contains empty spaces and you keep pressing the arrow up key, nothing will happen because the comment is not empty. But now the comment length is based on the trimmed version of that text so the composer appears empty and pressing the arrow up will get you into edit mode.

});

// Indicate that draft has been created.
Expand Down Expand Up @@ -345,8 +346,8 @@ class ReportActionCompose extends React.Component {
this.submitForm();
}

// Trigger the edit box for last sent message if ArrowUp is pressed
if (e.key === 'ArrowUp' && this.state.isCommentEmpty) {
// Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty
if (e.key === 'ArrowUp' && this.textInput.selectionStart === 0 && this.state.isCommentEmpty) {
e.preventDefault();

const reportActionKey = _.find(
Expand Down