Skip to content

Commit

Permalink
feat(front): enhances mini PageNav TOC keyboard navigation focus (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrebb committed Oct 11, 2023
1 parent 4562e1e commit fbdca34
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions front/src/lib/_utils/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const focusTrap = (node, enabled) => {
const miniNavToggle = document.getElementById('page-navigation-checkbox');
miniNavToggle.checked = false;
miniNavToggle.focus();
} else {
return;
}
});
};
19 changes: 18 additions & 1 deletion front/src/lib/components/content/TableOfContents.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@
export let pageFenceClickHandler = null;
export let activeLink = null;
export let setActiveLink = null;
const TOCAnchorFocus = (e) => {
if (e.key === 'Enter' || e.keyCode === 13) {
const anchor = e.target.getAttribute('href');
const focusTarget = document.querySelector(
`.post-article a[href="${anchor}"]`
);
e.preventDefault();
pageFenceClickHandler(e);
focusTarget.focus();
} else {
return;
}
};
</script>

<ul class="toc">
{#each Object.values(contents) as { text, link }, i}
{#each contents as { text, link }, i}
<li>
<a
on:click={(e) => {
Expand All @@ -20,6 +34,9 @@
data-sveltekit-replacestate
data-sveltekit-noscroll="false"
use:activeLink
on:keydown={(e) => {
TOCAnchorFocus(e);
}}
>
<SvelteMarkdown source={text} isInline />
</a>
Expand Down
3 changes: 3 additions & 0 deletions front/src/lib/styles/base/utilities.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
transition-duration: var(--transition-duration);
transition-timing-function: var(--transition-timing-function);
}
.hidden {
display: none;
}
}

0 comments on commit fbdca34

Please sign in to comment.