nhsuk / nhsuk-service-manual-community-backlog

This is a place for digital teams in the NHS to work together and develop the NHS digital service manual.
https://service-manual.nhs.uk/community-and-contribution
62 stars 5 forks source link

Cannot assign attributes to the last element in a breadcrumb. #471

Open jamessan85 opened 1 year ago

jamessan85 commented 1 year ago

What is the problem?

Cannot add attributes to the last element in the breadcrumbs

Bugs

What did you expect to happen?

Expect to be able to add custom attributes to the last element in a bread crumb. But the way the template has been written the attributes for the last element fall out side of the loop so it can not load the attributes into the tag.

Steps to reproduce it:

  1. Add attributes to the breadcrumbs component inside the array
  2. Check the last component, attributes are not added.

You can see below on line 13 to 15 this falls out of the loop, but the attributes are looking for item.attributes which cannot be accessed as it is outside of the loop.

File: node_modules/nhsuk-frontend/packages/components/breadcrumb/template.njk
04:     <ol class="nhsuk-breadcrumb__list">
05:       {%- for item in params.items %}
06:         {%- if item.href %}
07:           <li class="nhsuk-breadcrumb__item">
08:             <a class="nhsuk-breadcrumb__link" href="{{ item.href }}"{% for attribute, value in item.attributes %} {{attribute}}="{{value}}"{% endfor %}>{{ item.text }}</a>
09:             {% if not loop.last %}{% endif %}
10:           </li>
11:         {%- endif -%}
12:       {% endfor %}
13:       <li class="nhsuk-breadcrumb__item">
14:         <a class="nhsuk-breadcrumb__link" href="{{ params.href }}"{% for attribute, value in item.attributes %} {{attribute}}="{{value}}"{% endfor %}>{{ params.text}}</a>
15:       </li>
16:     </ol>
the-nathan-smith commented 1 year ago

@jamessan85 we've got a fix for this in the pipeline that should go out with the next nhsuk-frontend release. I'll update this issue when it's sorted.