Skip to content

Commit

Permalink
improve placement and size of expand/collapse toggle button in nav; c…
Browse files Browse the repository at this point in the history
…hange title to aria-label
  • Loading branch information
mojavelinux committed Nov 9, 2023
1 parent 6adfb9b commit 9c88d12
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/css/nav.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@
.nav-menu-toggle {
background: transparent url(../img/octicons-24.svg#view-unfold) no-repeat center / 100% 100%;
border: none;
outline: none;
width: 0.9rem;
height: 0.9rem;
float: right;
height: 1em;
margin-right: -0.5rem;
opacity: 0.5;
outline: none;
padding: 0;
position: sticky;
top: 0.8075rem;
margin-right: -0.5rem;
float: right;
visibility: hidden;
width: 1em;
top: 0.8rem;
}

.nav-menu-toggle.is-active {
Expand Down
25 changes: 14 additions & 11 deletions src/js/01-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
navContainer.addEventListener('click', trapEvent)

var nav = navContainer.querySelector('.nav')
var navMenuToggle = navContainer.querySelector('.nav-menu-toggle')
var menuPanel = nav.querySelector('[data-panel=menu]')
var navBounds = { encroachingElement: document.querySelector('footer.footer') }
var currentPageItem
Expand Down Expand Up @@ -38,18 +39,20 @@

fitNavInit({})

menuPanel.querySelector('.nav-menu-toggle').addEventListener('click', function () {
var collapse = !this.classList.toggle('is-active')
find(menuPanel, '.nav-item > .nav-item-toggle').forEach(function (btn) {
collapse ? btn.parentElement.classList.remove('is-active') : btn.parentElement.classList.add('is-active')
if (navMenuToggle) {
navMenuToggle.addEventListener('click', function () {
var collapse = !this.classList.toggle('is-active')
find(menuPanel, '.nav-item > .nav-item-toggle').forEach(function (btn) {
collapse ? btn.parentElement.classList.remove('is-active') : btn.parentElement.classList.add('is-active')
})
if (currentPageItem) {
if (collapse) activateCurrentPath(currentPageItem)
scrollItemToMidpoint(menuPanel, currentPageItem)
} else {
menuPanel.scrollTop = 0
}
})
if (currentPageItem) {
if (collapse) activateCurrentPath(currentPageItem)
scrollItemToMidpoint(menuPanel, currentPageItem)
} else {
menuPanel.scrollTop = 0
}
})
}

find(menuPanel, '.nav-item-toggle').forEach(function (btn) {
btn.addEventListener('click', toggleActive.bind(btn.parentElement))
Expand Down
2 changes: 1 addition & 1 deletion src/partials/nav-menu.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#with page.navigation}}
<div class="nav-panel-menu is-active is-loading" data-panel="menu">
<nav class="nav-menu">
<button class="nav-menu-toggle" title="Toggle expand/collapse all"></button>
<button class="nav-menu-toggle" aria-label="Toggle expand/collapse all"></button>
{{#with @root.page.componentVersion}}
<h3 class="title"><a href="{{{relativize ./url}}}">{{./title}}</a></h3>
{{/with}}
Expand Down

0 comments on commit 9c88d12

Please sign in to comment.