Skip to content

Commit bb40dc7

Browse files
authored
Merge pull request #936 from dnum-mi/docs/dsfr-header-menu-link-mark-href-as-deprecated
fix(DsfrHeaderMenuLink): 🐛 déprécie href
2 parents 5550286 + 700e319 commit bb40dc7

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/components/DsfrHeader/DsfrHeader.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ export type DsfrHeaderMenuLinkProps = {
1212
target?: string
1313
onClick?: ($event: MouseEvent) => void
1414
to?: RouteLocationRaw
15+
/**
16+
* @deprecated Use the prop `to` instead
17+
*/
1518
href?: string
19+
/**
20+
* @deprecated Use the prop `to` instead
21+
*/
1622
path?: string
1723
}
1824

src/components/DsfrHeader/DsfrHeaderMenuLink.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ const isPathString = computed(() => {
2121
return typeof props.path === 'string'
2222
})
2323
const isExternalLink = computed(() => {
24-
return props.href?.startsWith('http') || (isPathString.value && (props.path as string).startsWith('http'))
24+
return props.href?.startsWith('http') ||
25+
(isPathString.value && (props.path as string).startsWith('http')) ||
26+
(typeof props.to === 'string' && (props.to as string).startsWith('http'))
2527
})
2628
const isMailto = computed(() => {
27-
return props.href?.startsWith('mailto') || (isPathString.value && (props.path as string).startsWith('mailto'))
29+
return props.href?.startsWith('mailto') ||
30+
(isPathString.value && (props.path as string).startsWith('mailto')) ||
31+
(typeof props.to === 'string' && (props.to as string).startsWith('mailto'))
2832
})
2933
const is = computed(() => {
3034
if (props.button) {
@@ -37,13 +41,13 @@ const actualHref = computed(() => {
3741
if (!isExternalLink.value && !isMailto.value) {
3842
return undefined
3943
}
40-
return props.href !== undefined ? props.href : props.path
44+
return props.to ?? props.href ?? props.path
4145
})
4246
const actualTo = computed(() => {
4347
if (isExternalLink.value || isMailto.value) {
4448
return undefined
4549
}
46-
return props.to || props.path
50+
return props.to ?? props.path
4751
})
4852
const linkData = computed(() => {
4953
return actualTo.value ? { to: actualTo.value } : { href: actualHref.value }

0 commit comments

Comments
 (0)