Skip to content

Commit 312b590

Browse files
Auto scroll to current side nav item + show all breadcrumbs (#161)
* scrollIntoView for current page nav item, show all breadcrumbs * classnames for algolia * more ids for algolia * better algoia selectors
1 parent 76243bc commit 312b590

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
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: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
{{#unless (or (eq page.layout 'landing') (eq page.layout 'full') (eq page.layout 'home'))}}
2-
<nav class="flex" aria-label="breadcrumbs">
3-
{{#if page.breadcrumbs}}
4-
<ul class="flex flex-wrap !list-none !m-0 !p-0">
2+
{{#if page.breadcrumbs}}
3+
<nav id="breadcrumbs" class="flex" aria-label="breadcrumbs">
4+
<ol 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 class="component-home" 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}}
21-
</ul>
22-
{{/if}}
25+
</ol>
2326
</nav>
27+
{{/if}}
2428
{{/unless}}

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}}>

src/partials/nav.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
{{~/if}}
77
id="side-nav"
88
class="h-full bg-level1 overflow-y-scroll flex flex-col w-[18.5rem] px-2 pt-2">
9-
<div class="flex items-start gap-1 mb-1 ">
9+
<div class="flex items-start gap-1 mb-1">
1010
{{#with @root.page.componentVersion}}
11-
<a class="flex flex-grow py-1 px-2 text-h4 hover:bg-level2 rounded transition-colors !no-underline" href="{{{relativize ./url}}}">{{./title}}</a>
11+
<a class="component-home flex flex-grow py-1 px-2 text-h4 hover:bg-level2 rounded transition-colors !no-underline" href="{{{relativize ./url}}}">{{./title}}</a>
1212
{{/with}}
1313
{{> page-versions page=../page}}
1414
</div>

0 commit comments

Comments
 (0)