Skip to content

Add button group and full width button styles#1309

Merged
anandamaryon1 merged 13 commits into
mainfrom
form-button-group
Jun 30, 2025
Merged

Add button group and full width button styles#1309
anandamaryon1 merged 13 commits into
mainfrom
form-button-group

Conversation

@colinrotherham
Copy link
Copy Markdown
Contributor

@colinrotherham colinrotherham commented May 20, 2025

Description

This PR aligns with GOV.UK Frontend by including:

  1. Switch to full width buttons on mobile
  2. Add new "button group" styling

The styles for .nhsuk-button-group were initially copied from GOV.UK Frontend:

But have now been updated to match NHS App Frontend spacing:


Button group

From NHS App Frontend Button component research:


Full width buttons

Testing on the NHS App has found that full width buttons are not a problem for users with smaller screens. But we will continue to test if:

  • full width buttons are problematic for users with low digital skills
  • users don’t actually see them as actionable things to click

Checklist

Comment on lines +27 to +30
// Ideally we'd use `gap` with flexbox rather than having to do it all with
// margins, but unfortunately the support isn't there (yet) and @supports
// doesn't play nicely with it
// (https://github.com/w3c/csswg-drafts/issues/3559)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usual caveat, I copied from GOV.UK Frontend!

Mainly leaving this PR here for all the designers to chip in with their tweaks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use gap in the header, but not as much as we once did; the navigation used it, but it meant items were bunched up on older versions of Safari locked-to-the-last-support-version-of-iOS. Probably something we’d want to test across a number of different devices.

@frankieroberto
Copy link
Copy Markdown
Contributor

One factor to consider is the mobile view. In govuk-frontend, buttons go full-width on mobile, and so it makes sense to also vertically stack buttons group at mobile widths.

However NHS frontend does not make buttons full-width on mobile views, so we could continue to allow buttons to be side-by-side in a button group on mobile, however they might not always fit.

Here's how it currently looks at 640 width vs 641:

640 width 641 width
Screenshot 2025-05-20 at 16 12 31 Screenshot 2025-05-20 at 16 12 46

Tricky!

@frankieroberto
Copy link
Copy Markdown
Contributor

The NHS App team have already added button groups: https://design-system.nhsapp.service.nhs.uk/components/buttons/#grouping-buttons - they also have a nhsapp-button modifier which makes buttons full-width on mobile.

We could consider something similar and have the behaviour opt-in, perhaps via nhsuk-button--full-width-on-mobile or similar?

@paulrobertlloyd
Copy link
Copy Markdown
Contributor

Please, please, please can we replicate the GOV.UK behaviour and have buttons go full width on mobile by default? (I've been using my button group wrapper as a bit of a hack to enable this)

@frankieroberto
Copy link
Copy Markdown
Contributor

Please, please, please can we replicate the GOV.UK behaviour and have buttons go full width on mobile by default? (I've been using my button group wrapper as a bit of a hack to enable this)

@paulrobertlloyd Which breakpoint would you pick? 640 has always felt a bit too wide to me, but maybe its fine? 🤷

Screenshot 2025-05-20 at 18 11 34

How about making it opt-in or opt-out? 🤔

@paulrobertlloyd
Copy link
Copy Markdown
Contributor

Be bold @frankieroberto! < 640px is perfectly fine! (What do they do on the app?)

@frankieroberto
Copy link
Copy Markdown
Contributor

Be bold @frankieroberto! < 640px is perfectly fine! (What do they do on the app?)

The app has a modifier to make them full-width on mobile: https://github.com/nhsuk/nhsapp-frontend/blob/main/src/components/button/_index.scss#L14-L23 - I think @davidhunter08 and co did some research on it.

@davidhunter08
Copy link
Copy Markdown
Contributor

In July 2024, the NHS App made all buttons full width by default at < 640px. No usability problems found so far.

Other NHS services use full width buttons, including 111 online and NHS login.

NHS login example

Screenshot 2025-05-21 at 09 18 38

111 online example

Screenshot 2025-05-21 at 09 19 13

@colinrotherham
Copy link
Copy Markdown
Contributor Author

This is great to hear, I purposely removed "full width by default" to match what we do now

Shall I push an update to put it back?

  1. Full width by default
  2. Full width only within button groups

Where 1) would align with the app, 111 online and NHS login's approach

@frankieroberto
Copy link
Copy Markdown
Contributor

Happy to go with option 1 - full width buttons on mobile. Maybe it doesn't even need an opt-out?

Would we consider it a breaking change though? 🤔

@colinrotherham
Copy link
Copy Markdown
Contributor Author

How's this? Just pushed

Button group at full width on mobile

@paulrobertlloyd
Copy link
Copy Markdown
Contributor

Yaaaaay!!

@colinrotherham colinrotherham force-pushed the form-button-group branch 2 times, most recently from e26199e to baa60de Compare June 4, 2025 09:45
@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1309 June 12, 2025 08:45 Inactive
@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1309 June 12, 2025 15:45 Inactive
@colinrotherham
Copy link
Copy Markdown
Contributor Author

colinrotherham commented Jun 12, 2025

Updated to match the spacing in NHS App Frontend

//cc @davidhunter08

@colinrotherham colinrotherham marked this pull request as ready for review June 12, 2025 15:53
@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1309 June 12, 2025 15:53 Inactive
@colinrotherham colinrotherham changed the title Add button group styles Add button group and full width button styles Jun 12, 2025
Copy link
Copy Markdown
Contributor

@frankieroberto frankieroberto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looks good to me.

Here's how I'm planning to use it (this is just a quick mockup):

Screenshot 2025-06-12 at 17 14 29

@frankieroberto
Copy link
Copy Markdown
Contributor

One thing this pull request doesn't currently do is let you add non-linked text next to the button:

Should we support that too? 🤔

Screenshot 2025-06-13 at 12 44 35

@colinrotherham
Copy link
Copy Markdown
Contributor Author

Thanks @frankieroberto

Ahh in GOV.UK Frontend .govuk-button-group .govuk-link gets a bottom margin like govuk-body

E.g. You'd want to wrap your "or" text into <span class="nhsuk-body-m">or</span>

But looks like we need to iterate the NHS App spacing a little more for that

@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1309 June 30, 2025 09:23 Inactive
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1309 June 30, 2025 09:27 Inactive
Comment thread CHANGELOG.md Outdated
Co-authored-by: Colin Rotherham <work@colinr.com>
@frankieroberto frankieroberto temporarily deployed to nhsuk-frontend-pr-1309 June 30, 2025 10:58 Inactive
@sonarqubecloud
Copy link
Copy Markdown

@colinrotherham
Copy link
Copy Markdown
Contributor Author

Brilliant, shall we merge this and do testing as part of the pre-release?

Noting that the styles were largely taken from the NHS App

@anandamaryon1 anandamaryon1 merged commit 16740bc into main Jun 30, 2025
13 checks passed
@anandamaryon1 anandamaryon1 deleted the form-button-group branch June 30, 2025 13:13
colinrotherham pushed a commit that referenced this pull request Jun 30, 2025
Add button group and full width button styles
@colinrotherham colinrotherham self-assigned this Aug 15, 2025
@colinrotherham colinrotherham moved this to Ready to release in Service Manual Sprint Board Aug 15, 2025
@colinrotherham colinrotherham added this to the v10.0.0 milestone Aug 15, 2025
@sarawilcox sarawilcox moved this from Ready to release to Done in Service Manual Sprint Board Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done - 2025

Development

Successfully merging this pull request may close these issues.

6 participants