diff --git a/src/libs/ComposerUtils/index.js b/src/libs/ComposerUtils/index.js index e48a803f1152..7bf08fdeef8c 100644 --- a/src/libs/ComposerUtils/index.js +++ b/src/libs/ComposerUtils/index.js @@ -1,5 +1,6 @@ import getNumberOfLines from './getNumberOfLines'; import updateNumberOfLines from './updateNumberOfLines'; +import * as DeviceCapabilities from '../DeviceCapabilities'; /** * Replace substring between selection with a text. @@ -12,8 +13,21 @@ function insertText(text, selection, textToInsert) { return text.slice(0, selection.start) + textToInsert + text.slice(selection.end, text.length); } +/** + * Check whether we can skip trigger hotkeys on some specific devices. + * @param {Boolean} isSmallScreenWidth + * @param {Boolean} isKeyboardShown + * @returns {Boolean} + */ +function canSkipTriggerHotkeys(isSmallScreenWidth, isKeyboardShown) { + // Do not trigger actions for mobileWeb or native clients that have the keyboard open + // because for those devices, we want the return key to insert newlines rather than submit the form + return (isSmallScreenWidth && DeviceCapabilities.canUseTouchScreen()) || isKeyboardShown; +} + export { getNumberOfLines, updateNumberOfLines, insertText, + canSkipTriggerHotkeys, }; diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 5e589b499898..c01d0a048fa9 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -642,8 +642,7 @@ class ReportActionCompose extends React.Component { * @param {Object} e */ triggerHotkeyActions(e) { - // Do not trigger actions for mobileWeb or native clients that have the keyboard open because for those devices, we want the return key to insert newlines rather than submit the form - if (!e || this.props.isSmallScreenWidth || this.props.isKeyboardShown) { + if (!e || ComposerUtils.canSkipTriggerHotkeys(this.props.isSmallScreenWidth, this.props.isKeyboardShown)) { return; } diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 8ca6e1c69da6..74d10be8568f 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -239,8 +239,7 @@ class ReportActionItemMessageEdit extends React.Component { * @param {Event} e */ triggerSaveOrCancel(e) { - // Do not trigger actions for mobileWeb or native clients that have the keyboard open because for those devices, we want the return key to insert newlines rather than submit the form - if (!e || this.props.isSmallScreenWidth || this.props.isKeyboardShown) { + if (!e || ComposerUtils.canSkipTriggerHotkeys(this.props.isSmallScreenWidth, this.props.isKeyboardShown)) { return; } if (e.key === 'Enter' && !e.shiftKey) {