nhsuk / nhsuk-frontend

NHS.UK frontend contains the code you need to start building user interfaces for NHS websites and services.
https://nhsuk.github.io/nhsuk-frontend/
MIT License
606 stars 106 forks source link

Support classes and attributes in header primary links #978

Closed frankieroberto closed 1 day ago

frankieroberto commented 1 week ago

Description

This adds support for adding optional custom CSS classes or other HTML attributes to the list item tags of the primary links within the Header component.

This gives the header navigation a bit more flexibility to be customised by services, who may wish to do things like highlighting the current section, having some items left-aligned and some right aligned, colour-coding the sections, adding data attributes for testing purposes, or other things we’ve not yet thought of.

The options are enabled by supporting classes and attributes as params within the primaryLinks objects in the Nunjucks macro, like this:

{{ header({
  "showNav": "true",
  "showSearch": "false",
  "primaryLinks": [
    {
      "url"  : "https://www.nhs.uk/conditions",
      "label" : "Health A-Z",
      "classes": "app-header__navigation-item--current",
      "attributes": {
        "aria-current": "true"
      }
    },
    {
      "url" : "https://www.nhs.uk/live-well/",
      "label" : "Live Well"
    }
  ]
}) }}

Checklist

edwardhorsford commented 1 week ago

This would be super helpful, using all kinds of hacks at the moment to try and style individual navigation items.

Might also be a good idea to bring in the attributes macro used by GOV.UK Frontend (and added in #969) via a separate PR so that boolean attributes are supported properly.

@paulrobertlloyd yeah it's part of #969 - though I now think it's probably better to bring it in as a separate pr sooner so that it can apply to other components and not be blocked by task list.

frankieroberto commented 1 week ago

@edwardhorsford nice - if you can pull that into a separate PR and get that merged, I can use the macro in the one.