Skip to content

Commit

Permalink
Merge pull request #1337 from alphagov/xlink-href-svg
Browse files Browse the repository at this point in the history
Set xlink:href on crown PNG fallback
  • Loading branch information
36degrees authored May 14, 2019
2 parents fea29aa + c08495c commit 840d019
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@

([PR #1319](https://github.com/alphagov/govuk-frontend/pull/1319))

- Prevent the fallback PNG image for the crown in the header from being
downloaded unnecessarily in Internet Explorer and Edge.

([PR #1337](https://github.com/alphagov/govuk-frontend/pull/1337))

## 2.11.0 (Feature release)

🆕 New features:
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
In other browsers <image> is synonymous for the <img> tag and will be
interpreted as such, displaying the fallback image. #}
<image src="{{ params.assetsPath | default('/assets/images') }}/govuk-logotype-crown.png" class="govuk-header__logotype-crown-fallback-image"></image>
<image src="{{ params.assetsPath | default('/assets/images') }}/govuk-logotype-crown.png" xlink:href="" class="govuk-header__logotype-crown-fallback-image"></image>
</svg>
<span class="govuk-header__logotype-text">
GOV.UK
Expand Down
26 changes: 26 additions & 0 deletions src/components/header/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,30 @@ describe('header', () => {
})
})
})

describe('SVG logo', () => {
const $ = render('header', {})
const $svg = $('.govuk-header__logotype-crown')

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

it('sets role="presentation" so that it is ignored by assistive technologies', () => {
expect($svg.attr('focusable')).toEqual('false')
})

describe('fallback PNG', () => {
const $fallbackImage = $('.govuk-header__logotype-crown-fallback-image')

it('uses the <image> tag which is a valid SVG element', () => {
expect($fallbackImage[0].tagName).toEqual('image')
})

it('sets a blank xlink:href to prevent IE from downloading both the SVG and the PNG', () => {
// Cheerio converts xhref to href - https://github.com/cheeriojs/cheerio/issues/1101
expect($fallbackImage.attr('href')).toEqual('')
})
})
})
})

0 comments on commit 840d019

Please sign in to comment.