Skip to content

Commit

Permalink
Indent HTML for Header
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Feb 9, 2024
1 parent b5ab858 commit 31a389d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
54 changes: 28 additions & 26 deletions src/govuk/components/header/template.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% from "../../macros/attributes.njk" import govukAttributes -%}
{% from "../../macros/attributes.njk" import govukAttributes %}

{% set menuButtonText = params.menuButtonText if params.menuButtonText else 'Menu' -%}
{%- set menuButtonText = params.menuButtonText if params.menuButtonText else 'Menu' -%}

{% set _stEdwardsCrown %}
{%- set _stEdwardsCrown %}
<svg
focusable="false"
role="img"
Expand All @@ -18,7 +18,7 @@
</svg>
{% endset %}

{% set _tudorCrown %}
{%- set _tudorCrown %}
<svg
focusable="false"
role="img"
Expand All @@ -32,7 +32,7 @@
<title>GOV.UK</title>
<path d="M22.6 10.4c-1 .4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s-.1 2-1 2.4m-5.9 6.7c-.9.4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s-.1 2-1 2.4m10.8-3.7c-1 .4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s0 2-1 2.4m3.3 4.8c-1 .4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s-.1 2-1 2.4M17 4.7l2.3 1.2V2.5l-2.3.7-.2-.2.9-3h-3.4l.9 3-.2.2c-.1.1-2.3-.7-2.3-.7v3.4L15 4.7c.1.1.1.2.2.2l-1.3 4c-.1.2-.1.4-.1.6 0 1.1.8 2 1.9 2.2h.7c1-.2 1.9-1.1 1.9-2.1 0-.2 0-.4-.1-.6l-1.3-4c-.1-.2 0-.2.1-.3m-7.6 5.7c.9.4 2-.1 2.4-1 .4-.9-.1-2-1-2.4-.9-.4-2 .1-2.4 1s0 2 1 2.4m-5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.8-.4 1.7-.4 2.7v.1c0 1 .1 1.9.4 2.7.2.8.6 1.6 1.1 2.2.5.6 1.1 1.1 1.7 1.4.6.3 1.4.5 2.4.5zM88.9 28 83 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.4L148 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>
{% endset %}
{% endset -%}

<header class="govuk-header {%- if params.classes %} {{ params.classes }}{% endif %}" role="banner" data-module="govuk-header"
{{- govukAttributes(params.attributes) }}>
Expand All @@ -45,50 +45,52 @@
We use a single compound path for the logo to prevent subpixel rounding
shifting different elements unevenly relative to one another. #}
{{ (_tudorCrown if params.useTudorCrown else _stEdwardsCrown) | safe }}
{{ (_tudorCrown if params.useTudorCrown else _stEdwardsCrown) | safe | trim | indent(8) }}
{% if (params.productName) %}
<span class="govuk-header__product-name">
{{ params.productName }}
</span>
{% endif %}
</a>
</div>
{% if params.serviceName or params.navigation | length %}
{% if params.serviceName or params.navigation | length %}
<div class="govuk-header__content">
{% if params.serviceName %}
{% if params.serviceUrl %}
{% if params.serviceUrl %}
<a href="{{ params.serviceUrl }}" class="govuk-header__link govuk-header__service-name">
{{ params.serviceName }}
</a>
{% else%}
{% else %}
<span class="govuk-header__service-name">
{{ params.serviceName }}
</span>
{% endif %}
{% endif %}
{% endif %}
{% if params.navigation | length %}
<nav aria-label="{{ params.navigationLabel | default(menuButtonText, true) }}" class="govuk-header__navigation {%- if params.navigationClasses %} {{ params.navigationClasses }}{% endif %}">
<button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" {%- if params.menuButtonLabel and params.menuButtonLabel != menuButtonText %} aria-label="{{ params.menuButtonLabel }}"{% endif %} hidden>{{ menuButtonText }}</button>
<nav aria-label="{{ params.navigationLabel | default(menuButtonText, true) }}" class="govuk-header__navigation {%- if params.navigationClasses %} {{ params.navigationClasses }}{% endif %}">
<button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" {%- if params.menuButtonLabel and params.menuButtonLabel != menuButtonText %} aria-label="{{ params.menuButtonLabel }}"{% endif %} hidden>
{{ menuButtonText }}
</button>

<ul id="navigation" class="govuk-header__navigation-list">
<ul id="navigation" class="govuk-header__navigation-list">
{% for item in params.navigation %}
{% if item.text or item.html %}
<li class="govuk-header__navigation-item {%- if item.active %} govuk-header__navigation-item--active{% endif %}">
{% if item.href %}
<a class="govuk-header__link" href="{{ item.href }}"
{{- govukAttributes(item.attributes) -}}>
{% endif %}
{{ item.html | safe if item.html else item.text }}
{% if item.href %}
</a>
{% endif %}
</li>
<li class="govuk-header__navigation-item {%- if item.active %} govuk-header__navigation-item--active{% endif %}">
{% if item.href %}
<a class="govuk-header__link" href="{{ item.href }}"
{{- govukAttributes(item.attributes) -}}>
{% endif %}
{{ item.html | safe | trim | indent(14) if item.html else item.text }}
{% if item.href %}
</a>
{% endif %}
</li>
{% endif %}
{% endfor %}
</ul>
</nav>
</ul>
</nav>
{% endif %}
</div>
{% endif %}
{% endif %}
</div>
</header>
6 changes: 3 additions & 3 deletions src/govuk/components/header/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('header', () => {
const $button = $component.find('.govuk-header__menu-button')

expect($nav.attr('aria-label')).toEqual('Custom navigation label')
expect($button.text()).toEqual('Custom menu button text')
expect($button.text().trim()).toEqual('Custom menu button text')
})

it('renders navigation with active item', () => {
Expand Down Expand Up @@ -237,14 +237,14 @@ describe('header', () => {

const $button = $('.govuk-header__menu-button')

expect($button.text()).toEqual('Menu')
expect($button.text().trim()).toEqual('Menu')
})
it('allows text to be customised', () => {
const $ = render('header', examples['with custom menu button text'])

const $button = $('.govuk-header__menu-button')

expect($button.text()).toEqual('Dewislen')
expect($button.text().trim()).toEqual('Dewislen')
})
})
})
Expand Down

0 comments on commit 31a389d

Please sign in to comment.