about summary refs log tree commit diff
path: root/src/view/com
diff options
context:
space:
mode:
authorAnsh <anshnanda10@gmail.com>2023-05-09 13:01:42 -0400
committerGitHub <noreply@github.com>2023-05-09 12:01:42 -0500
commit28f7ff76a4d7cb756d63f1cb6224965ce26cd6f8 (patch)
tree0b6fe4f26eb62a534cf3f27cfec0557e5242cb9c /src/view/com
parentcfdfd8f39514a3d8edea373ad7d170c71ec2652b (diff)
downloadvoidsky-28f7ff76a4d7cb756d63f1cb6224965ce26cd6f8.tar.zst
add target="_blank" prop to LinkText for safari (#606)
Diffstat (limited to 'src/view/com')
-rw-r--r--src/view/com/util/Link.tsx16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/view/com/util/Link.tsx b/src/view/com/util/Link.tsx
index 253f80bdc..f753f01cc 100644
--- a/src/view/com/util/Link.tsx
+++ b/src/view/com/util/Link.tsx
@@ -1,4 +1,4 @@
-import React, {ComponentProps} from 'react'
+import React, {ComponentProps, useMemo} from 'react'
 import {observer} from 'mobx-react-lite'
 import {
   Linking,
@@ -21,7 +21,7 @@ import {TypographyVariant} from 'lib/ThemeContext'
 import {NavigationProp} from 'lib/routes/types'
 import {router} from '../../../routes'
 import {useStores, RootStoreModel} from 'state/index'
-import {convertBskyAppUrlIfNeeded} from 'lib/strings/url-helpers'
+import {convertBskyAppUrlIfNeeded, isExternalUrl} from 'lib/strings/url-helpers'
 import {isDesktopWeb} from 'platform/detection'
 import {sanitizeUrl} from '@braintree/sanitize-url'
 
@@ -132,6 +132,16 @@ export const TextLink = observer(function TextLink({
     },
     [store, navigation, href],
   )
+  const hrefAttrs = useMemo(() => {
+    const isExternal = isExternalUrl(href)
+    if (isExternal) {
+      return {
+        target: '_blank',
+        // rel: 'noopener noreferrer',
+      }
+    }
+    return {}
+  }, [href])
 
   return (
     <Text
@@ -142,6 +152,8 @@ export const TextLink = observer(function TextLink({
       lineHeight={lineHeight}
       // @ts-ignore web only -prf
       dataSet={dataSet}
+      // @ts-ignore web only -prf
+      hrefAttrs={hrefAttrs} // hack to get open in new tab to work on safari. without this, safari will open in a new window
       {...props}>
       {text}
     </Text>