Skip to content

Add checkbox “select all” behaviour#1707

Open
frankieroberto wants to merge 7 commits intomainfrom
checkbox-inclusive
Open

Add checkbox “select all” behaviour#1707
frankieroberto wants to merge 7 commits intomainfrom
checkbox-inclusive

Conversation

@frankieroberto
Copy link
Contributor

@frankieroberto frankieroberto commented Nov 26, 2025

This updates the Checkbox component with a new option for “select all” checkboxes, using inclusive: true alongside the existing “none of the above” option which deselects all the others when checked.

@frankieroberto
Copy link
Contributor Author

I've found myself using this in a prototype this week, for a checkbox listing pharmacies (where there can be a lot of them):

Screenshot 2025-12-09 at 12 39 51

We’re aiming to user test this in the coming weeks.

@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1707 December 9, 2025 13:44 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1707 January 8, 2026 11:01 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1707 January 13, 2026 14:40 Inactive
Fixes bug:

Bug: When an inclusive checkbox ("Select all") was unchecked with checkboxes that have unique names and use inclusiveGroup, the other checkboxes were not being unchecked because handleClick called unCheckAllInputsExcept() which uses checkboxExclusiveGroup instead of checkboxInclusiveGroup.
This updates the behaviour for inclusive ("select all") checkboxes, so that if you individually check all checkboxes except for "select all", then the "select all" checkbox gets automatically check when you check the last checkbox.

This avoids being in a state where "select all" is the only checkbox unchecked, and when you check it then nothing happens.
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1707 January 13, 2026 22:33 Inactive
@frankieroberto frankieroberto changed the title Spike: Add checkbox “select all” behaviour Add checkbox “select all” behaviour Jan 13, 2026
@frankieroberto frankieroberto marked this pull request as ready for review January 13, 2026 23:02
@frankieroberto
Copy link
Contributor Author

@colinrotherham I’ve updated this (with some help from AI) so I think it’s a reviewable state now.

I made one behavioural change which is that the “select all” checkbox becomes automatically checked if you individually check all the other checkboxes.

@frankieroberto
Copy link
Contributor Author

frankieroberto commented Jan 13, 2026

One difference with the GOVUK implementation of this (which I originally wrote) is that that uses behaviour: "exclusive" whereas the NHS one uses exclusive: true.

The advantage of the GOVUK one is that you can’t specify both inclusive and exclusive on same input! (Not that they support inclusive behaviour yet)

We could either choose to align with the GOVUK version and switch to a behaviour param (which could be backwards-compatible), or keep with exclusive: true and inclusive: true but make a decision about which one takes priority if both are specified?

@sonarqubecloud
Copy link

@frankieroberto
Copy link
Contributor Author

@anandamaryon1 @colinrotherham @sarawilcox any chance we could review this for the next release? I think we have enough evidence that it would be useful?! (It's been designed into at least 2 vaccination services).

@anandamaryon1
Copy link
Contributor

Sorry for not replying on this one. It makes total sense. Did you get to run your user testing with it?

I think we'd want to add guidance and an example in the design system too. Any insight as to why gov haven't added it?

@colinrotherham
Copy link
Contributor

colinrotherham commented Feb 11, 2026

@frankieroberto
Copy link
Contributor Author

frankieroberto commented Feb 11, 2026

I've asked in the cross-gov Slack about it too.

@frankieroberto
Copy link
Contributor Author

We tested the interface in #1707 (comment) in our last round of user research, with staff who use Record a vaccination across multiple pharmacies. We didn’t find any issues with the interaction.

In our current prototype I’m always including the select-all option so long as there’s 2+ options (if there’s only a single option they skip the screen entirely).

It might be that it only makes sense to include the select-all option if there are 5+ or some other number of options though.

@colinrotherham
Copy link
Contributor

colinrotherham commented Feb 11, 2026

I'd like us to support item.behaviour to set data-behaviour="{{ item.behaviour }}" like GOV.UK Frontend

We'd want backwards compatibility with our NHS specific item.exclusive option in v10.x too

But what about multiple inclusive groups—would we support these too?

Multiple named groups

Unlike GOV.UK Frontend we also support multiple named groups via item.exclusiveGroup

E.g. Try the 3 named exclusive groups:
https://nhsuk.github.io/nhsuk-frontend/examples/conditional-reveals/

  • None of the primary colours
  • None of the secondary colours
  • None of the above

Should we rename to item.exclusiveGroup item.behaviourGroup to pair with item.behaviour?

@frankieroberto
Copy link
Contributor Author

@colinrotherham maybe initially we add this in a backwards-compatible way, by adding inclusive: true and inclusiveGroup (see the PR as it is now)?

Then could consider switching to behaviour: "inclusive" and behaviour: "exclusive" in the next breaking change release, along with either behaviourGroup or removing the group functionality (depending on whether we still think there’s a good use case for it)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants