Fix open-in-new-tab for TextLink (#2773)
parent
76811657e8
commit
dc6603a1b9
|
@ -197,6 +197,15 @@ export const TextLink = memo(function TextLink({
|
||||||
href,
|
href,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
isWeb &&
|
||||||
|
href !== '#' &&
|
||||||
|
e != null &&
|
||||||
|
isModifiedEvent(e as React.MouseEvent)
|
||||||
|
) {
|
||||||
|
// Let the browser handle opening in new tab etc.
|
||||||
|
return
|
||||||
|
}
|
||||||
if (onPress) {
|
if (onPress) {
|
||||||
e?.preventDefault?.()
|
e?.preventDefault?.()
|
||||||
// @ts-ignore function signature differs by platform -prf
|
// @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)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue