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
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