Skip to content

Commit

Permalink
Fix homepage active state in navigation and add parameter to allow th…
Browse files Browse the repository at this point in the history
…is to work properly in the prototype kit (#401)
  • Loading branch information
bameyrick authored Jun 4, 2019
1 parent cd0476f commit 49bdd90
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
17 changes: 9 additions & 8 deletions src/components/header/_macro-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

## Navigation

| Name | Type | Required | Description |
| ------------- | ------------- | -------- | ---------------------------------------------------------- |
| currentPath | string | true | Path to the default active page |
| classes | string | false | Additional css classes for the navigation element |
| id | string | true | A unique ID for the navigation element |
| ariaLabel | string | true | The aria-label added to the navigation element |
| ariaListLabel | string | true | The aria-label added to the navigation list |
| itemsList | `Array<Item>` | true | An array of list items to render in the navigation element |
| Name | Type | Required | Description |
| ------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| currentPath | string | true | Path to the default active page |
| classes | string | false | Additional css classes for the navigation element |
| id | string | true | A unique ID for the navigation element |
| ariaLabel | string | true | The aria-label added to the navigation element |
| ariaListLabel | string | true | The aria-label added to the navigation list |
| itemsList | `Array<Item>` | true | An array of list items to render in the navigation element |
| siteBasePath | string | false | If the base path for your site is not `/` (i.e. in a prototype), you can use this to get the active functionality working on your Home link |

## Item

Expand Down
2 changes: 1 addition & 1 deletion src/components/header/_macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<nav class="header-nav header-nav--mobile js-header-nav" id="{{ params.navigation.id }}" aria-label="{{ params.navigation.ariaLabel }}">
<ul class="header-nav__list" aria-label="{{ params.navigation.ariaListLabel }}" role="menubar">
{% for item in (params.navigation.itemsList if params.navigation.itemsList is iterable else params.navigation.itemsList.items()) %}
<li class="header-nav__item {{ item.classes }}{{ ' header-nav__item--active' if (item.url == params.navigation.currentPath) or (item.url in params.navigation.currentPath) }}">
<li class="header-nav__item {{ item.classes }}{{ ' header-nav__item--active' if (item.url == params.navigation.currentPath) or (item.url != (params.navigation.siteBasePath | default('/')) and item.url in params.navigation.currentPath) }}">
<a href="{{ item.url }}" class="header-nav__link" role="menuitem">{{ item.title }}</a>
</li>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion src/get-started/index.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Get started
sortOrder: 1
sortOrder: 2
---
You can start using the latest version of the ONS Design System in your service right now. All of the styles, assets and components are production ready.

Expand Down
3 changes: 2 additions & 1 deletion src/index.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: ONS Design System - Homepage
title: Home
layout: home
sortOrder: 1
---
{% from "components/button/_macro.njk" import onsButton %}
{% from "components/card/_macro.njk" import onsCard %}
Expand Down
1 change: 1 addition & 0 deletions src/patterns/index.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Patterns
sortOrder: 4
---
Patterns are best practice, simple, and reusable solutions to users' commonly occurring tasks or problems,
built up of [components](/components).
1 change: 1 addition & 0 deletions src/styles/index.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Styles
sortOrder: 5
---

Styles make up the foundations on which ONS digital products and services are built.
Expand Down
3 changes: 1 addition & 2 deletions src/views/layouts/_home.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"ariraListLabel": "Navigation menu",
"currentPath": pageInfo.url,
"itemsList": helpers.navigationHelper({
"pages": pageInfo.siteMap,
"ignoreURLs": ["/"]
"pages": pageInfo.siteMap
})
}
})
Expand Down
3 changes: 1 addition & 2 deletions src/views/layouts/_page.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"ariraListLabel": "Navigation menu",
"currentPath": pageInfo.url,
"itemsList": helpers.navigationHelper({
"pages": pageInfo.siteMap,
"ignoreURLs": ["/"]
"pages": pageInfo.siteMap
})
}
})
Expand Down

0 comments on commit 49bdd90

Please sign in to comment.