Fix open-in-new-tab for TextLink (#2773)

zio/stable
dan 2024-02-07 03:45:16 +00:00 committed by GitHub
parent 76811657e8
commit dc6603a1b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 0 deletions

View File

@ -197,6 +197,15 @@ export const TextLink = memo(function TextLink({
href,
})
}
if (
isWeb &&
href !== '#' &&
e != null &&
isModifiedEvent(e as React.MouseEvent)
) {
// Let the browser handle opening in new tab etc.
return
}
if (onPress) {
e?.preventDefault?.()
// @ts-ignore function signature differs by platform -prf
@ -382,3 +391,16 @@ function onPressInner(
}
}
}
function isModifiedEvent(e: React.MouseEvent): boolean {
const eventTarget = e.currentTarget as HTMLAnchorElement
const target = eventTarget.getAttribute('target')
return (
(target && target !== '_self') ||
e.metaKey ||
e.ctrlKey ||
e.shiftKey ||
e.altKey ||
(e.nativeEvent && e.nativeEvent.which === 2)
)
}