diff --git a/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.yaml b/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.yaml index a55cabf399..b4f684d173 100644 --- a/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.yaml +++ b/packages/govuk-frontend/src/govuk/components/exit-this-page/exit-this-page.yaml @@ -23,6 +23,15 @@ params: type: object required: false description: HTML attributes (for example data attributes) to add to the exit this page container. + - name: button.attributes + type: object + required: false + description: Options for the exit this page button. + params: + - name: attributes + type: object + required: false + description: HTML attributes (for example data attributes) to add to the exit this page button. The default disables referrer information being provided to the `redirectUrl` and tells search engines to ignore the page being linked to. - name: activatedText type: string required: false @@ -66,6 +75,10 @@ examples: classes: 'test-class' attributes: test-attribute: true + button: + attributes: + rel: 'nofollow noreferrer noopener' + test-attribute: true - name: testing-html hidden: true data: diff --git a/packages/govuk-frontend/src/govuk/components/exit-this-page/template.njk b/packages/govuk-frontend/src/govuk/components/exit-this-page/template.njk index 6f3e57637d..3df15b0c76 100644 --- a/packages/govuk-frontend/src/govuk/components/exit-this-page/template.njk +++ b/packages/govuk-frontend/src/govuk/components/exit-this-page/template.njk @@ -15,6 +15,7 @@ html: params.html if (params.html or params.text) else defaultHtml, text: params.text, classes: "govuk-button--warning govuk-exit-this-page__button govuk-js-exit-this-page-button", - href: params.redirectUrl | default("https://www.bbc.co.uk/weather") + href: params.redirectUrl | default("https://www.bbc.co.uk/weather"), + attributes: params.button.attributes | default({ 'rel': 'nofollow noreferrer' }) }) -}} diff --git a/packages/govuk-frontend/src/govuk/components/exit-this-page/template.test.js b/packages/govuk-frontend/src/govuk/components/exit-this-page/template.test.js index c28e4d3348..756a7a23e1 100644 --- a/packages/govuk-frontend/src/govuk/components/exit-this-page/template.test.js +++ b/packages/govuk-frontend/src/govuk/components/exit-this-page/template.test.js @@ -16,6 +16,7 @@ describe('Exit this page', () => { expect($button.hasClass('govuk-button--warning')).toBeTruthy() expect($button.html()).toContain('Emergency Exit this page') expect($button.attr('href')).toBe('/full-page-examples/announcements') + expect($button.attr('rel')).toBe('nofollow noreferrer') }) }) @@ -61,6 +62,14 @@ describe('Exit this page', () => { expect($component.attr('test-attribute')).toBe('true') }) + + it('renders with custom button attributes', () => { + const $ = render('exit-this-page', examples.testing) + const $button = $('.govuk-exit-this-page').find('.govuk-button') + + expect($button.attr('rel')).toBe('nofollow noreferrer noopener') + expect($button.attr('test-attribute')).toBe('true') + }) }) describe('Translated', () => {