From fce62f88dbf6806d6a015edea8bab65c96efebb7 Mon Sep 17 00:00:00 2001 From: azimgd Date: Tue, 2 May 2023 19:13:00 +0500 Subject: [PATCH] Add enter shortcut for KeyboardShortcutsModal so that you can close it by pressing enter --- src/components/KeyboardShortcutsModal.js | 12 +++++++++--- .../OptionsSelector/BaseOptionsSelector.js | 3 ++- src/pages/iou/steps/MoneyRequestAmountPage.js | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/KeyboardShortcutsModal.js b/src/components/KeyboardShortcutsModal.js index a5454e280f0d..dbe18427ecf2 100644 --- a/src/components/KeyboardShortcutsModal.js +++ b/src/components/KeyboardShortcutsModal.js @@ -40,11 +40,17 @@ class KeyboardShortcutsModal extends React.Component { KeyboardShortcutsActions.showKeyboardShortcutModal(); }, openShortcutModalConfig.descriptionKey, openShortcutModalConfig.modifiers, true); - const closeShortcutModalConfig = CONST.KEYBOARD_SHORTCUTS.ESCAPE; - this.unsubscribeEscapeModal = KeyboardShortcut.subscribe(closeShortcutModalConfig.shortcutKey, () => { + const closeShortcutEscapeModalConfig = CONST.KEYBOARD_SHORTCUTS.ESCAPE; + this.unsubscribeEscapeModal = KeyboardShortcut.subscribe(closeShortcutEscapeModalConfig.shortcutKey, () => { ModalActions.close(); KeyboardShortcutsActions.hideKeyboardShortcutModal(); - }, closeShortcutModalConfig.descriptionKey, closeShortcutModalConfig.modifiers, true, true); + }, closeShortcutEscapeModalConfig.descriptionKey, closeShortcutEscapeModalConfig.modifiers, true, true); + + const closeShortcutEnterModalConfig = CONST.KEYBOARD_SHORTCUTS.ENTER; + this.unsubscribeEscapeModal = KeyboardShortcut.subscribe(closeShortcutEnterModalConfig.shortcutKey, () => { + ModalActions.close(); + KeyboardShortcutsActions.hideKeyboardShortcutModal(); + }, closeShortcutEnterModalConfig.descriptionKey, closeShortcutEnterModalConfig.modifiers, true, () => !this.props.isShortcutsModalOpen, 0); } componentWillUnmount() { diff --git a/src/components/OptionsSelector/BaseOptionsSelector.js b/src/components/OptionsSelector/BaseOptionsSelector.js index 027899e9be9b..4f8c1425eaf8 100755 --- a/src/components/OptionsSelector/BaseOptionsSelector.js +++ b/src/components/OptionsSelector/BaseOptionsSelector.js @@ -70,6 +70,7 @@ class BaseOptionsSelector extends Component { enterConfig.modifiers, true, () => !this.state.allOptions[this.state.focusedIndex], + 1, ); const CTRLEnterConfig = CONST.KEYBOARD_SHORTCUTS.CTRL_ENTER; @@ -359,7 +360,7 @@ class BaseOptionsSelector extends Component { text={defaultConfirmButtonText} onPress={this.props.onConfirmSelection} pressOnEnter - enterKeyEventListenerPriority={1} + enterKeyEventListenerPriority={2} /> )} {this.props.footerContent} diff --git a/src/pages/iou/steps/MoneyRequestAmountPage.js b/src/pages/iou/steps/MoneyRequestAmountPage.js index 7fb169fa3d84..c3fd2602c29e 100755 --- a/src/pages/iou/steps/MoneyRequestAmountPage.js +++ b/src/pages/iou/steps/MoneyRequestAmountPage.js @@ -354,6 +354,7 @@ class MoneyRequestAmountPage extends React.Component { pressOnEnter isDisabled={!this.state.amount.length || parseFloat(this.state.amount) < 0.01} text={this.props.buttonText} + enterKeyEventListenerPriority={2} />