From 3312884a555a3d56283f6c3c03ccc4c9fa8b85a2 Mon Sep 17 00:00:00 2001 From: Jeremy Asuncion Date: Fri, 18 Oct 2024 12:41:02 -0700 Subject: [PATCH] fix: view tomogram open in new tab (#1251) Fixes issue with view tomogram button not opening external links in new tab. This works by passing the `Link` component to reuse the auto opening in new tab functionality for the `Button` component --- .../data-portal/app/components/Link/Link.tsx | 13 ++++++++++--- .../app/components/ViewTomogramButton.tsx | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/packages/data-portal/app/components/Link/Link.tsx b/frontend/packages/data-portal/app/components/Link/Link.tsx index 39149cb7c..2a972f820 100644 --- a/frontend/packages/data-portal/app/components/Link/Link.tsx +++ b/frontend/packages/data-portal/app/components/Link/Link.tsx @@ -13,12 +13,19 @@ export type VariantLinkProps = LinkProps & { } function BaseLink( - { to, variant, className, ...props }: VariantLinkProps, + { + href, + to, + variant, + className, + ...props + }: VariantLinkProps & { href?: string }, ref: ForwardedRef, ) { let newTabProps: Partial = {} + const url = href ?? to - if (typeof to === 'string' && isExternalUrl(to)) { + if (typeof url === 'string' && isExternalUrl(url)) { // For new tabs, add rel=noreferrer for security: // https://web.dev/external-anchors-use-rel-noopener/#how-to-improve-your-site's-performance-and-prevent-security-vulnerabilities newTabProps = { @@ -30,7 +37,7 @@ function BaseLink( return ( {t('viewTomogram')}