11<script lang="ts" setup>
2- import { computed } from ' vue'
2+ import { computed , hasInjectionContext , inject } from ' vue'
33import { getRandomId } from ' ../../utils/random-utils'
44
5- import VIcon from ' ../VIcon/VIcon.vue '
5+ import { registerNavigationLinkKey } from ' ../DsfrHeader/injection-key '
66
7+ import VIcon from ' ../VIcon/VIcon.vue'
78import type { DsfrNavigationMenuLinkProps } from ' ./DsfrNavigation.types'
89
910export type { DsfrNavigationMenuLinkProps }
@@ -27,6 +28,9 @@ const iconProps = computed(() => (dsfrIcon.value || !props.icon)
2728 ? { scale: defaultScale , name: props .icon }
2829 : { scale: defaultScale , ... ((props .icon as Record <string , string >) || {}) },
2930)
31+
32+ const useHeader = hasInjectionContext () ? inject (registerNavigationLinkKey )! : undefined
33+ const closeModal = useHeader ?.() ?? (() => {})
3034 </script >
3135
3236<template >
@@ -35,8 +39,7 @@ const iconProps = computed(() => (dsfrIcon.value || !props.icon)
3539 class =" fr-nav__link"
3640 data-testid =" nav-external-link"
3741 :href =" (to as string)"
38- @click =" $emit('toggleId', id)"
39- @click.stop =" onClick($event)"
42+ @click =" $emit('toggleId', id); onClick($event)"
4043 >
4144 {{ text }}
4245 </a >
@@ -48,8 +51,7 @@ const iconProps = computed(() => (dsfrIcon.value || !props.icon)
4851 :class =" {
4952 [String(icon)]: dsfrIcon,
5053 }"
51- @click =" $emit('toggleId', id)"
52- @click.stop =" onClick($event)"
54+ @click =" closeModal(); $emit('toggleId', id); onClick?.($event)"
5355 >
5456 <VIcon
5557 v-if =" icon && iconProps"
0 commit comments