From 2ec1c7bef4b463f935982193800c83b32298c7a9 Mon Sep 17 00:00:00 2001 From: Fran McDade Date: Mon, 5 Aug 2024 14:25:36 +1000 Subject: [PATCH] feat: link component internal url test should include hash routes (#147) --- src/components/Links/common/utils.ts | 2 +- src/components/Links/components/Link/link.tsx | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/Links/common/utils.ts b/src/components/Links/common/utils.ts index 364407cc..3c970f68 100644 --- a/src/components/Links/common/utils.ts +++ b/src/components/Links/common/utils.ts @@ -7,7 +7,7 @@ import { Url, UrlObjectWithHrefAndQuery } from "./entities"; * @returns true if the given link is an internal link. */ export function isClientSideNavigation(link: string): boolean { - return /^\/(?!\/)/.test(link); + return /^\/(?!\/)|^#/.test(link); } /** diff --git a/src/components/Links/components/Link/link.tsx b/src/components/Links/components/Link/link.tsx index 9da43db8..65c95f2c 100644 --- a/src/components/Links/components/Link/link.tsx +++ b/src/components/Links/components/Link/link.tsx @@ -36,6 +36,7 @@ export const Link = ({ target, TypographyProps, url, + ...props /* Spread props to allow for specific MuiLink prop overrides. */ }: LinkProps): JSX.Element => { if (isURLObjectWithHrefAndQuery(url)) { /* Internal navigation - explore link */ @@ -62,6 +63,7 @@ export const Link = ({ target={target || ANCHOR_TARGET.SELF} onClick={onClick} {...TypographyProps} + {...props} > {label} @@ -82,6 +84,7 @@ export const Link = ({ rel={REL_ATTRIBUTE.NO_OPENER_NO_REFERRER} target={target || ANCHOR_TARGET.BLANK} {...TypographyProps} + {...props} > {label} @@ -92,7 +95,12 @@ export const Link = ({ } /* Invalid URL */ return ( - + {label} );