diff --git a/src/components/Button/index.js b/src/components/Button/index.js
index 4ca933a45d6f..dc12a4ded5c2 100644
--- a/src/components/Button/index.js
+++ b/src/components/Button/index.js
@@ -18,6 +18,9 @@ import PressableWithFeedback from '../Pressable/PressableWithFeedback';
import refPropTypes from '../refPropTypes';
const propTypes = {
+ /** Should the press event bubble across multiple instances when Enter key triggers it. */
+ allowBubble: PropTypes.bool,
+
/** The text for the button label */
text: PropTypes.string,
@@ -123,6 +126,7 @@ const propTypes = {
};
const defaultProps = {
+ allowBubble: false,
text: '',
shouldShowRightIcon: false,
icon: null,
@@ -183,7 +187,7 @@ class Button extends Component {
shortcutConfig.descriptionKey,
shortcutConfig.modifiers,
true,
- false,
+ this.props.allowBubble,
this.props.enterKeyEventListenerPriority,
false,
);
diff --git a/src/components/ButtonWithDropdownMenu.js b/src/components/ButtonWithDropdownMenu.js
index 54d6c0deac5a..a0a6e276bc28 100644
--- a/src/components/ButtonWithDropdownMenu.js
+++ b/src/components/ButtonWithDropdownMenu.js
@@ -19,6 +19,9 @@ const propTypes = {
/** Callback to execute when the main button is pressed */
onPress: PropTypes.func.isRequired,
+ /** Call the onPress function on main button when Enter key is pressed */
+ pressOnEnter: PropTypes.bool,
+
/** Whether we should show a loading state for the main button */
isLoading: PropTypes.bool,
@@ -57,6 +60,7 @@ const propTypes = {
const defaultProps = {
isLoading: false,
isDisabled: false,
+ pressOnEnter: false,
menuHeaderText: '',
style: [],
buttonSize: CONST.DROPDOWN_BUTTON_SIZE.MEDIUM,
@@ -101,6 +105,7 @@ function ButtonWithDropdownMenu(props) {
diff --git a/src/stories/Button.stories.js b/src/stories/Button.stories.js
index 52212e673f0f..9fec08800f0a 100644
--- a/src/stories/Button.stories.js
+++ b/src/stories/Button.stories.js
@@ -1,5 +1,8 @@
+/* eslint-disable react/jsx-props-no-spreading */
import React, {useCallback, useState} from 'react';
+import {View} from 'react-native';
import Button from '../components/Button';
+import Text from '../components/Text';
/**
* We use the Component Story Format for writing stories. Follow the docs here:
@@ -28,7 +31,6 @@ function PressOnEnter(props) {
}, []);
return (
+ Both buttons will trigger on press of Enter as the Enter event will bubble across all instances of button.
+
+
+
+
+ >
+ );
+}
+
Default.args = {
text: 'Save & Continue',
success: true,
@@ -53,5 +73,12 @@ PressOnEnter.args = {
success: true,
};
+PressOnEnterWithBubbling.args = {
+ pressOnEnter: true,
+ success: true,
+ medium: true,
+ allowBubble: true,
+};
+
export default story;
-export {Default, Loading, PressOnEnter};
+export {Default, Loading, PressOnEnter, PressOnEnterWithBubbling};
diff --git a/src/stories/ButtonWithDropdownMenu.stories.js b/src/stories/ButtonWithDropdownMenu.stories.js
index 7629a6ff0e17..88fa73c20fa1 100644
--- a/src/stories/ButtonWithDropdownMenu.stories.js
+++ b/src/stories/ButtonWithDropdownMenu.stories.js
@@ -21,9 +21,13 @@ function Template(args) {
const Default = Template.bind({});
Default.args = {
buttonText: 'Pay using Expensify',
+ onPress: (e, item) => {
+ alert(`Button ${item} is pressed.`);
+ },
+ pressOnEnter: true,
options: [
- {value: 1, text: 'One'},
- {value: 2, text: 'Two'},
+ {value: 'One', text: 'One'},
+ {value: 'Two', text: 'Two'},
],
};