Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 6 additions & 2 deletions src/libs/KeyboardShortcut/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand All @@ -150,6 +153,7 @@ function subscribe(key, callback, descriptionKey, modifiers = 'shift', captureOn
id: callbackID,
callback,
captureOnInputs,
shouldPreventDefault,
shouldBubble,
});

Expand Down