Skip to content

Commit e837b25

Browse files
committed
fix: 🐛 ajoute de l'attribut id au composant DsfrNavigationItem depuis le composant DsfrNavigation
1 parent d9bba2b commit e837b25

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

demo-app/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, ref } from 'vue'
2+
import { computed, ref, useId } from 'vue'
33
import { useRoute } from 'vue-router'
44
55
import DsfrBreadcrumb from '../src/components/DsfrBreadcrumb/DsfrBreadcrumb.vue'
@@ -64,6 +64,7 @@ const quickLinks: DsfrHeaderProps['quickLinks'] = [
6464
const route = useRoute()
6565
const navItems: DsfrNavigationProps['navItems'] = [
6666
{
67+
id: useId(),
6768
to: { name: 'Home' },
6869
text: 'Accueil',
6970
},

src/components/DsfrNavigation/DsfrNavigation.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ onUnmounted(() => {
7878
<slot />
7979
<DsfrNavigationItem
8080
v-for="(navItem, idx) of navItems"
81+
:id="navItem.id"
8182
:key="idx"
8283
>
8384
<DsfrNavigationMenuLink

src/components/DsfrNavigation/DsfrNavigationItem.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { render } from '@testing-library/vue'
22
// import '@gouvfr/dsfr/dist/core/core.module.js'
3+
import { useId } from 'vue-demi'
34

45
import DsfrNavigationItem from './DsfrNavigationItem.vue'
56

67
describe('DsfrNavigationItem', () => {
78
it('should render a navigation item', () => {
89
const content = 'Contenu d’un item de menu de navigation'
9-
10+
const id = useId()
1011
const { getByText } = render(DsfrNavigationItem, {
12+
props: {
13+
id,
14+
},
1115
slots: {
1216
default: content,
1317
},
@@ -18,5 +22,6 @@ describe('DsfrNavigationItem', () => {
1822
expect(liEl).toHaveClass('fr-nav__item')
1923
expect(liEl).not.toHaveClass('fr-nav__item--active')
2024
expect(liEl).toHaveAttribute('id')
25+
expect(liEl.id).toBe(id)
2126
})
2227
})

0 commit comments

Comments
 (0)