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

Clear compose on Esc key #15650

Merged
merged 2 commits into from
Mar 7, 2023
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
15 changes: 15 additions & 0 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../../componen
import withDrawerState from '../../../components/withDrawerState';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import withKeyboardState, {keyboardStatePropTypes} from '../../../components/withKeyboardState';
import KeyboardShortcut from '../../../libs/KeyboardShortcut';

const propTypes = {
/** Beta features list */
Expand Down Expand Up @@ -168,6 +169,16 @@ class ReportActionCompose extends React.Component {

this.focus(false);
});

const shortcutConfig = CONST.KEYBOARD_SHORTCUTS.ESCAPE;
this.unsubscribeEscapeKey = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, () => {
if (!this.state.isFocused || this.comment.length === 0) {
return;
}

this.updateComment('');
}, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true);

this.setMaxLines();
this.updateComment(this.comment);
}
Expand Down Expand Up @@ -201,6 +212,10 @@ class ReportActionCompose extends React.Component {

componentWillUnmount() {
ReportActionComposeFocusManager.clear();

if (this.unsubscribeEscapeKey) {
this.unsubscribeEscapeKey();
}
}

onSelectionChange(e) {
Expand Down