alphagov / govuk-frontend

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.
https://frontend.design-system.service.gov.uk/
MIT License
1.14k stars 320 forks source link

Support array of strings in radios and checkboxes #4032

Open joelanman opened 1 year ago

joelanman commented 1 year ago

Related component

Radios and checkboxes

Context

You don't always want different name from text, for example when prototyping. An array of strings is a lot simpler than an array of objects. For example:

items: ["England", "Northern Ireland", "Scotland", "Wales"]

compared to the current approach:

items: [
  {"name": "England", "text": "England"},
  {"name": "Northern Ireland", "text": "Northern Ireland"},
  {"name": "Scotland", "text": "Scotland"},
  {"name": "Wales", "text": "Wales"}
]

(In this suggestion only text is supported - if you want other options like html or hint you'd have to use the object approach)

querkmachine commented 1 year ago

I think we may have already resolved this recently! #3773

joelanman commented 1 year ago

Hi that link is for the select element? Was the same thing done for radios and checkboxes?

querkmachine commented 1 year ago

Ah whoops, no it wasn't, sorry!

Making the same change for checkboxes and radios may be a bit more involved as they each have several more parameters that can slot into the object within items, but it's not impossible.

I worry a little about maintainability from the user's perspective—if they've used the string array syntax and now decided they want to add hint text to an option, for example, they would need to completely reformat how they're providing data to allow that, which they wouldn't need to do if they were using the object syntax.

Maybe even if we allow an array of strings, it'd be better to have it as a bit of a 'hidden' feature rather than something we encourage the use of.