Skip to content

Commit 1eacc5a

Browse files
authored
Merge pull request #1233 from MaitreManuel/fix-title-dsfr-pagination-again
Correction améliorée de l'accessibilité de DsfrPagination
2 parents 0c1feae + f557569 commit 1eacc5a

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

src/components/DsfrPagination/DsfrPagination.spec.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -87,39 +87,6 @@ describe('DsfrPagination', () => {
8787
})
8888
})
8989

90-
it('should render a list of links with appropriate title', async () => {
91-
// Given
92-
const pages = makePages(6)
93-
94-
// When
95-
const { getByRole } = render(Pagination, {
96-
global: { components: { VIcon } },
97-
props: {
98-
pages,
99-
currentPage: 2,
100-
truncLimit: 4,
101-
firstPageTitle: 'Première page',
102-
lastPageTitle: 'Dernière page',
103-
nextPageTitle: 'Page suivante',
104-
prevPageTitle: 'Page précédente',
105-
currentPageTitleSuffix: ' - page courante',
106-
ellipsisTitle: 'Pages intermédiaires non affichées',
107-
},
108-
})
109-
110-
const nextLink = getByRole('link', { name: 'Page suivante' })
111-
const prevLink = getByRole('link', { name: 'Page précédente' })
112-
const firstLink = getByRole('link', { name: 'Première page' })
113-
const lastLink = getByRole('link', { name: 'Dernière page' })
114-
const currentLink = getByRole('link', { current: 'page' })
115-
// Then
116-
expect(nextLink.getAttribute('title')).toBe('Page suivante')
117-
expect(prevLink.getAttribute('title')).toBe('Page précédente')
118-
expect(firstLink.getAttribute('title')).toBe('Première page')
119-
expect(lastLink.getAttribute('title')).toBe('Dernière page')
120-
expect(currentLink.getAttribute('title')).toBe('page 3 - page courante')
121-
})
122-
12390
it('renders navigation with default aria-label', () => {
12491
// Given
12592
const pages = makePages(3)
@@ -201,7 +168,7 @@ describe('DsfrPagination', () => {
201168
if (link.ariaCurrent === 'page') {
202169
expect(link.getAttribute('title')).toBe(`page ${index + 1} - page courante`)
203170
} else {
204-
expect(link.getAttribute('title')).toBe(`page ${index + 1}`)
171+
expect(link.getAttribute('title')).toBe(null)
205172
}
206173
})
207174
})

src/components/DsfrPagination/DsfrPagination.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ const toPreviousPage = () => toPage(Math.max(0, props.currentPage - 1))
3838
const toNextPage = () => toPage(Math.min(props.pages.length - 1, props.currentPage + 1))
3939
const toLastPage = () => toPage(props.pages.length - 1)
4040
const isCurrentPage = (page: Page) => props.pages.indexOf(page) === props.currentPage
41+
const pageTitle = (page: Page) => {
42+
if (isCurrentPage(page) && page.title) {
43+
if (props.currentPageTitleSuffix) {
44+
return `${page.title}${props.currentPageTitleSuffix}`
45+
}
46+
47+
if (page.label !== page.title) {
48+
return page.title
49+
}
50+
}
51+
52+
return undefined
53+
}
4154
</script>
4255

4356
<template>
@@ -52,7 +65,6 @@ const isCurrentPage = (page: Page) => props.pages.indexOf(page) === props.curren
5265
:href="pages[0]?.href"
5366
class="fr-pagination__link fr-pagination__link--first"
5467
:class="{ 'fr-pagination__link--disabled': currentPage === 0 }"
55-
:title="firstPageTitle"
5668
:aria-disabled="currentPage === 0 ? true : undefined"
5769
@click.prevent="currentPage === 0 ? null : tofirstPage()"
5870
>
@@ -64,7 +76,6 @@ const isCurrentPage = (page: Page) => props.pages.indexOf(page) === props.curren
6476
:href="pages[Math.max(currentPage - 1, 0)]?.href"
6577
class="fr-pagination__link fr-pagination__link--prev fr-pagination__link--lg-label"
6678
:class="{ 'fr-pagination__link--disabled': currentPage === 0 }"
67-
:title="prevPageTitle"
6879
:aria-disabled="currentPage === 0 ? true : undefined"
6980
@click.prevent="currentPage === 0 ? null : toPreviousPage()"
7081
>{{ prevPageTitle }}</a>
@@ -79,7 +90,7 @@ const isCurrentPage = (page: Page) => props.pages.indexOf(page) === props.curren
7990
<a
8091
:href="page?.href"
8192
class="fr-pagination__link fr-unhidden-lg"
82-
:title="(isCurrentPage(page) && page.title) ? (currentPageTitleSuffix) ? page.title + currentPageTitleSuffix : page.title : (page.title !== page.label) ? page.title : undefined"
93+
:title="pageTitle(page)"
8394
:aria-current="isCurrentPage(page) ? 'page' : undefined"
8495
@click.prevent="toPage(pages.indexOf(page))"
8596
>
@@ -103,7 +114,6 @@ const isCurrentPage = (page: Page) => props.pages.indexOf(page) === props.curren
103114
:href="pages[Math.min(currentPage + 1, pages.length - 1)]?.href"
104115
class="fr-pagination__link fr-pagination__link--next fr-pagination__link--lg-label"
105116
:class="{ 'fr-pagination__link--disabled': currentPage === pages.length - 1 }"
106-
:title="nextPageTitle"
107117
:disabled="currentPage === pages.length - 1 ? true : undefined"
108118
:aria-disabled="currentPage === pages.length - 1 ? true : undefined"
109119
@click.prevent="currentPage === pages.length - 1 ? null : toNextPage()"
@@ -114,7 +124,6 @@ const isCurrentPage = (page: Page) => props.pages.indexOf(page) === props.curren
114124
:href="pages.at(-1)?.href"
115125
class="fr-pagination__link fr-pagination__link--last"
116126
:class="{ 'fr-pagination__link--disabled': currentPage === pages.length - 1 }"
117-
:title="lastPageTitle"
118127
:disabled="currentPage === pages.length - 1 ? true : undefined"
119128
:aria-disabled="currentPage === pages.length - 1 ? true : undefined"
120129
@click.prevent="currentPage === pages.length - 1 ? null : toLastPage()"
@@ -129,8 +138,8 @@ const isCurrentPage = (page: Page) => props.pages.indexOf(page) === props.curren
129138
<style scoped>
130139
.fr-pagination__link:hover {
131140
background-image: linear-gradient(
132-
deg, rgba(224,224,224,0.5), rgba(224,224,224,0.5));
133-
}
141+
deg, rgba(224,224,224,0.5), rgba(224,224,224,0.5));
142+
}
134143
.fr-pagination__link--disabled {
135144
color: currentColor;
136145
cursor: not-allowed;

0 commit comments

Comments
 (0)