Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DsfrNavigationMenuLink): 🐛 utilise onClick passé en prop #927

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions demo-app/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import VueDsfr from '@/index'
import { Icon } from '@iconify/vue'

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

createApp(App)
.use(router)
.component('Icon', Icon)
.use(VueDsfr)
.mount('#app')

Expand Down
27 changes: 14 additions & 13 deletions demo-app/views/AppHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const onClick = () => {
}, 2000)
}

const expandedId = ref('')
const activeAccordion = ref(-1)
</script>

<template>
Expand Down Expand Up @@ -111,19 +111,20 @@ const expandedId = ref('')
</h2>

<div>
<DsfrAccordion
id="accordion-1"
style="position: relative;"
title="Accordéon avec infobulle"
:expanded-id="expandedId"
@expand="expandedId = $event"
<DsfrAccordionsGroup
v-model="activeAccordion"
>
Test infobulle dans accordéon
<DsfrTooltip

content="Texte de l’info-bulle qui apparaît au survol"
/>
</DsfrAccordion>
<DsfrAccordion
style="position: relative;"
title="Accordéon avec infobulle"
>
Test infobulle dans accordéon
<DsfrTooltip

content="Texte de l’info-bulle qui apparaît au survol"
/>
</DsfrAccordion>
</DsfrAccordionsGroup>
</div>

<div class="flex justify-between w-full relative">
Expand Down
2 changes: 1 addition & 1 deletion src/components/DsfrAccordion/DsfrAccordionsGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { computed, onUnmounted, provide, ref, type Ref, watch } from 'vue'
import { registerTabKey } from './injection-key'

const props = withDefaults(defineProps<{
modelValue: number
modelValue?: number
}>(), {
modelValue: -1,
})
Expand Down
6 changes: 5 additions & 1 deletion src/components/DsfrHeader/DsfrHeader.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts" setup>
import { computed, onMounted, onUnmounted, ref, toRef, useSlots } from 'vue'
import { computed, onMounted, onUnmounted, provide, ref, toRef, useSlots } from 'vue'

import DsfrLanguageSelector, { type DsfrLanguageSelectorElement } from '../DsfrLanguageSelector/DsfrLanguageSelector.vue'
import DsfrLogo from '../DsfrLogo/DsfrLogo.vue'
import DsfrSearchBar from '../DsfrSearchBar/DsfrSearchBar.vue'
import DsfrHeaderMenuLinks from './DsfrHeaderMenuLinks.vue'
import { registerNavigationLinkKey } from './injection-key'

import type { DsfrHeaderProps } from './DsfrHeader.types'

Expand Down Expand Up @@ -79,6 +80,9 @@ const onQuickLinkClick = hideModal
const slots = useSlots()
const isWithSlotOperator = computed(() => Boolean(slots.operator?.().length) || !!props.operatorImgSrc)
const isWithSlotNav = computed(() => Boolean(slots.mainnav))
provide(registerNavigationLinkKey, () => {
return hideModal
})
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DsfrHeader/DsfrHeaderMenuLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const iconProps = computed(() => typeof props.icon === 'string'
}"
v-bind="linkData"
:target="target"
@click.stop="onClick"
@click.stop="onClick($event)"
>
<template
v-if="!dsfrIcon && (icon || iconAttrs?.name) && !iconRight"
Expand Down
5 changes: 5 additions & 0 deletions src/components/DsfrHeader/injection-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { InjectionKey } from 'vue'

type RegisterNavigationLink = () => () => void

export const registerNavigationLinkKey: InjectionKey<RegisterNavigationLink> = Symbol('header')
12 changes: 8 additions & 4 deletions src/components/DsfrNavigation/DsfrNavigationMenuLink.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { computed, hasInjectionContext, inject } from 'vue'
import { getRandomId } from '../../utils/random-utils'

import VIcon from '../VIcon/VIcon.vue'
import { registerNavigationLinkKey } from '../DsfrHeader/injection-key'

import VIcon from '../VIcon/VIcon.vue'
import type { DsfrNavigationMenuLinkProps } from './DsfrNavigation.types'

export type { DsfrNavigationMenuLinkProps }
Expand All @@ -27,6 +28,9 @@ const iconProps = computed(() => (dsfrIcon.value || !props.icon)
? { scale: defaultScale, name: props.icon }
: { scale: defaultScale, ...((props.icon as Record<string, string>) || {}) },
)

const useHeader = hasInjectionContext() ? inject(registerNavigationLinkKey)! : undefined
const closeModal = useHeader?.() ?? (() => {})
</script>

<template>
Expand All @@ -35,7 +39,7 @@ const iconProps = computed(() => (dsfrIcon.value || !props.icon)
class="fr-nav__link"
data-testid="nav-external-link"
:href="(to as string)"
@click="$emit('toggleId', id)"
@click="$emit('toggleId', id); onClick($event)"
>
{{ text }}
</a>
Expand All @@ -47,7 +51,7 @@ const iconProps = computed(() => (dsfrIcon.value || !props.icon)
:class="{
[String(icon)]: dsfrIcon,
}"
@click="$emit('toggleId', id)"
@click="closeModal(); $emit('toggleId', id); onClick?.($event)"
>
<VIcon
v-if="icon && iconProps"
Expand Down
Loading