Skip to content

Commit

Permalink
Update organisation switcher link logic
Browse files Browse the repository at this point in the history
Only display the organisation switcher link if a link object is
passed to the component.

This prevents an empty link tag being output to the source if there
is no link destination.

This change still supports the fallback text as long as a link `href`
is supplied.

It also updates the example to show how the component will look
without a change link and with the fallback link text.
  • Loading branch information
teneightfive committed Aug 7, 2019
1 parent 334d7d2 commit 993b2f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 9 additions & 3 deletions app/views/components/organisation-switcher/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ <h2 class="govuk-heading-l">Example 1</h2>
href: '#'
}
}) }}

<br>

<h2 class="govuk-heading-l">Example 2</h2>
{{ mojOrganisationSwitcher({
text: 'HMP Brixton, HMP/YOI Feltham, HMP/YOI Isis, HMP Pentonville, HMP Thameside, HMP Wandsworth, HMP Wormwood Scrubs',
link: {
text: "Change prisons",
href: '#'
}
}) }}

<br>

<h2 class="govuk-heading-l">Example 3</h2>
{{ mojOrganisationSwitcher({
text: 'HMP Brixton'
}) }}

</div>

</div>
Expand Down
14 changes: 9 additions & 5 deletions src/moj/components/organisation-switcher/template.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<div {% if params.id %}id="{{ params.id }}"{% endif -%} class="moj-organisation-nav {{- ' ' + params.classes if params.classes}}" aria-label="{{ params.label | default('Organisation switcher') }}" {%- for attribute, value in params.attributes -%} {{ attribute }}="{{ value }}"{% endfor %}>
<div {%- if params.id %} id="{{ params.id }}"{% endif %} class="moj-organisation-nav {{- ' ' + params.classes if params.classes }}" aria-label="{{ params.label | default('Organisation switcher') }}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
<div class="moj-organisation-nav__title">
{{- params.html | safe if params.html else params.text -}}
</div>
<a {% if params.link.id %}id="{{ params.link.id }}"{% endif -%} href="{{ params.link.href }}" class="moj-organisation-nav__link {{- ' ' + params.link.classes if params.link.classes}}" {%- for attribute, value in params.link.attributes -%} {{ attribute }}="{{ value }}"{% endfor %}>
{{- params.link.html | safe if params.link.html else params.link.text | default('Change organisation') -}}
</a>
</div>

{% if params.link %}
{%- set linkText = params.link.text | default('Change organisation') -%}
<a {%- if params.link.id %} id="{{ params.link.id }}"{% endif %} href="{{ params.link.href }}" class="moj-organisation-nav__link {{- ' ' + params.link.classes if params.link.classes }}" {%- for attribute, value in params.link.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{{- linkText -}}
</a>
{% endif %}
</div>

0 comments on commit 993b2f4

Please sign in to comment.