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.16k stars 320 forks source link

Explore adding `id` as an attribute for all our component macros #3598

Open owenatgov opened 1 year ago

owenatgov commented 1 year ago

Investigate the feasibility of adding a default id attribute for applying an optional HTML id to all component nunjucks macros. This would be similar to class and attributes, the 2 current default attributes.

Context

This has come up in conversation on support and in the following related issues:

The case for doing this in brief is that id is a standard part of the HTML spec, similar to class, so exposing it would be useful for teams who might need to use the id attribute for any reason.

Additionally, several components already feature an id attribute so making this consistent has value.

Alternatives

Currently teams can do this via attributes:

attributes: {
    "id": "my-custom-id"
}
RintoC commented 1 year ago

We been looking into being able to add an id to a fieldset where the question heading is the same as the page heading. This is possible on raw html, but for nunjucks, the above attribute suggestion does not work currently.

It was requested by the testers in our team so they can target the h1's for regression testing.

I have tried the attributes feature on text input components where you only have a label and input, and it works great. But the attributes features does not work on legends.