Skip to content

Commit 5310d56

Browse files
committed
fix(DsfrHeader): 🐛 ferme la modale en mobile au clic sur un lien du menu
1 parent b3ebb4b commit 5310d56

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

demo-app/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import VueDsfr from '@/index'
2-
import { Icon } from '@iconify/vue'
32

43
import { createApp } from 'vue'
54
import App from './App.vue'
@@ -14,7 +13,6 @@ import '@gouvfr/dsfr/dist/utility/icons/icons.main.min.css'
1413

1514
createApp(App)
1615
.use(router)
17-
.component('Icon', Icon)
1816
.use(VueDsfr)
1917
.mount('#app')
2018

demo-app/views/AppHome.vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const onClick = () => {
7070
}, 2000)
7171
}
7272
73-
const expandedId = ref('')
73+
const activeAccordion = ref(-1)
7474
</script>
7575

7676
<template>
@@ -111,19 +111,20 @@ const expandedId = ref('')
111111
</h2>
112112

113113
<div>
114-
<DsfrAccordion
115-
id="accordion-1"
116-
style="position: relative;"
117-
title="Accordéon avec infobulle"
118-
:expanded-id="expandedId"
119-
@expand="expandedId = $event"
114+
<DsfrAccordionsGroup
115+
v-model="activeAccordion"
120116
>
121-
Test infobulle dans accordéon
122-
<DsfrTooltip
123-
124-
content="Texte de l’info-bulle qui apparaît au survol"
125-
/>
126-
</DsfrAccordion>
117+
<DsfrAccordion
118+
style="position: relative;"
119+
title="Accordéon avec infobulle"
120+
>
121+
Test infobulle dans accordéon
122+
<DsfrTooltip
123+
124+
content="Texte de l’info-bulle qui apparaît au survol"
125+
/>
126+
</DsfrAccordion>
127+
</DsfrAccordionsGroup>
127128
</div>
128129

129130
<div class="flex justify-between w-full relative">

src/components/DsfrAccordion/DsfrAccordionsGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { computed, onUnmounted, provide, ref, type Ref, watch } from 'vue'
44
import { registerTabKey } from './injection-key'
55
66
const props = withDefaults(defineProps<{
7-
modelValue: number
7+
modelValue?: number
88
}>(), {
99
modelValue: -1,
1010
})

src/components/DsfrHeader/DsfrHeader.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script lang="ts" setup>
2-
import { computed, onMounted, onUnmounted, ref, toRef, useSlots } from 'vue'
2+
import { computed, onMounted, onUnmounted, provide, ref, toRef, useSlots } from 'vue'
33
44
import DsfrLanguageSelector, { type DsfrLanguageSelectorElement } from '../DsfrLanguageSelector/DsfrLanguageSelector.vue'
55
import DsfrLogo from '../DsfrLogo/DsfrLogo.vue'
66
import DsfrSearchBar from '../DsfrSearchBar/DsfrSearchBar.vue'
77
import DsfrHeaderMenuLinks from './DsfrHeaderMenuLinks.vue'
8+
import { registerNavigationLinkKey } from './injection-key'
89
910
import type { DsfrHeaderProps } from './DsfrHeader.types'
1011
@@ -79,6 +80,9 @@ const onQuickLinkClick = hideModal
7980
const slots = useSlots()
8081
const isWithSlotOperator = computed(() => Boolean(slots.operator?.().length) || !!props.operatorImgSrc)
8182
const isWithSlotNav = computed(() => Boolean(slots.mainnav))
83+
provide(registerNavigationLinkKey, () => {
84+
return hideModal
85+
})
8286
</script>
8387

8488
<template>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { InjectionKey } from 'vue'
2+
3+
type RegisterNavigationLink = () => () => void
4+
5+
export const registerNavigationLinkKey: InjectionKey<RegisterNavigationLink> = Symbol('header')

src/components/DsfrNavigation/DsfrNavigationMenuLink.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script lang="ts" setup>
2-
import { computed } from 'vue'
2+
import { computed, hasInjectionContext, inject } from 'vue'
33
import { 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'
78
import type { DsfrNavigationMenuLinkProps } from './DsfrNavigation.types'
89
910
export 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

Comments
 (0)