Skip to content

Conversation

frankieroberto
Copy link
Contributor

@frankieroberto frankieroberto commented Sep 20, 2024

This updates Pagination component to support a new variant which is suitable for paging between numbered lists of pages, for example in search results or a long list of patients or appointments.

The variant is based on the GOV.UK Pagination variant, but with a few changes to match NHS styling, and some differences in the macro params.

The component is backwards-compatible, so the existing previous and next pagination variant is unchanged.

TODO

  • Mobile view
  • Write guidance
  • Test in all supported browsers
  • Unit tests
  • Add to backstop image tests
  • Code review
  • CHANGELOG entry

@frankieroberto frankieroberto changed the title Add pagination options Add numbered pages pagination option Sep 20, 2024
@paulrobertlloyd
Copy link
Contributor

paulrobertlloyd commented Sep 21, 2024

The existing Previous and Next variant for the NHS pagination component uses different HTML from the GOV.UK one, for example the NHS one uses a <ul> list containing 1 or 2 list items, whereas the GOV.UK one uses <div>s.

Is there an opportunity for us to follow the GOV.UK decision here? My spidey sense is that using a list item for the now and next page items, inside a navigation landmark labelled pagination, is misleading (there may be more than 2 pages, its just that only the previous and next ones have been linked to).

Further more, if you have numbered pagination with say 3 items, it’ll be announced in a list having 5 items. Which is to say, I think the distinction between those links that appear in a list, and those used for previous and next links, is an important one.

To avoid making any breaking changes to the existing pagination component, I’ve left that as-is, including all the existing HTML and CSS classes.

How compatible with the GOV.UK markup would this component be, say if you were using – entirely hypothetically you understand – a GOV.UK-based component library that allowed you to use NHS styles by changing class prefixes from govuk-* to nhsuk-* (cough)?


Separately, see #1027; from both wanting visual consistency, and being able to identify the pagination arrows at these smaller sizes, the existing pagination arrows should have open tips.

@frankieroberto
Copy link
Contributor Author

@paulrobertlloyd:

Is there an opportunity for us to follow the GOV.UK decision here? My spidey sense is that using a list item for the now and next page items, inside a navigation landmark labelled pagination, is misleading (there may be more than 2 pages, its just that only the previous and next ones have been linked to).

Further more, if you have numbered pagination with say 3 items, it’ll be announced in a list having 5 items. Which is to say, I think the distinction between those links that appear in a list, and those used for previous and next links, is an important one.

Ah sorry, I didn’t explain this well enough. I’ve followed the GOVUK markup for the new 'numbered pages' variant. This means that the numbers are within a <ul> list, but the previous and next links are in a separate <div> before or after the list, and not part of the list.

What I’ve not done is changed the markup used for the existing 'previous and next links with page titles' variant, which uses this markup in the NHS version:

<nav><ul>
  <li><a href="#">Previous: page title</a></li>
  <li><a href="#">Next: page title</a></li>
</ul></nav>

but this in the GOV.UK version:

<nav>
  <a href="#">Previous: page title</a>
  <a href="#">Next: page title</a>
</nav>

(<div>s and <span>s not shown)

Possibly we should also update this to match the GOV.UK version, but possibly the <ul> list is beneficial here (or not?) - and I also wanted to avoid a breaking change, at least initially. But maybe it’s better to do that at the same time?

How compatible with the GOV.UK markup would this component be, say if you were using – entirely hypothetically you understand – a GOV.UK-based component library that allowed you to use NHS styles by changing class prefixes from govuk-* to nhsuk-* (cough)?

Right now the markup for the new numbered pages variant should be mostly compatible except for the SVG for the arrows, which is different. There might also be some other differences in the css names.

@paulrobertlloyd
Copy link
Contributor

But maybe it’s better to do that at the same time?

Do it Ben Stiller saying ‘Do it’ from the movie ‘Starsky & Hutch’,

frankieroberto added a commit to NHSDigital/record-a-vaccination-prototype that referenced this pull request Oct 24, 2024
This adds a pagination component to the bottom of the Manage users page,
rather than just displaying all users on a single page.

The number of users per page is set at 20, although this could be
tweaked.

The pagination component is not yet part of the NHS design system, so
I’ve borrowed the GOV.UK one and applied NHS styling. This is still
work-in-progress, and I’m working on contributing this to the NHS design
system here: nhsuk/nhsuk-frontend#1026

## Screenshots

### Manage users

| First page | Middle page | Last page |
| ------ | ------ | ------ |
|
![manage-users-page-1](https://github.com/user-attachments/assets/79f2e200-f771-4327-bc60-e4e30f706d09)
|
![manage-users-page-3](https://github.com/user-attachments/assets/635e8a69-72ab-4f93-8fba-623d484cb225)
|
![manage-users-page-5](https://github.com/user-attachments/assets/3ba01ff2-3d6d-48be-be78-5e79ec588794)
|

### Vaccine batches (on vaccine product page for a given site)


![pagination-of-vaccine-batches](https://github.com/user-attachments/assets/99772ecc-8a09-4300-935f-0c463f6ae7a2)


If there are a lot of pages, then ellipsis would be used to show gaps in
the sequence, so that the first page, last page, previous and next page
are always included:

<img width="608" alt="Screenshot 2024-09-23 at 16 09 43"
src="https://github.com/user-attachments/assets/500b8dfd-2ecc-4f69-b8a4-3078642a1fbe">
@frankieroberto frankieroberto changed the title Add numbered pages pagination option Update pagination component to allow numbered pages, use new arrows, and other changes Apr 26, 2025
Copy link

@Arpana18
Copy link

Arpana18 commented Jun 2, 2025

How can we hide (not show) the 'Previous' link when users are on the first page AND "Next" link when users are on the last page?

Our user research revealed that participants were confused about what the 'Previous' link would do when they're already on page 1. Similarly, users expect the 'Next' link to be disabled when they reach the last page.

This feedback suggests we need to implement hide states for pagination controls to provide clearer visual cues about available navigation options.

@frankieroberto
Copy link
Contributor Author

How can we hide (not show) the 'Previous' link when users are on the first page AND "Next" link when users are on the last page?

@Arpana18 Hiya - the previous and next links are only shown when specified in the HTML or in the previous and next params within the Nunjucks macro. We’ll make it clearer in the accompanying guidance how to do this! Thanks for commenting. 👍

@frankieroberto
Copy link
Contributor Author

@colinrotherham @paulrobertlloyd I've updated this from main and fixed the conflicts and deprecations (I think).

Next step is to sort out the mobile view. Follow GOVUK and go centre aligned, with 'Previous' stacked above the numbers and 'Next' stacked below?

@colinrotherham
Copy link
Contributor

Next step is to sort out the mobile view. Follow GOVUK and go centre aligned, with 'Previous' stacked above the numbers and 'Next' stacked below?

I'd say so, but only in the absence of a better (researched) option.

For comparison we could look at ideas in:

@colinrotherham colinrotherham force-pushed the add-pagination-options branch from d0dd372 to 82c26a9 Compare June 9, 2025 19:55
@colinrotherham
Copy link
Contributor

colinrotherham commented Jun 9, 2025

Sorry about the force push @frankieroberto

I've removed all the link style overrides so the defaults are now used, including :visited etc

Pagination with default link styles

Would be good to chat about the --block modifier used by GOV.UK Frontend

A few of the default styles were causing conflicts without it (e.g. stretching link :hover over the whole item)

@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1026 June 12, 2025 08:46 Inactive
@colinrotherham colinrotherham force-pushed the add-pagination-options branch from ceef42c to 669439a Compare June 23, 2025 13:33
@colinrotherham
Copy link
Contributor

colinrotherham commented Jun 23, 2025

Sorry about the force push again, 639 commits added and macro options are now ES modules

@colinrotherham
Copy link
Contributor

Merged with latest main now review app examples are consolidated

@frankieroberto
Copy link
Contributor Author

@colinrotherham I'm planning to pick this up again later this week, as it a component desperately needed by my service.

But this would be a v11 thing.

@colinrotherham colinrotherham force-pushed the add-pagination-options branch from 527cf90 to fa7bfa2 Compare July 2, 2025 16:22
@colinrotherham
Copy link
Contributor

Updated with main where reference images were generated again

Copy link

sonarqubecloud bot commented Jul 2, 2025

@colinrotherham colinrotherham mentioned this pull request Aug 14, 2025
3 tasks
@colinrotherham colinrotherham changed the base branch from main to add-link-underline-offset September 1, 2025 06:25
@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1026 September 1, 2025 06:26 Inactive
@colinrotherham
Copy link
Contributor

Fixed all the conflicts to bring in:

  1. Next and Previous icons via nhsukIcon()
  2. Link colours from Change link hover and active colours #1367
  3. Link underlines from Add link underline offset and make underline thicker on hover #1366

@frankieroberto frankieroberto changed the base branch from add-link-underline-offset to main September 5, 2025 20:08
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1026 September 5, 2025 20:11 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1026 September 5, 2025 20:18 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1026 September 5, 2025 20:20 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1026 September 5, 2025 21:35 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1026 September 5, 2025 21:39 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1026 September 5, 2025 21:49 Inactive
@frankieroberto frankieroberto changed the title Update pagination component to allow numbered pages, use new arrows, and other changes Update pagination component to add new numbered pages variant Sep 5, 2025
Copy link

sonarqubecloud bot commented Sep 5, 2025

@frankieroberto
Copy link
Contributor Author

Okay I’ve updated this, with the main aim of making this now backwards-compatible, so that it is no longer a breaking change.

The downside of this is that it remains un-aligned with the govuk frontend one at both the macro level and the HTML output is also slightly different (especially for the existing variant), but I’ve made it as compatible as I can. The use of the nested nhsukIcon macro means it’ll never be 100% the same anyway.

We could still decide to deprecate previousUrl for previous.href and previousText for previous.labelText etc, if we wanted to.

Still got a bit of fiddling to do on the design and the mobile-responsiveness, but getting closer...

@colinrotherham
Copy link
Contributor

Have a look from line 6?

https://github.com/nhsuk/nhsuk-frontend/blob/component-form-inputs/packages/nhsuk-frontend/src/nhsuk/components/input/template.njk

I had to do some wrangling to make the GOV.UK Frontend object syntax for prefix/suffix work with our strings

But it worked. Old and new API,
side by side

If that opens any doorways for you?

@frankieroberto
Copy link
Contributor Author

@colinrotherham yeah, I was considering doing similar to support both previousUrl (which could be deprecated) and previous.href. Depends how important we think it is to update the Nunjucks params.

For now, I’ll focus on the remaining design tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants