Skip to content

Commit

Permalink
Merge pull request #4449 from alphagov/transition-crown-v5
Browse files Browse the repository at this point in the history
Implement transitional crown in the Header component (v5.0)
  • Loading branch information
querkmachine authored Nov 23, 2023
2 parents 7a237b5 + e346a4a commit 7a1913e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 54 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ For advice on how to use these release notes see [our guidance on staying up to

## Unreleased

### Breaking changes

#### Update the GOV.UK logo

The GOV.UK logo has been updated to merge the GOV.UK text with the crown graphic. This is to ensure that the full logo is always rendered correctly even if parts of the page, such as CSS or the Transport webfont fail to load. Styles relating to the logo have also been modified.

If you're using the `govukHeader` Nunjucks macro you don't need to change anything.

Otherwise, to update to the new logo:

1. Remove `<span class="govuk-header__logotype-text">` and its content.
2. Remove the `<span class="govuk-header__logotype">` around the `svg` element.
3. Replace the `svg` element with [this updated SVG](https://github.com/alphagov/govuk-frontend/blob/06e6a56655f458112363423dc8f1fb50d21b225e/packages/govuk-frontend/src/govuk/components/header/template.njk#L14-L25), ensuring that the class name and attributes are also updated.

This change was made in [pull request #4449: Implement transitional crown in the Header component (v5.0)](https://github.com/alphagov/govuk-frontend/pull/4449).

### Recommended changes

We've recently made some non-breaking changes to GOV.UK Frontend. Implementing these changes will make your service work better.
Expand Down
45 changes: 28 additions & 17 deletions packages/govuk-frontend/src/govuk/components/header/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$govuk-header-link-underline-thickness: 3px;

.govuk-header {
@include govuk-font($size: 16);
@include govuk-font($size: 16, $line-height: 1);

border-bottom: govuk-spacing(2) solid govuk-colour("white");
color: $govuk-header-text;
Expand All @@ -34,10 +34,14 @@

.govuk-header__logotype {
display: inline-block;
position: relative;
top: -3px;

// Add a gap after the logo in case it's followed by a product name. This
// gets removed later if the logotype is a :last-child.
margin-right: govuk-spacing(1);
fill: currentcolor;
vertical-align: top;

// Prevent readability backplate from obscuring underline in Windows High
// Contrast Mode
Expand All @@ -53,18 +57,32 @@
}
}

.govuk-header__logotype-crown {
position: relative;
top: -1px;
margin-right: 1px;
fill: currentcolor;
vertical-align: top;
}

.govuk-header__product-name {
$product-name-offset: 10px;
$product-name-offset-tablet: 5px;

@include govuk-typography-responsive($size: 24, $override-line-height: 1);
@include govuk-typography-weight-regular;
display: inline-table;

// Maintain space below logo when wrapped
margin-top: $product-name-offset;

// Firefox places the GOV.UK logo one pixel higher, due to how it rounds
// subpixels, so nudge the product name in FF to still be aligned.
@-moz-document url-prefix() {
margin-top: $product-name-offset - 0.5px;
}

// Align vertically with logo when not wrapped
vertical-align: top;

@include govuk-media-query($from: tablet) {
margin-top: $product-name-offset-tablet;
@-moz-document url-prefix() {
margin-top: $product-name-offset-tablet - 0.5px;
}
}
}

.govuk-header__link {
Expand Down Expand Up @@ -96,13 +114,11 @@
.govuk-header__link--homepage {
// Font size needs to be set on the link so that the box sizing is correct
// in Firefox
@include govuk-typography-weight-bold;
display: inline-block;
margin-right: govuk-spacing(2);
font-size: 30px; // We don't have a mixin that produces 30px font size
line-height: 1;

@include govuk-media-query($from: tablet) {
@include govuk-media-query($from: desktop) {
display: inline;

&:focus {
Expand Down Expand Up @@ -288,11 +304,6 @@
background: transparent;
}

// Hide the inverted crown when printing in browsers that don't support SVG.
.govuk-header__logotype-crown-fallback-image {
display: none;
}

.govuk-header__link {
&:link,
&:visited {
Expand Down
47 changes: 17 additions & 30 deletions packages/govuk-frontend/src/govuk/components/header/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,24 @@
<div class="govuk-header__container {{ params.containerClasses | default("govuk-width-container", true) }}">
<div class="govuk-header__logo">
<a href="{{ params.homepageUrl | default("/", true) }}" class="govuk-header__link govuk-header__link--homepage">
<span class="govuk-header__logotype">
{#- We use an inline SVG for the crown so that we can cascade the
currentColor into the crown whilst continuing to support older browsers
which do not support external SVGs without a Javascript polyfill. This
adds approximately 1kb to every page load.
{#- The SVG needs `focusable="false"` so that Internet Explorer does
not treat it as an interactive element - without this it will be
'focusable' when using the keyboard to navigate.
We use currentColour so that we can easily invert it when printing and
when the focus state is applied. This also benefits users who override
colours in their browser as they will still see the crown.
The SVG needs `focusable="false"` so that Internet Explorer does not
treat it as an interactive element - without this it will be
'focusable' when using the keyboard to navigate. #}
<svg
aria-hidden="true"
focusable="false"
class="govuk-header__logotype-crown"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 132 97"
height="30"
width="36"
>
<path
fill="currentColor" fill-rule="evenodd"
d="M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 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-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z"
></path>
</svg>
<span class="govuk-header__logotype-text">
GOV.UK
</span>
</span>
We use a single compound path for the logo to prevent subpixel rounding
shifting different elements unevenly relative to one another. #}
<svg
focusable="false"
role="img"
class="govuk-header__logotype"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 152 30"
height="30"
width="152"
>
<title>GOV.UK</title>
<path d="M6.7 12.2c1 .4 2.1-.1 2.5-1s-.1-2.1-1-2.5c-1-.4-2.1.1-2.5 1-.4 1 0 2.1 1 2.5m-4.3 2.5c1 .4 2.1-.1 2.5-1s-.1-2.1-1-2.5c-1-.4-2.1.1-2.5 1-.5 1 0 2.1 1 2.5m-1.3 4.8c1 .4 2.1-.1 2.5-1 .4-1-.1-2.1-1-2.5-1-.4-2.1.1-2.5 1-.4 1 0 2.1 1 2.5m10.4-5.8c1 .4 2.1-.1 2.5-1s-.1-2.1-1-2.5c-1-.4-2.1.1-2.5 1s0 2.1 1 2.5m17.4-1.5c-1 .4-2.1-.1-2.5-1s.1-2.1 1-2.5c1-.4 2.1.1 2.5 1 .5 1 0 2.1-1 2.5m4.3 2.5c-1 .4-2.1-.1-2.5-1s.1-2.1 1-2.5c1-.4 2.1.1 2.5 1 .5 1 0 2.1-1 2.5m1.3 4.8c-1 .4-2.1-.1-2.5-1-.4-1 .1-2.1 1-2.5 1-.4 2.1.1 2.5 1 .4 1 0 2.1-1 2.5m-10.4-5.8c-1 .4-2.1-.1-2.5-1s.1-2.1 1-2.5c1-.4 2.1.1 2.5 1s0 2.1-1 2.5m-5.3-4.9 2.4 1.3V6.5l-2.4.8c-.1-.1-.1-.2-.2-.2s1-3 1-3h-3.4l1 3c-.1.1-.2.1-.2.2-.1.1-2.4-.7-2.4-.7v3.5L17 8.8c-.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1.4.7-.3 1.5-.5 2.4-.5.9 0 1.7.2 2.4.5s1.3.8 1.7 1.4c.5.6.8 1.3 1.1 2.2.2.8.4 1.7.4 2.7v.1zM92.9 28 87 7h4.7l4 15.7h.1l4-15.7h4.7l-5.9 21h-5.7zm28.8-3.6c.6 0 1.2-.1 1.7-.3.5-.2 1-.4 1.4-.8.4-.4.7-.8.9-1.4.2-.6.3-1.2.3-2v-13h4.1v13.6c0 1.2-.2 2.2-.6 3.1s-1 1.7-1.8 2.4c-.7.7-1.6 1.2-2.7 1.5-1 .4-2.2.5-3.4.5-1.2 0-2.4-.2-3.4-.5-1-.4-1.9-.9-2.7-1.5-.8-.7-1.3-1.5-1.8-2.4-.4-.9-.6-2-.6-3.1V6.9h4.2v13c0 .8.1 1.4.3 2 .2.6.5 1 .9 1.4.4.4.8.6 1.4.8.6.2 1.1.3 1.8.3zm13-17.4h4.2v9.1l7.4-9.1h5.2l-7.2 8.4L152 28h-4.9l-5.5-9.4-2.7 3V28h-4.2V7zm-27.6 16.1c-1.5 0-2.7 1.2-2.7 2.7s1.2 2.7 2.7 2.7 2.7-1.2 2.7-2.7-1.2-2.7-2.7-2.7z"></path>
</svg>
{% if (params.productName) %}
<span class="govuk-header__product-name">
{{ params.productName }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,19 @@ describe('header', () => {

beforeAll(() => {
$ = render('header', examples.default)
$svg = $('.govuk-header__logotype-crown')
$svg = $('.govuk-header__logotype')
})

it('sets focusable="false" so that IE does not treat it as an interactive element', () => {
expect($svg.attr('focusable')).toEqual('false')
})

it('sets aria-hidden="true" so that it is ignored by assistive technologies', () => {
expect($svg.attr('aria-hidden')).toEqual('true')
it('sets role="img" so that assistive technologies do not treat it as an embedded document', () => {
expect($svg.attr('role')).toEqual('img')
})

it('has an embedded <title> element to serve as alternative text', () => {
expect($svg.html()).toContain('<title>GOV.UK</title>')
})
})
})
10 changes: 6 additions & 4 deletions packages/govuk-frontend/src/govuk/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ describe('Template', () => {
})
})

// These tests use a select that specifically looks for a <title> within the <head> of the page
// to prevent them from matching <title> elements within embedded SVGs.
describe('<title>', () => {
const expectedTitle =
'GOV.UK - The best place to find government services and information'

it(`defaults to '${expectedTitle}'`, () => {
const $ = renderTemplate('govuk/template.njk')
expect($('title').text()).toEqual(expectedTitle)
expect($('head > title').text()).toEqual(expectedTitle)
})

it('can be overridden using the pageTitle block', () => {
Expand All @@ -181,12 +183,12 @@ describe('Template', () => {
}
})

expect($('title').text()).toEqual('Foo')
expect($('head > title').text()).toEqual('Foo')
})

it('does not have a lang attribute by default', () => {
const $ = renderTemplate('govuk/template.njk')
expect($('title').attr('lang')).toBeUndefined()
expect($('head > title').attr('lang')).toBeUndefined()
})

it('can have a lang attribute specified using pageTitleLang', () => {
Expand All @@ -196,7 +198,7 @@ describe('Template', () => {
}
})

expect($('title').attr('lang')).toEqual('zu')
expect($('head > title').attr('lang')).toEqual('zu')
})
})
})
Expand Down

0 comments on commit 7a1913e

Please sign in to comment.