Skip to content

Commit

Permalink
Merge pull request #12034 from dhairyasenjaliya/enterKeyEvent
Browse files Browse the repository at this point in the history
onKeyDown added to Textlink component
  • Loading branch information
tgolen authored Nov 3, 2022
2 parents 0610934 + d0ad7de commit 1dd7174
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/components/TextLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,37 @@ const defaultProps = {

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

/**
* @param {Event} event
*/
const openLink = (event) => {
event.preventDefault();
if (props.onPress) {
props.onPress();
return;
}

Linking.openURL(props.href);
};

/**
* @param {Event} event
*/
const openLinkIfEnterKeyPressed = (event) => {
if (event.key !== 'Enter') {
return;
}
openLink(event);
};

return (
<Text
style={[styles.link, ...additionalStyles]}
accessibilityRole="link"
href={props.href}
onPress={(e) => {
e.preventDefault();
if (props.onPress) {
props.onPress();
return;
}

Linking.openURL(props.href);
}}
onPress={openLink}
onKeyDown={openLinkIfEnterKeyPressed}
>
{props.children}
</Text>
Expand Down

0 comments on commit 1dd7174

Please sign in to comment.