Skip to content

Commit

Permalink
Merge pull request #936 from dnum-mi/docs/dsfr-header-menu-link-mark-…
Browse files Browse the repository at this point in the history
…href-as-deprecated

fix(DsfrHeaderMenuLink): 🐛 déprécie href
  • Loading branch information
laruiss authored Sep 15, 2024
2 parents 5550286 + 700e319 commit bb40dc7
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 bb40dc7

Please sign in to comment.