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,7 +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)"
42+ @click =" $emit('toggleId', id); onClick($event) "
3943 >
4044 {{ text }}
4145 </a >
@@ -47,7 +51,7 @@ const iconProps = computed(() => (dsfrIcon.value || !props.icon)
4751 :class =" {
4852 [String(icon)]: dsfrIcon,
4953 }"
50- @click =" $emit('toggleId', id)"
54+ @click =" closeModal(); $emit('toggleId', id); onClick?.($event )"
5155 >
5256 <VIcon
5357 v-if =" icon && iconProps"
0 commit comments