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 1 commit
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
11 changes: 7 additions & 4 deletions src/components/TextLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ const propTypes = {

/** Overwrites the default link behavior with a custom callback */
onPress: PropTypes.func,
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: '',
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 +49,8 @@ const TextLink = (props) => {
};

/**
* @param {Event} event
*/
* @param {Event} event
*/
const openLinkIfEnterKeyPressed = (event) => {
if (event.key !== 'Enter') {
return;
Expand All @@ -62,6 +64,7 @@ const TextLink = (props) => {
accessibilityRole="link"
href={props.href}
onPress={openLink}
onMouseDown={props.onMouseDown}
onKeyDown={openLinkIfEnterKeyPressed}
>
{props.children}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReimbursementAccount/BankAccountManualStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ 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" onMouseDown={e => e.preventDefault()}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a comment on why we adding this line and what the issue is.

{`Expensify ${this.props.translate('common.termsOfService')}`}
</TextLink>
</View>
Expand Down