Skip to content

Commit

Permalink
Allow passing attributes for tags
Browse files Browse the repository at this point in the history
Because we’re just passing the options defined by the user straight through to the tag component we can simplify the code and just pass the entire `item.status.tag` object rather than each option individually.

Co-authored-by: Colin Rotherham <work@colinr.com>
  • Loading branch information
36degrees and colinrotherham committed Jul 13, 2023
1 parent 55d488e commit a1e29b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/govuk/components/task-list/task-list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ examples:
status:
tag:
text: Status
attributes:
data-tag-attribute: tag-value

- name: custom id prefix
hidden: true
Expand Down
6 changes: 1 addition & 5 deletions src/govuk/components/task-list/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
</div>
<div class="govuk-task-list__status {%- if item.status.classes %} {{ item.status.classes }}{% endif %}" id="{{ statusId }}">
{% if item.status.tag %}
{{ govukTag({
text: item.status.tag.text,
html: item.status.tag.html,
classes: item.status.tag.classes
}) | indent(4) | trim }}
{{ govukTag(item.status.tag) | indent(4) | trim }}
{% else %}
{{ item.status.html | safe if item.status.html else item.status.text }}
{% endif %}
Expand Down
7 changes: 7 additions & 0 deletions src/govuk/components/task-list/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ describe('Task List', () => {
const $tag = $('.govuk-task-list__status .govuk-tag')
expect($tag.hasClass('custom-class-on-tag')).toBeTruthy()
})

it('allows for custom attributes on tags', () => {
const $ = render('task-list', examples['custom attributes'])

const $component = $('.govuk-tag')
expect($component.attr('data-tag-attribute')).toEqual('tag-value')
})
})

describe('when a task has a non-tag status', () => {
Expand Down

0 comments on commit a1e29b8

Please sign in to comment.