Skip to content

Commit

Permalink
Merge pull request #976 from dnum-mi/fix/give-id-to-dsfr-navigation-item
Browse files Browse the repository at this point in the history
feat(DsfrNavigation): 🐛 ajoute de l'attribut `id` au composant `DsfrNavigationItem` depuis le composant `DsfrNavigation`
  • Loading branch information
laruiss authored Nov 19, 2024
2 parents d9bba2b + b1e9af0 commit f4154d4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion demo-app/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { computed, ref, useId } from 'vue'
import { useRoute } from 'vue-router'
import DsfrBreadcrumb from '../src/components/DsfrBreadcrumb/DsfrBreadcrumb.vue'
Expand Down Expand Up @@ -64,6 +64,7 @@ const quickLinks: DsfrHeaderProps['quickLinks'] = [
const route = useRoute()
const navItems: DsfrNavigationProps['navItems'] = [
{
id: useId(),
to: { name: 'Home' },
text: 'Accueil',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"@iconify/vue": "^4.1.2",
"vue": "^3.4.38",
"vue": "^3.5.13",
"vue-router": "^4.4.3"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/components/DsfrNavigation/DsfrNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ onUnmounted(() => {
<slot />
<DsfrNavigationItem
v-for="(navItem, idx) of navItems"
:id="navItem.id"
:key="idx"
>
<DsfrNavigationMenuLink
Expand Down
7 changes: 6 additions & 1 deletion src/components/DsfrNavigation/DsfrNavigationItem.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { render } from '@testing-library/vue'
// import '@gouvfr/dsfr/dist/core/core.module.js'
import { useId } from 'vue'

import DsfrNavigationItem from './DsfrNavigationItem.vue'

describe('DsfrNavigationItem', () => {
it('should render a navigation item', () => {
const content = 'Contenu d’un item de menu de navigation'

const id = useId()
const { getByText } = render(DsfrNavigationItem, {
props: {
id,
},
slots: {
default: content,
},
Expand All @@ -18,5 +22,6 @@ describe('DsfrNavigationItem', () => {
expect(liEl).toHaveClass('fr-nav__item')
expect(liEl).not.toHaveClass('fr-nav__item--active')
expect(liEl).toHaveAttribute('id')
expect(liEl.id).toBe(id)
})
})

0 comments on commit f4154d4

Please sign in to comment.