add target="_blank" prop to LinkText for safari (#606)
parent
cfdfd8f395
commit
28f7ff76a4
|
@ -66,6 +66,10 @@ export function isBskyAppUrl(url: string): boolean {
|
||||||
return url.startsWith('https://bsky.app/')
|
return url.startsWith('https://bsky.app/')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isExternalUrl(url: string): boolean {
|
||||||
|
return !isBskyAppUrl(url) && url.startsWith('http')
|
||||||
|
}
|
||||||
|
|
||||||
export function isBskyPostUrl(url: string): boolean {
|
export function isBskyPostUrl(url: string): boolean {
|
||||||
if (isBskyAppUrl(url)) {
|
if (isBskyAppUrl(url)) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, {ComponentProps} from 'react'
|
import React, {ComponentProps, useMemo} from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {
|
import {
|
||||||
Linking,
|
Linking,
|
||||||
|
@ -21,7 +21,7 @@ import {TypographyVariant} from 'lib/ThemeContext'
|
||||||
import {NavigationProp} from 'lib/routes/types'
|
import {NavigationProp} from 'lib/routes/types'
|
||||||
import {router} from '../../../routes'
|
import {router} from '../../../routes'
|
||||||
import {useStores, RootStoreModel} from 'state/index'
|
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 {isDesktopWeb} from 'platform/detection'
|
||||||
import {sanitizeUrl} from '@braintree/sanitize-url'
|
import {sanitizeUrl} from '@braintree/sanitize-url'
|
||||||
|
|
||||||
|
@ -132,6 +132,16 @@ export const TextLink = observer(function TextLink({
|
||||||
},
|
},
|
||||||
[store, navigation, href],
|
[store, navigation, href],
|
||||||
)
|
)
|
||||||
|
const hrefAttrs = useMemo(() => {
|
||||||
|
const isExternal = isExternalUrl(href)
|
||||||
|
if (isExternal) {
|
||||||
|
return {
|
||||||
|
target: '_blank',
|
||||||
|
// rel: 'noopener noreferrer',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
}, [href])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
|
@ -142,6 +152,8 @@ export const TextLink = observer(function TextLink({
|
||||||
lineHeight={lineHeight}
|
lineHeight={lineHeight}
|
||||||
// @ts-ignore web only -prf
|
// @ts-ignore web only -prf
|
||||||
dataSet={dataSet}
|
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}>
|
{...props}>
|
||||||
{text}
|
{text}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
Loading…
Reference in New Issue