Skip to content

Commit f7fff79

Browse files
authored
Merge pull request #6447 from alphagov/fix-pagination-empty-items-v6
2 parents 9e70113 + 8113509 commit f7fff79

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ We've made fixes to GOV.UK Frontend in the following pull requests:
267267

268268
- [#5311: Remove non-operational value parameter from file upload component](https://github.com/alphagov/govuk-frontend/pull/5311)
269269
- [#6434: Fix rebranded header background being visible when printed](https://github.com/alphagov/govuk-frontend/pull/6434) - thanks to @lewis-softwire for reporting this issue
270+
- [#6447: Fix pagination outputting empty links when provided a null or empty value](https://github.com/alphagov/govuk-frontend/pull/6447) – thanks to @NikhilNanjappa for reporting this issue
270271

271272
## v6.0.0-beta.0 (Beta breaking release)
272273

packages/govuk-frontend/src/govuk/components/pagination/pagination.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ examples:
206206
options:
207207
next:
208208
href: '/next'
209+
209210
# Hidden examples are not shown in the review app, but are used for tests and HTML fixtures
210211
- name: with custom classes
211212
hidden: true
@@ -275,3 +276,13 @@ examples:
275276
- number: 3
276277
href: '/page/3'
277278
visuallyHiddenText: '3rd page'
279+
- name: with empty items
280+
hidden: true
281+
options:
282+
items:
283+
- number: 1
284+
href: '/page/1'
285+
- null
286+
- {}
287+
- number: 4
288+
href: '/page/4'

packages/govuk-frontend/src/govuk/components/pagination/template.njk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
{%- if params.items %}
6969
<ul class="govuk-pagination__list">
7070
{% for item in params.items %}
71-
{{ _pageItem(item) | indent(2) }}
71+
{% if item is not null and (item | length) > 0 %}
72+
{{ _pageItem(item) | indent(2) }}
73+
{% endif %}
7274
{% endfor %}
7375
</ul>
7476
{% endif %}

packages/govuk-frontend/src/govuk/components/pagination/template.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ describe('Pagination', () => {
6262
// Test for the unicode character of &ctdot;
6363
expect($firstEllipsis.text().trim()).toBe('\u22ef')
6464
})
65+
66+
it('does not output empty list items', () => {
67+
const $ = render('pagination', examples['with empty items'])
68+
const $listItems = $('.govuk-pagination__item')
69+
70+
expect($listItems).toHaveLength(2)
71+
})
6572
})
6673

6774
describe('with custom text, labels and landmarks', () => {

0 commit comments

Comments
 (0)