diff --git a/src/components/Button.js b/src/components/Button.js index a57a68a1d50..d192c43f773 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -123,12 +123,12 @@ class Button extends Component { const shortcutConfig = CONST.KEYBOARD_SHORTCUTS.ENTER; // Setup and attach keypress handler for pressing the button with Enter key - this.unsubscribe = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, () => { - if (this.props.isDisabled || this.props.isLoading) { + this.unsubscribe = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, (e) => { + if (this.props.isDisabled || this.props.isLoading || (e && e.target.nodeName === 'TEXTAREA')) { return; } this.props.onPress(); - }, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true, false, this.props.enterKeyEventListenerPriority); + }, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true, false, this.props.enterKeyEventListenerPriority, false); } componentWillUnmount() { diff --git a/src/libs/KeyboardShortcut/index.js b/src/libs/KeyboardShortcut/index.js index aa485ffa8cd..4b92775731f 100644 --- a/src/libs/KeyboardShortcut/index.js +++ b/src/libs/KeyboardShortcut/index.js @@ -83,7 +83,9 @@ function bindHandlerToKeydownEvent(event) { if (_.isFunction(callback.callback)) { callback.callback(event); } - event.preventDefault(); + if (callback.shouldPreventDefault) { + event.preventDefault(); + } // If the event should not bubble, short-circuit the loop let shouldBubble = callback.shouldBubble || false; @@ -136,9 +138,10 @@ function getPlatformEquivalentForKeys(keys) { * @param {Boolean} [captureOnInputs] Should we capture the event on inputs too? * @param {Boolean|Function} [shouldBubble] Should the event bubble? * @param {Number} [priority] The position the callback should take in the stack. 0 means top priority, and 1 means less priority than the most recently added. + * @param {Boolean} [shouldPreventDefault] Should call event.preventDefault after callback? * @returns {Function} clean up method */ -function subscribe(key, callback, descriptionKey, modifiers = 'shift', captureOnInputs = false, shouldBubble = false, priority = 0) { +function subscribe(key, callback, descriptionKey, modifiers = 'shift', captureOnInputs = false, shouldBubble = false, priority = 0, shouldPreventDefault = true) { const platformAdjustedModifiers = getPlatformEquivalentForKeys(modifiers); const displayName = getDisplayName(key, platformAdjustedModifiers); if (!_.has(eventHandlers, displayName)) { @@ -150,6 +153,7 @@ function subscribe(key, callback, descriptionKey, modifiers = 'shift', captureOn id: callbackID, callback, captureOnInputs, + shouldPreventDefault, shouldBubble, });