govuk-frontend icon indicating copy to clipboard operation
govuk-frontend copied to clipboard

Ability to group radio buttons / checkboxes within sub-headings

Open frankieroberto opened this issue 6 years ago • 29 comments

Hi.

I'm wondering how best to support radio buttons (and checkboxes) which have sub-groups with headings?

Currently, you can use multiple govukRadios macros which share the same name attribute, however because they use a data-module attribute to scope the conditional reveals, these don't work properly across the groups.

Alternatively, you can using a single macro and put headings in using dividers, but these don't currently support HTML markup.

On a related not, it's unclear whether the best output would be nested <fieldset>s with <legend>s, or a single <fieldset> with headings and either aria attributes or visually-hidden prefixes to associate labels with their headings.

frankieroberto avatar Nov 23 '18 15:11 frankieroberto

I spoke to Frankie and we put together a coded example: https://tricky-fisher.glitch.me/

NickColley avatar Nov 23 '18 15:11 NickColley

I was looking to do similar today. I've got a set of 10 or so radios and I'd like to group in to 3 related groups. It's all one question - so tried to do it in one radio group with the divider option - but found it is hardcoded to be too narrow.

Also wanted to do similar for checkboxes, but found they don't support divider yet.

edwardhorsford avatar Jan 23 '19 16:01 edwardhorsford

Hey there @edwardhorsford, @frankieroberto and @stevenaproctor. Would you be able to share a few use cases of this pattern here, so we can better understand how it's used in a service and what variations a macro would need to support?

Thanks!

timpaul avatar Jan 30 '19 14:01 timpaul

Here's an example from our service - radios roughly grouped in to individuals and teams: screenshot 2019-01-30 at 15 05 21

An older design we're not going with, but with a similar need: screenshot 2019-01-30 at 15 06 30

For the first example, I don't think it's essential for 'teams' to be programmatically linked to the options. For the second it does, or the options would need hidden text to make the team they apply to clear.

edwardhorsford avatar Jan 30 '19 15:01 edwardhorsford

@timpaul here's the example from the pattern I was looking at:

screenshot 2019-01-30 at 15 12 51

I used two govukRadios macros with the same name, which is fine for the radios (and would probably work for @edwardhorsford's examples) but the conditional reveals don’t work properly because they're scoped to the data-module. I think that this could be fixed by scoping the conditional reveals to the whole page (as the name attributes have page-scope anyhow).

frankieroberto avatar Jan 30 '19 15:01 frankieroberto

@timpaul I do not have any examples from HMRC. I will ask in our working group.

stevenaproctor avatar Jan 30 '19 17:01 stevenaproctor

Here's a possible fix: #1163.

frankieroberto avatar Jan 30 '19 17:01 frankieroberto

I've been working on this too so thought I'd share my examples:

1. Multiple fieldsets of checkboxes with legends https://seemly-airmail.glitch.me

2. Multiple fieldsets of checkboxes with legends With aria-describedby on nested fieldsets https://childlike-cinema.glitch.me/

3. Single fieldset of checkboxes with subheadings https://steep-knife.glitch.me

We're doing some more screen reader testing on Monday.

So far we've not tried @frankieroberto's suggestion above of prefixing (but visually hidden) the nested legends with the parent legend's text.

colinrotherham avatar Feb 01 '19 12:02 colinrotherham

@colinrotherham how did you get on with screen reader testing?

NickColley avatar Feb 13 '19 14:02 NickColley

We initially tested version 1 versus 3 and found 3 worked best, but this was thanks to the aria-describedby attribute making VoiceOver read out the headings as you move from input to input.

Why? In version 1 VoiceOver (Safari on Mac) won't automatically read out the parent legend/hint, and it only does this once per child fieldset anyway. This was our workaround.

So, with this in mind, we created version 2 which also tested well.

We're not sure if it's now too chatty, but it does now provide all the context needed when hints and validation messages apply.

Some useful replies from @LJWatson and Chris Bush https://twitter.com/colinrotherham/status/1091302018898112513

See the caveats around only using simple cases like this for nested fieldsets.

colinrotherham avatar Feb 13 '19 15:02 colinrotherham

We could reproduce version 2 via govuk-frontend but we'd need to solve:

  1. https://github.com/alphagov/govuk-frontend/pull/1163 For nested radio components, maybe checkboxes too
  2. https://github.com/alphagov/govuk-frontend/issues/1166 To extend the wrapping fieldset

colinrotherham avatar Feb 13 '19 15:02 colinrotherham

Thanks everyone for the ideas and examples.

Does anyone have any evidence either way regarding the usability of grouped radios?

One concern we have is that some users might assume that the groups work independently of each other. They would go down the list selecting an option from each group in the mistaken belief that that's what would be submitted, when in fact only their last choice would be.

timpaul avatar Apr 04 '19 10:04 timpaul

Hi @timpaul, we have a single question with a long list of checkboxes.

We use the subheadings to break them up into logical groups, making them easier to read.

Can't offer any evidence for radio buttons though sorry.

colinrotherham avatar Apr 04 '19 11:04 colinrotherham

I've not observed any issues, but we've not had many users go through this. I can see the concern - but I think the context in which the labels are used (inc not having them phrased as questions) should make it clear what they're doing.

edwardhorsford avatar Apr 04 '19 14:04 edwardhorsford

We've spoken to the ONS, who used a version of the grouped radio buttons with subheadings in an early test, and they did experience some users who assumed that each heading was independent, and that they had to select one option from each sub-group. They weren't using the Design System typography though but their own styles.

frankieroberto avatar Apr 05 '19 08:04 frankieroberto

Re-opening this after a discussion with @edwardhorsford, you can now use conditional reveals with grouped radios but this doesnt answer this specific question of which is the best way to markup multiple groups.

NickColley avatar Jul 23 '19 09:07 NickColley

I'm back looking at this page again.

Here's where it's gotten to: Screenshot 2020-05-14 at 16 05 19

Note: in our case I don't think it's essential you get get read these groupings. They're extra context for the options, but the options themselves are what users are choosing between. If there's a neat way of including them with the options I'd happy use it though.

edwardhorsford avatar May 14 '20 15:05 edwardhorsford

Thanks @edwardhorsford, looks good – have you tested this approach with any assistive technologies? I guess you could argue the grouping labels are an enhancement but would be interested to see what the experience is like for screen readers etc.

christopherthomasdesign avatar May 19 '20 08:05 christopherthomasdesign

@christopherthomasdesign no, this is just in my prototype right now.

In our case, we might consider them an enhancement - it'll essentially read the radios in a less-obvious order (but still in priority order). We could preface each option with the text too - might try that and see what it sounds like.

edwardhorsford avatar May 19 '20 09:05 edwardhorsford

Is there anything left to do to close this issue?

If the missing piece of the puzzle is to document this in the Design System, I think we should close this and open a new issue in the Design System repo instead?

36degrees avatar Jul 29 '22 12:07 36degrees

@36degrees I don't think there's any way to group radios or checkboxes in the design system is there? Not that I'm aware of using the macros at least.

I think the need is to investigate the technical options and extend the macro to support them (if appropriate).

edwardhorsford avatar Jul 29 '22 12:07 edwardhorsford

You can create sets of radios that are not enclosed in a fieldset by not setting the fieldset option and then manually wrap the multiple sets in a fieldset using the govukFieldset macro. So it's possible to achieve using the macros, but we don't provide a pre-defined method for doing it.

36degrees avatar Jul 29 '22 12:07 36degrees

@36degrees would you then manually add an appropriate label for each? Presumably legends aren't appropriate.

I think it would be nice if the macros supported this - but if that's not wanted and there's a manual solution - yeah this could be moved to the Design system repo to add an example / guidance for how to do this.

edwardhorsford avatar Jul 29 '22 14:07 edwardhorsford