Skip to content

Add current item indicator for header navigation #1067

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

Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
33ab393
Remove hardcoded Home link from navigation
frankieroberto Jul 17, 2024
d03ad5b
Add 'Home' to examples
frankieroberto Jul 17, 2024
9aa7a23
Use single path for NHS logo in header
paulrobertlloyd Oct 9, 2024
47cb1b5
Update CHANGELOG with updated SVG logo
paulrobertlloyd Oct 9, 2024
43eac1f
Update SVG in README for header component
paulrobertlloyd Oct 9, 2024
391be0b
Format header styles with Prettier
paulrobertlloyd Oct 9, 2024
5bc6c11
Simplify template logic for header component
paulrobertlloyd Aug 19, 2024
ed57406
Allow transactional service name in header alongside navigation and s…
paulrobertlloyd Aug 20, 2024
acab488
Update CHANGELOG.md
paulrobertlloyd Aug 22, 2024
8a03f6f
Ensure logo in header appears for print media
paulrobertlloyd Oct 24, 2024
61a6089
Refactor header styles
paulrobertlloyd Oct 24, 2024
2184dcc
Update header README to account for recent markup changes
paulrobertlloyd Oct 24, 2024
4934b6b
Update backstop reference images for header component
paulrobertlloyd Oct 24, 2024
08add40
Remove home link from header navigation
paulrobertlloyd Oct 31, 2024
5cde630
Add current item indicator for header navigation
frankieroberto Nov 6, 2024
b26703a
Remove custom class
frankieroberto Nov 13, 2024
fd57863
Fix focus style on expanded menu item
frankieroberto Nov 13, 2024
9ab62ce
Merge branch 'main' into header-breaking-changes
frankieroberto Nov 27, 2024
f793606
Merge branch 'header-breaking-changes' into add-header-navigation-cur…
frankieroberto Nov 27, 2024
74b72c8
Changed current item indicator in white nav to blue
frankieroberto Nov 27, 2024
ae3aaba
Bump mobile current item indicator to 8px
frankieroberto Nov 27, 2024
140dc9c
Set current item in example header-org-white variant
frankieroberto Nov 27, 2024
d3ad1bb
Update backstop images
frankieroberto Nov 27, 2024
ca951e4
Merge branch 'header-breaking-changes' into add-header-navigation-cur…
frankieroberto Dec 18, 2024
96bd854
Fix
frankieroberto Dec 18, 2024
3dc45ab
Bump mobile nav current idem indicator to 6px
frankieroberto Dec 18, 2024
131875e
Remove duplicate entries from changelog
frankieroberto Dec 18, 2024
7e96476
Add entry to changelog
frankieroberto Dec 18, 2024
7185da5
Update backstop images
frankieroberto Dec 18, 2024
d2a800c
Remove excess whitespace
frankieroberto Dec 18, 2024
6cd2e33
Fix: focus link in white header should always have black border
frankieroberto Jan 8, 2025
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# NHS.UK frontend Changelog

## Unreleased

:new: **New features**

- The primary navigation in the header now lets you show which item is the current section or page. ([PR 1067](https://github.com/nhsuk/nhsuk-frontend/pull/1067))

:wrench: **Fixes**

- Fix appearance of disabled warning buttons ([Issue 1034]([https://github.com/nhsuk/nhsuk-service-manual-community-backlog/issues/1034]))
Expand Down
11 changes: 4 additions & 7 deletions app/components/header/header-navigation.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
{{ header({
"primaryLinks": [
{
"url" : "https://www.nhs.uk/conditions",
"label" : "Health A-Z",
"classes": "app-header__navigation-item--current",
"attributes": {
"aria-current": "true"
}
href: "https://www.nhs.uk/conditions",
text: "Health A-Z"
},
{
href: 'https://www.nhs.uk/live-well/',
Expand All @@ -25,7 +21,8 @@
},
{
href: 'https://www.nhs.uk/conditions/social-care-and-support/',
text: 'Care and support'
text: 'Care and support',
active: true
},
{
href: 'https://www.nhs.uk/pregnancy/',
Expand Down
3 changes: 2 additions & 1 deletion app/components/header/header-org-white-nav.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
{
href: '#',
text: 'Wards and departments'
text: 'Wards and departments',
active: true
},
{
href: '#',
Expand Down
3 changes: 2 additions & 1 deletion app/components/header/header-org-white.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
{
href: '#',
text: 'Wards and departments'
text: 'Wards and departments',
active: true
},
{
href: '#',
Expand Down
3 changes: 2 additions & 1 deletion app/components/header/header-service-name-with-nav.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
{
href: '#',
text: 'Design system'
text: 'Design system',
current: true
},
{
'url' : '#',
Expand Down
1 change: 1 addition & 0 deletions app/components/header/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"search": true,
"primaryLinks": [
{

href: "https://www.nhs.uk/conditions",
text: "Health A-Z"
},
Expand Down
19 changes: 19 additions & 0 deletions packages/components/header/_header-white.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,24 @@

.nhsuk-header__navigation-link {
@include nhsuk-link-style-no-visited-state;

// Visual indicator for current navigation item has blue line on
// bottom edge instead of grey in the regular Header nav
&[aria-current="page"],
&[aria-current="true"] {
box-shadow: inset 0 ($nhsuk-focus-width * -1) $color_nhsuk-blue;
}
}

// Drop down navigation
.nhsuk-header__drop-down {
.nhsuk-header__navigation-link {
// When in expanded menu, a current item link should revert to having a
// no box-shadow, with a box-shadow added to containing list item instead.
&[aria-current="page"],
&[aria-current="true"] {
box-shadow: none;
}
}
}
}
38 changes: 38 additions & 0 deletions packages/components/header/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@
margin-bottom: 0;
}

// This is a <strong> element used as a fallback mechanism for visually
// indicating current page in scenarios where CSS isn’t available.
// We don’t actually want it to be bold normally, so inherit parent font-weight.
.nhsuk-header__navigation-item-active-fallback {
font-weight: inherit;
}

.nhsuk-header__navigation-link {
@include nhsuk-font(16);
@include nhsuk-link-style-header;
Expand All @@ -228,6 +235,14 @@
padding: nhsuk-spacing(3) 2px;
white-space: nowrap;

// Visual indicator for current navigation item has grey line on bottom edge,
// and no underline on the link.
&[aria-current="page"],
&[aria-current="true"] {
text-decoration: none;
box-shadow: inset 0 ($nhsuk-focus-width * -1) $nhsuk-border-color;
}

&:focus {
box-shadow: inset 0 ($nhsuk-focus-width * -1) $nhsuk-focus-text-color;
}
Expand Down Expand Up @@ -277,11 +292,34 @@
.nhsuk-header__navigation-link {
@include govuk-width-container;
@include nhsuk-link-style-no-visited-state;
padding: 12px 0;

// When in expanded menu, a current item link should revert to having a
// no box-shadow, with a box-shadow added to containing list item instead.
&[aria-current="page"],
&[aria-current="true"] {
box-shadow: none;
}

// But when focused the black line at the bottom should return,
// again using box-shadow.
&:focus {
box-shadow: inset 0 ($nhsuk-focus-width * -1) $nhsuk-focus-text-color;
}
}

.nhsuk-header__navigation-item {
border-top: 1px solid $color_nhsuk-grey-5;
}

// Current item within expended mobile menu gets blue line on left edge.
//
// The blue line uses an inset box-shadow instead of a border, as there’s
// already a grey border on the top, and using 2 different colour borders
// creates an awkward diagonal line where they meet.
.nhsuk-header__navigation-item--current {
box-shadow: inset 6px 0 $color_nhsuk-blue;
}
}

.nhsuk-header__drop-down--hidden {
Expand Down
16 changes: 14 additions & 2 deletions packages/components/header/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,20 @@
<nav class="nhsuk-navigation" id="header-navigation" role="navigation" aria-label="Primary navigation">
<ul class="nhsuk-header__navigation-list {%- if params.primaryLinks.length < 4 %} nhsuk-header__navigation-list--left-aligned{% endif %}">
{%- for item in params.primaryLinks %}
<li class="nhsuk-header__navigation-item {%- if item.classes %} {{ item.classes }}{% endif %}" {{- nhsukAttributes(item.attributes) }}>
<a class="nhsuk-header__navigation-link" href="{{ item.href if item.href else item.url }}">{{ item.text if item.text else item.label }}</a>
{% set linkInnerContent %}
{# Wrap active links in strong element so users who override colours
or styles still have some indicator of the current nav item. #}
{% if item.active or item.current %}
<strong class="nhsuk-header__navigation-item-active-fallback">{{- item.text -}}</strong>
{% else %}
{{- item.text -}}
{% endif %}
{% endset %}

<li class="nhsuk-header__navigation-item {%- if item.active or item.current %} nhsuk-header__navigation-item--current{% endif %} {%- if item.classes %} {{ item.classes }}{% endif %}" {{- nhsukAttributes(item.attributes) }}>
<a class="nhsuk-header__navigation-link" href="{{item.url}}" {%- if item.active or item.current %} aria-current="{{ 'page' if item.current else 'true' }}"{% endif %}>
{{ linkInnerContent | safe }}
</a>
</li>
{%- endfor %}
<li class="nhsuk-mobile-menu-container">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading