Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: mWeb- Unable to move to another line by clicking "return" button #7920

Merged
merged 8 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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') {
ahmdshrif marked this conversation as resolved.
Show resolved Hide resolved
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 we call event.preventDefault after callback ?
ahmdshrif marked this conversation as resolved.
Show resolved Hide resolved
* @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