Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions _assets/styles/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
height: $navbar-height;
}

// The panel and its backdrop both cross the toggle while the sidebar slides,
// so a tap in that beat would land on whichever one is passing. Sealing the
// sidebar off sends it back to the button, which ignores it until the slide
// settles. The footer script sets the attribute.
[data-sidebar-busy] bento-sidebar {
pointer-events: none;
}

bento-sidebar {
background-color: $secondary;

Expand Down
48 changes: 39 additions & 9 deletions _includes/footer.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,46 @@
</footer>

<script>
(async () => {
const sidebar = document.querySelector('#sidebar');
await customElements.whenDefined('bento-sidebar');
const api = await sidebar.getApi();
// Bento arrives from a CDN, so the page draws and takes taps before the
// runtime lands. The buttons are bound here and wait on the API inside the
// handler, so a tap made in that gap opens the sidebar rather than falling
// on the floor.
const sidebarReady = customElements
.whenDefined('bento-sidebar')
.then(() => document.querySelector('#sidebar').getApi());

// set up button actions
const matches = document.querySelectorAll('.navbar-toggler');
// Bento slides the sidebar in over 350ms, and the panel and its backdrop
// both cross the button on the way. A tap during that stretch lands on
// whatever is passing underneath, so the sidebar stops taking taps and the
// toggle is ignored until it settles.
const slideDuration = 350;
let busy = false;

matches.forEach((match) => {
match.onclick = () => api.toggle(0);
for (const button of document.querySelectorAll('.navbar-toggler')) {
button.addEventListener('click', async () => {
if (busy) return;
busy = true;
document.documentElement.dataset.sidebarBusy = '';

const api = await sidebarReady;
api.toggle();

setTimeout(() => {
busy = false;
delete document.documentElement.dataset.sidebarBusy;
}, slideDuration);
});
})();
}

// The buttons say which state they are in. Reading it off the element keeps
// the answer right when the sidebar closes on the backdrop or on Escape.
const sidebar = document.querySelector('#sidebar');
const togglers = document.querySelectorAll('.navbar-toggler');

new MutationObserver(() => {
const expanded = String(sidebar.hasAttribute('open'));
for (const toggler of togglers) {
toggler.setAttribute('aria-expanded', expanded);
}
}).observe(sidebar, { attributeFilter: ['open'] });
</script>
10 changes: 5 additions & 5 deletions _includes/header.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class='navbar-toggler'
type='button'
aria-label='Toggle navigation'
aria-controls='sidebar'
aria-expanded='false'
>
{% include 'assets/img/sublime-theme/hamburger-secondary.svg' %}
</button>
Expand All @@ -36,17 +38,15 @@
</div>
</nav>
</header>
<bento-sidebar
id='sidebar'
side='right'
layout='nodisplay'
>
<bento-sidebar id='sidebar' side='right'>
<nav class='navbar py-0' aria-label='Sidebar'>
<div class='navbar-toggler-wrapper container-fluid'>
<button
class='navbar-toggler'
type='button'
aria-label='Toggle navigation'
aria-controls='sidebar'
aria-expanded='false'
>
{% include 'assets/img/sublime-theme/hamburger-primary.svg' %}
</button>
Expand Down