From 700e319641888ab1d034ccaea8e8304dbbd087aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanislas=20Ormi=C3=A8res?= Date: Sun, 15 Sep 2024 13:28:17 +0200 Subject: [PATCH] =?UTF-8?q?fix(DsfrHeaderMenuLink):=20=F0=9F=90=9B=20d?= =?UTF-8?q?=C3=A9pr=C3=A9cie=20href?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pour cohérence avec DsfrNavigationMenuLink qui peuvent être intégrés à l’en-tête --- src/components/DsfrHeader/DsfrHeader.types.ts | 6 ++++++ src/components/DsfrHeader/DsfrHeaderMenuLink.vue | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/DsfrHeader/DsfrHeader.types.ts b/src/components/DsfrHeader/DsfrHeader.types.ts index eeffb8e7..4712b343 100644 --- a/src/components/DsfrHeader/DsfrHeader.types.ts +++ b/src/components/DsfrHeader/DsfrHeader.types.ts @@ -12,7 +12,13 @@ export type DsfrHeaderMenuLinkProps = { target?: string onClick?: ($event: MouseEvent) => void to?: RouteLocationRaw + /** + * @deprecated Use the prop `to` instead + */ href?: string + /** + * @deprecated Use the prop `to` instead + */ path?: string } diff --git a/src/components/DsfrHeader/DsfrHeaderMenuLink.vue b/src/components/DsfrHeader/DsfrHeaderMenuLink.vue index 938da873..afe50f9f 100644 --- a/src/components/DsfrHeader/DsfrHeaderMenuLink.vue +++ b/src/components/DsfrHeader/DsfrHeaderMenuLink.vue @@ -21,10 +21,14 @@ const isPathString = computed(() => { return typeof props.path === 'string' }) const isExternalLink = computed(() => { - return props.href?.startsWith('http') || (isPathString.value && (props.path as string).startsWith('http')) + return props.href?.startsWith('http') || + (isPathString.value && (props.path as string).startsWith('http')) || + (typeof props.to === 'string' && (props.to as string).startsWith('http')) }) const isMailto = computed(() => { - return props.href?.startsWith('mailto') || (isPathString.value && (props.path as string).startsWith('mailto')) + return props.href?.startsWith('mailto') || + (isPathString.value && (props.path as string).startsWith('mailto')) || + (typeof props.to === 'string' && (props.to as string).startsWith('mailto')) }) const is = computed(() => { if (props.button) { @@ -37,13 +41,13 @@ const actualHref = computed(() => { if (!isExternalLink.value && !isMailto.value) { return undefined } - return props.href !== undefined ? props.href : props.path + return props.to ?? props.href ?? props.path }) const actualTo = computed(() => { if (isExternalLink.value || isMailto.value) { return undefined } - return props.to || props.path + return props.to ?? props.path }) const linkData = computed(() => { return actualTo.value ? { to: actualTo.value } : { href: actualHref.value }