Skip to content

Commit

Permalink
Merge pull request #15650 from Expensify/cmartins-escapeToClear
Browse files Browse the repository at this point in the history
Clear compose on Esc key
  • Loading branch information
madmax330 authored Mar 7, 2023
2 parents a7b6838 + 8bfa4b7 commit 71a119f
Showing 1 changed file with 15 additions and 0 deletions.
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 @@ -205,6 +216,10 @@ class ReportActionCompose extends React.Component {

componentWillUnmount() {
ReportActionComposeFocusManager.clear();

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

onSelectionChange(e) {
Expand Down

0 comments on commit 71a119f

Please sign in to comment.