Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data-nosnippet to prevent cookie banner text appearing in Google Search snippets #2192

Merged
merged 3 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This was added in [pull request #2164: Enable cookie banner to set link styled a
- [#2157: Use pointer cursor for 'Menu' button in header](https://github.com/alphagov/govuk-frontend/pull/2157) – thanks to [@MalcolmVonMoJ](https://github.com/MalcolmVonMoJ) for contributing this.
- [#2171: Fix padding on GOV.UK logo affecting hover and focus states](https://github.com/alphagov/govuk-frontend/pull/2171)
- [#2186: Fix display of warning text in Edge when Windows High Contrast Mode is enabled](https://github.com/alphagov/govuk-frontend/pull/2186)
- [#2192: Add data-nosnippet to prevent cookie banner text appearing in Google Search snippets](https://github.com/alphagov/govuk-frontend/pull/2192)

## 3.11.0 (Feature release)

Expand Down
15 changes: 15 additions & 0 deletions src/govuk/components/cookie-banner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Cookie banner

## Installation

See the [main README quick start guide](https://github.com/alphagov/govuk-frontend#quick-start) for how to install this component.

## Guidance and Examples

Find out when to use the cookie banner component in your service in the [GOV.UK Design System](https://design-system.service.gov.uk/components/cookie-banner).

## Component options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

See [options table](https://design-system.service.gov.uk/components/cookie-banner/#options-default-cookie-banner-example) for details.
2 changes: 1 addition & 1 deletion src/govuk/components/cookie-banner/template.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% from "../button/macro.njk" import govukButton -%}

<div class="govuk-cookie-banner {{ params.classes if params.classes }}" role="region" aria-label="{{ params.ariaLabel | default("Cookie banner") }}"
<div class="govuk-cookie-banner {{ params.classes if params.classes }}" data-nosnippet role="region" aria-label="{{ params.ariaLabel | default("Cookie banner") }}"
{%- if params.hidden %} hidden{% endif %}
{%- for attribute, value in params.attributes %} {{attribute}}="{{value}}"{% endfor %}>

Expand Down
7 changes: 7 additions & 0 deletions src/govuk/components/cookie-banner/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ describe('Cookie Banner', () => {
const $actions = $('.govuk-cookie-banner__message[hidden]')
expect($actions.length).toEqual(2)
})

it('has a data-nosnippet attribute to hide it from search result snippets', () => {
const $ = render('cookie-banner', examples['client-side implementation'])

const $parentContainer = $('.govuk-cookie-banner')
expect($parentContainer.attr('data-nosnippet')).toEqual('')
})
})

describe('full cookie banner hidden', () => {
Expand Down