Skip to content

Commit 004e258

Browse files
committed
scrollIntoView for current page nav item, show all breadcrumbs
1 parent ed28d4e commit 004e258

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/helpers/is-last.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/js/01-nav.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
})
1616
}
1717

18-
// Open first nav collapse if none are open.
19-
// Useful for pages with no nav links i.e. landing pages.
2018
const sideNav = document.querySelector('#side-nav')
2119
if (sideNav) {
20+
// Open first nav collapse if none are open.
21+
// Useful for pages with no nav links i.e. landing pages.
2222
const activeCollapses = sideNav.querySelectorAll('.collapse > .collapse-content.active')
2323
if (!activeCollapses.length) {
2424
const firstCollapse = sideNav.querySelector('.collapse > .collapse-content')
2525
if (firstCollapse) {
2626
firstCollapse.classList.add('active')
2727
}
2828
}
29+
// Auto scroll the side nav to the current page's side nav link
30+
const currentPageLink = sideNav.querySelector('.nav-link.current-page')
31+
if (currentPageLink) {
32+
currentPageLink.scrollIntoView({ block: 'center' })
33+
}
2934
}
3035

3136
// Top Global Nav horizontal scrolling

src/partials/breadcrumbs.hbs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
<ul class="flex flex-wrap !list-none !m-0 !p-0">
55
{{#with page.componentVersion}}
66
{{#if (and ./title (ne ./title @root.page.breadcrumbs.0.content))}}
7-
<li class="text-link !m-0 !p-0 after:content-['/'] last-of-type:after:content-none after:text-tertiary after:px-2"><a href="{{{relativize ./url}}}">{{{./title}}}</a></li>
7+
<li class="text-link !m-0 !p-0 after:content-['/'] last-of-type:after:content-none after:text-tertiary after:px-2">
8+
<a href="{{{relativize ./url}}}">{{{./title}}}</a>
9+
</li>
810
{{/if}}
911
{{/with}}
1012
{{#each page.breadcrumbs}}
11-
{{#if (and ./url (eq ./urlType 'internal'))}}
12-
{{#if (is-last this ../page.breadcrumbs)}}
13-
<li class="text-tertiary !m-0 !p-0">{{{./content}}}</li>
14-
{{else}}
13+
{{#if ./content}}
14+
{{#if (not (eq ./url @root.page.url))}}
15+
{{#if (eq ./urlType 'internal')}}
1516
<li class="text-link !m-0 !p-0 after:content-['/'] last-of-type:after:content-none after:text-tertiary after:px-2">
1617
<a href="{{{relativize ./url}}}">{{{./content}}}</a>
1718
</li>
19+
{{else}}
20+
<li class="text-tertiary !m-0 !p-0 after:content-['/'] last-of-type:after:content-none after:text-tertiary after:px-2">{{{./content}}}</li>
21+
{{/if}}
1822
{{/if}}
1923
{{/if}}
2024
{{/each}}

src/partials/nav-tree.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<li class="nav-item{{#if ./items.length}} collapse{{/if}}" data-depth="{{or ../level 0}}">
66
{{#if (and ./url (not ./items.length))}}
77
<a
8-
class="nav-link !no-underline"
8+
class="nav-link !no-underline{{#if (eq ./url @root.page.url)}} current-page{{/if}}"
99
href="{{~#if (eq ./urlType 'internal')}}{{{relativize ./url}}}{{~else}}{{{./url}}}{{~/if}}"
1010
{{#if (eq ./url @root.page.url)}} aria-current="page"{{/if}}
1111
{{#if (eq ./urlType 'external')}} target="_blank"{{/if}}>

0 commit comments

Comments
 (0)