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

Added onMouseDown prop to TextLink component, fixed issue of not able to open link with one click in BankAccountManualStep component #12940

Merged
merged 4 commits into from
Nov 24, 2022
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
13 changes: 9 additions & 4 deletions src/components/TextLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ const propTypes = {

/** Overwrites the default link behavior with a custom callback */
onPress: PropTypes.func,

/** Callback that is called when mousedown is triggered */
onMouseDown: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add comment for the onMouseDown prop like Callback that is called when mousedown is triggered.

};

const defaultProps = {
href: undefined,
style: [],
onPress: undefined,
onMouseDown: undefined,
};

const TextLink = (props) => {
const additionalStyles = _.isArray(props.style) ? props.style : [props.style];

/**
* @param {Event} event
*/
* @param {Event} event
*/
const openLink = (event) => {
event.preventDefault();
if (props.onPress) {
Expand All @@ -47,8 +51,8 @@ const TextLink = (props) => {
};

/**
* @param {Event} event
*/
* @param {Event} event
*/
const openLinkIfEnterKeyPressed = (event) => {
if (event.key !== 'Enter') {
return;
Expand All @@ -62,6 +66,7 @@ const TextLink = (props) => {
accessibilityRole="link"
href={props.href}
onPress={openLink}
onMouseDown={props.onMouseDown}
onKeyDown={openLinkIfEnterKeyPressed}
>
{props.children}
Expand Down
7 changes: 6 additions & 1 deletion src/pages/ReimbursementAccount/BankAccountManualStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ class BankAccountManualStep extends React.Component {
<Text>
{this.props.translate('common.iAcceptThe')}
</Text>
<TextLink href="https://use.expensify.com/terms">
<TextLink
href="https://use.expensify.com/terms"

// to call the onPress in the TextLink before the input blur is fired and shift the link element
onMouseDown={e => e.preventDefault()}
>
{`Expensify ${this.props.translate('common.termsOfService')}`}
</TextLink>
</View>
Expand Down