diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b8facfb3c..79a22e61ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,12 @@ ([PR #990](https://github.com/alphagov/govuk-frontend/pull/990)) +- Allow attributes to be added to some child items in header, footer, breadcrumbs, tabs and error-summary components + + You can now pass additional attributes to links in header, footer, breadcrumbs, tabs and error-summary components + + ([PR #993](https://github.com/alphagov/govuk-frontend/pull/993)) + - Pull Request Title goes here Description goes here (optional) diff --git a/src/components/breadcrumbs/README.md b/src/components/breadcrumbs/README.md index 8b7a6d2905..64f99d3f66 100644 --- a/src/components/breadcrumbs/README.md +++ b/src/components/breadcrumbs/README.md @@ -288,6 +288,18 @@ If you are using Nunjucks,then macros take the following arguments +items.{}.attributes + +object + +No + +Any extra HTML attributes (for example data attributes) to add to the breadcrumb anchor item. + + + + + classes string diff --git a/src/components/breadcrumbs/README.njk b/src/components/breadcrumbs/README.njk index 58917e2b10..0faaec20b3 100644 --- a/src/components/breadcrumbs/README.njk +++ b/src/components/breadcrumbs/README.njk @@ -71,6 +71,20 @@ The Breadcrumbs component helps users to understand where they are within a webs text: 'Link for the breadcrumbs item. If not specified, breadcrumbs item is a normal list item' } ], + [ + { + text: 'items.{}.attributes' + }, + { + text: 'object' + }, + { + text: 'No' + }, + { + text: 'Any extra HTML attributes (for example data attributes) to add to the breadcrumb anchor item.' + } + ], [ { text: 'classes' diff --git a/src/components/breadcrumbs/template.njk b/src/components/breadcrumbs/template.njk index 1c4e9cebfc..e89b9bf0a5 100644 --- a/src/components/breadcrumbs/template.njk +++ b/src/components/breadcrumbs/template.njk @@ -3,7 +3,7 @@ {% for item in params.items %} {% if item.href %}
  • - {{ item.html | safe if item.html else item.text }} + {{ item.html | safe if item.html else item.text }}
  • {% else %}
  • {{ item.html | safe if item.html else item.text }}
  • diff --git a/src/components/breadcrumbs/template.test.js b/src/components/breadcrumbs/template.test.js index daa33c24e0..dd2b20a2b7 100644 --- a/src/components/breadcrumbs/template.test.js +++ b/src/components/breadcrumbs/template.test.js @@ -79,6 +79,25 @@ describe('Breadcrumbs', () => { expect($item.html()).toEqual('<span>Section 1</span>') }) + it('renders item anchor with attributes', () => { + const $ = render('breadcrumbs', { + items: [ + { + 'text': 'Section 1', + 'href': '/section', + 'attributes': { + 'data-attribute': 'my-attribute', + 'data-attribute-2': 'my-attribute-2' + } + } + ] + }) + + const $breadcrumbLink = $('.govuk-breadcrumbs__link') + expect($breadcrumbLink.attr('data-attribute')).toEqual('my-attribute') + expect($breadcrumbLink.attr('data-attribute-2')).toEqual('my-attribute-2') + }) + it('renders item with html', () => { const $ = render('breadcrumbs', { items: [ diff --git a/src/components/error-summary/README.md b/src/components/error-summary/README.md index adc2d9a4d2..845aa1ac8b 100644 --- a/src/components/error-summary/README.md +++ b/src/components/error-summary/README.md @@ -168,6 +168,18 @@ If you are using Nunjucks,then macros take the following arguments +errorList.{}.attributes + +object + +No + +Any extra HTML attributes (for example data attributes) to add to the error link anchor. + + + + + classes string diff --git a/src/components/error-summary/README.njk b/src/components/error-summary/README.njk index c2dc633205..f3bcba49bd 100644 --- a/src/components/error-summary/README.njk +++ b/src/components/error-summary/README.njk @@ -101,6 +101,20 @@ text: 'Text or HTML for the error link item. If `html` is provided, the `text` argument will be ignored.' } ], + [ + { + text: 'errorList.{}.attributes' + }, + { + text: 'object' + }, + { + text: 'No' + }, + { + text: 'Any extra HTML attributes (for example data attributes) to add to the error link anchor.' + } + ], [ { text: 'classes' diff --git a/src/components/error-summary/template.njk b/src/components/error-summary/template.njk index 79c9fab116..49b34b4595 100644 --- a/src/components/error-summary/template.njk +++ b/src/components/error-summary/template.njk @@ -14,7 +14,7 @@ {% for item in params.errorList %}
  • {% if item.href %} - {{ item.html | safe if item.html else item.text }} + {{ item.html | safe if item.html else item.text }} {% else %} {{ item.html | safe if item.html else item.text }} {% endif %} diff --git a/src/components/error-summary/template.test.js b/src/components/error-summary/template.test.js index 87494a0b3a..76bb66d0d5 100644 --- a/src/components/error-summary/template.test.js +++ b/src/components/error-summary/template.test.js @@ -128,6 +128,25 @@ describe('Error-summary', () => { expect(errorItem.attr('href')).toEqual('#example-error-1') }) + it('renders anchor tag with attributes', () => { + const $ = render('error-summary', { + errorList: [ + { + 'text': 'Error-1', + 'href': '#item', + 'attributes': { + 'data-attribute': 'my-attribute', + 'data-attribute-2': 'my-attribute-2' + } + } + ] + }) + + const $component = $('.govuk-error-summary__list a') + expect($component.attr('data-attribute')).toEqual('my-attribute') + expect($component.attr('data-attribute-2')).toEqual('my-attribute-2') + }) + it('renders error item text', () => { const $ = render('error-summary', examples.default) const errorItemText = $('.govuk-error-summary .govuk-error-summary__list li:first-child').text().trim() diff --git a/src/components/footer/README.md b/src/components/footer/README.md index f29f108a75..924c8d49c5 100644 --- a/src/components/footer/README.md +++ b/src/components/footer/README.md @@ -177,6 +177,18 @@ If you are using Nunjucks,then macros take the following arguments +meta.items.{}.attributes + +object + +No + +Any extra HTML attributes (for example data attributes) to add to the anchor in the footer meta section. + + + + + navigation array @@ -249,6 +261,18 @@ If you are using Nunjucks,then macros take the following arguments +navigation.items.{}.attributes + +object + +No + +Any extra HTML attributes (for example data attributes) to add to the anchor in the footer navigation section. + + + + + containerClasses string diff --git a/src/components/footer/README.njk b/src/components/footer/README.njk index 8d606ca2a8..54adfd16f8 100644 --- a/src/components/footer/README.njk +++ b/src/components/footer/README.njk @@ -114,6 +114,20 @@ text: 'List item href attribute in the meta section of the footer.' } ], + [ + { + text: 'meta.items.{}.attributes' + }, + { + text: 'object' + }, + { + text: 'No' + }, + { + text: 'Any extra HTML attributes (for example data attributes) to add to the anchor in the footer meta section.' + } + ], [ { text: 'navigation' @@ -198,6 +212,20 @@ text: 'List item href attribute in the navigation section of the footer. Both `text` and `href` attributes need to be present to create a link.' } ], + [ + { + text: 'navigation.items.{}.attributes' + }, + { + text: 'object' + }, + { + text: 'No' + }, + { + text: 'Any extra HTML attributes (for example data attributes) to add to the anchor in the footer navigation section.' + } + ], [ { text: 'containerClasses' diff --git a/src/components/footer/template.njk b/src/components/footer/template.njk index 17378de66a..71f3dc00c1 100644 --- a/src/components/footer/template.njk +++ b/src/components/footer/template.njk @@ -16,7 +16,7 @@ {% for item in item.items %} {% if item.href and item.text %}
  • @@ -37,7 +37,7 @@