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

Conditional navigation items #238

Merged
merged 2 commits into from
Jul 9, 2024
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
18 changes: 9 additions & 9 deletions x-govuk/components/primary-navigation/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<div class="govuk-width-container">
<h2 class="govuk-visually-hidden" id="primary-navigation-heading">{{ params.visuallyHiddenTitle or "Menu" }}</h2>
<ul class="x-govuk-primary-navigation__list">
{%- for item in params.items %}
{% if item.href %}
<li class="x-govuk-primary-navigation__item {{ "x-govuk-primary-navigation__item--current" if item.current }}{% if item.classes %} {{ item.classes }}{% endif -%}">
<a class="x-govuk-primary-navigation__link" {{ "aria-current=page" if item.current }} href="{{ item.href }}">
{{- item.text -}}
</a>
</li>
{% endif %}
{% endfor -%}
{%- for item in params.items %}
{% if item %}
<li class="x-govuk-primary-navigation__item {{ "x-govuk-primary-navigation__item--current" if item.current }}{% if item.classes %} {{ item.classes }}{% endif -%}">
<a class="x-govuk-primary-navigation__link" {{ "aria-current=page" if item.current }} href="{{ item.href }}">
{{- item.text -}}
</a>
</li>
{% endif %}
{% endfor -%}
</ul>
</div>
</nav>
66 changes: 33 additions & 33 deletions x-govuk/components/related-navigation/template.njk
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{% set headingLevel = params.headingLevel or 2 %}
<div class="x-govuk-related-navigation{%- if params.classes %} {{ params.classes }}{% endif -%}"
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{% for section in params.sections %}
{% set sectionTitle = section.title or "Related content" %}
{% set sectionId = section.id or sectionTitle | lower | replace(" ", "-") %}
<nav class="x-govuk-related-navigation__nav-section" role="navigation" aria-labelledby="related-navigation-{{ sectionId }}">
<h{{ headingLevel }} class="x-govuk-related-navigation__main-heading" id="related-navigation-{{ sectionId }}">
{{ sectionTitle }}
</h{{ headingLevel }}>
{% if section.items %}
{% for section in params.sections %}
{% set sectionTitle = section.title or "Related content" %}
{% set sectionId = section.id or sectionTitle | lower | replace(" ", "-") %}
<nav class="x-govuk-related-navigation__nav-section" role="navigation" aria-labelledby="related-navigation-{{ sectionId }}">
<h{{ headingLevel }} class="x-govuk-related-navigation__main-heading" id="related-navigation-{{ sectionId }}">
{{ sectionTitle }}
</h{{ headingLevel }}>
{% if section.items %}
<ul class="x-govuk-related-navigation__link-list">
{% for item in section.items %}
<li class="x-govuk-related-navigation__link">
<a class="govuk-link x-govuk-related-navigation__section-link x-govuk-related-navigation__section-link--other" href="{{ item.href }}">{{ item.text }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% for subsection in section.subsections %}
{% set subsectionId = subsection.id or subsection.title | lower | replace(" ", "-") %}
<nav role="navigation" class="x-govuk-related-navigation__nav-section"{% if subsection.title %} aria-labelledby="related-navigation-{{ subsectionId }}"{% endif %}>
{% if subsection.title %}
<h{{ headingLevel + 1 }} class="x-govuk-related-navigation__sub-heading" id="related-navigation-{{ subsectionId }}">
{{ subsection.title }}
</h{{ headingLevel + 1 }}>
{% endif %}
<ul class="x-govuk-related-navigation__link-list">
{% for item in section.items %}
<li class="x-govuk-related-navigation__link">
<a class="govuk-link x-govuk-related-navigation__section-link x-govuk-related-navigation__section-link--other" href="{{ item.href }}">{{ item.text }}</a>
</li>
{% endfor %}
{% for item in subsection.items %}
<li class="x-govuk-related-navigation__link">
<a class="govuk-link x-govuk-related-navigation__section-link" href="{{ item.href }}">{{ item.text }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% for subsection in section.subsections %}
{% set subsectionId = subsection.id or subsection.title | lower | replace(" ", "-") %}
<nav role="navigation" class="x-govuk-related-navigation__nav-section"{% if subsection.title %} aria-labelledby="related-navigation-{{ subsectionId }}"{% endif %}>
{% if subsection.title %}
<h{{ headingLevel + 1 }} class="x-govuk-related-navigation__sub-heading" id="related-navigation-{{ subsectionId }}">
{{ subsection.title }}
</h{{ headingLevel + 1 }}>
{% endif %}
<ul class="x-govuk-related-navigation__link-list">
{% for item in subsection.items %}
<li class="x-govuk-related-navigation__link">
<a class="govuk-link x-govuk-related-navigation__section-link" href="{{ item.href }}">{{ item.text }}</a>
</li>
{% endfor %}
</ul>
</nav>
{% endfor %}
</nav>
{% endfor %}
</nav>
{% endfor %}
</nav>
{% endfor %}
</div>
16 changes: 9 additions & 7 deletions x-govuk/components/secondary-navigation/template.njk
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<nav class="x-govuk-secondary-navigation {%- if params.classes %} {{ params.classes }}{% endif -%}" {% if params.labelledBy %}aria-labelledby="{{ params.labelledBy }}"{% else %}aria-label="{{ params.visuallyHiddenTitle or "Secondary menu" }}"{% endif %} {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
<ul class="x-govuk-secondary-navigation__list">
{% for item in params.items %}
<li class="x-govuk-secondary-navigation__list-item {{ "x-govuk-secondary-navigation__list-item--current" if item.current }}{% if item.classes %} {{ item.classes }}{% endif -%}">
<a class="x-govuk-secondary-navigation__link" href="{{ item.href }}" {{ "aria-current=page" if item.current }}>
{{ item.text }}
</a>
</li>
{% endfor %}
{% for item in params.items %}
{% if item %}
<li class="x-govuk-secondary-navigation__list-item {{ "x-govuk-secondary-navigation__list-item--current" if item.current }}{% if item.classes %} {{ item.classes }}{% endif -%}">
<a class="x-govuk-secondary-navigation__link" href="{{ item.href }}" {{ "aria-current=page" if item.current }}>
{{ item.text }}
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</nav>
38 changes: 20 additions & 18 deletions x-govuk/components/sub-navigation/template.njk
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<nav class="x-govuk-sub-navigation{%- if params.classes %} {{ params.classes }}{% endif %}" aria-labelledby="sub-navigation-heading"
{%- for attribute, value in params.attributes %} {{ attribute }}="{{value}}"{% endfor %}>
<h2 class="govuk-visually-hidden" id="sub-navigation-heading">{{ params.visuallyHiddenTitle or "Pages in this section" }}</h2>
{% for theme, items in params.items | groupby("theme") %}
{% if theme != "undefined" %}
<h3 class="x-govuk-sub-navigation__theme">{{ theme }}</h3>
{% endif %}
<ul class="x-govuk-sub-navigation__section">
{% for item in items %}
<li class="x-govuk-sub-navigation__section-item{% if item.parent or item.current %} x-govuk-sub-navigation__section-item--current{% endif %}">
<a class="x-govuk-sub-navigation__link" href="{{ item.href }}"{% if item.current %} aria-current="true"{% endif %}>{{ item.text }}</a>
{% if item.parent and item.children | length > 0 %}
<ul class="x-govuk-sub-navigation__section x-govuk-sub-navigation__section--nested">
{% for child in item.children %}
<li class="x-govuk-sub-navigation__section-item">
<a class="x-govuk-sub-navigation__link" href="{{ child.href }}"{% if child.current %} aria-current="true"{% endif %}>{{ child.text }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% for theme, items in params.items | groupby("theme") %}
{% if theme != "undefined" %}
<h3 class="x-govuk-sub-navigation__theme">{{ theme }}</h3>
{% endif %}
<ul class="x-govuk-sub-navigation__section">
{% for item in items %}
{% if item %}
<li class="x-govuk-sub-navigation__section-item{% if item.parent or item.current %} x-govuk-sub-navigation__section-item--current{% endif %}">
<a class="x-govuk-sub-navigation__link" href="{{ item.href }}"{% if item.current %} aria-current="true"{% endif %}>{{ item.text }}</a>
{% if item.parent and item.children | length > 0 %}
<ul class="x-govuk-sub-navigation__section x-govuk-sub-navigation__section--nested">
{% for child in item.children %}
<li class="x-govuk-sub-navigation__section-item">
<a class="x-govuk-sub-navigation__link" href="{{ child.href }}"{% if child.current %} aria-current="true"{% endif %}>{{ child.text }}</a>
</li>
{% endfor %}
</ul>
</ul>
{% endif %}
</li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}
</nav>