diff --git a/src/components/TextLink.js b/src/components/TextLink.js index 8a56af8341ad..55344d987139 100644 --- a/src/components/TextLink.js +++ b/src/components/TextLink.js @@ -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 ( { - e.preventDefault(); - if (props.onPress) { - props.onPress(); - return; - } - - Linking.openURL(props.href); - }} + onPress={openLink} + onKeyDown={openLinkIfEnterKeyPressed} > {props.children}