From 6b636ad8510f25898b44dd0cabbcab8599496374 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 3 Mar 2023 13:36:46 -0700 Subject: [PATCH 1/2] subscribe to keyboard event --- src/pages/home/report/ReportActionCompose.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 6af89e25dbb6..706e8c3e6411 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -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 */ @@ -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); } From 8bfa4b7151d97ab9d5e8382dbc84edc82cb0ce0d Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 3 Mar 2023 13:37:44 -0700 Subject: [PATCH 2/2] unsubscribe from event --- src/pages/home/report/ReportActionCompose.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 706e8c3e6411..aaca67ddb539 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -212,6 +212,10 @@ class ReportActionCompose extends React.Component { componentWillUnmount() { ReportActionComposeFocusManager.clear(); + + if (this.unsubscribeEscapeKey) { + this.unsubscribeEscapeKey(); + } } onSelectionChange(e) {