Skip to content

Commit

Permalink
fix(DsfrHeaderMenuLink): 🐛 dĂ©prĂ©cie href
Browse files Browse the repository at this point in the history
- pour cohĂ©rence avec DsfrNavigationMenuLink qui peuvent ĂȘtre intĂ©grĂ©s Ă  l’en-tĂȘte
  • Loading branch information
laruiss committed Sep 15, 2024
1 parent 5550286 commit 700e319
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/components/DsfrHeader/DsfrHeader.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 8 additions & 4 deletions src/components/DsfrHeader/DsfrHeaderMenuLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 }
Expand Down

0 comments on commit 700e319

Please sign in to comment.