Skip to content

Commit

Permalink
Fix skip-to-content scroll behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Apr 5, 2024
1 parent 87fd55d commit 5e9dbe1
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/core/event/index.js
Expand Up @@ -31,7 +31,7 @@ export function Events(Base) {

// Move focus to content
if (query.id || source === 'navigate') {
this.focusContent();
this.#focusContent();
}

if (loadNavbar) {
Expand Down Expand Up @@ -139,19 +139,15 @@ export function Events(Base) {
#enableScrollEvent = true;
#coverHeight = 0;

#skipLink(el) {
el = dom.getNode(el);

if (el === null || el === undefined) {
return;
}

dom.on(el, 'click', evt => {
const target = dom.getNode('#main');
#skipLink(elm) {
elm = typeof elm === 'string' ? dom.find(elm) : elm;

elm?.addEventListener('click', evt => {
evt.preventDefault();
target && target.focus();
this.#scrollTo(target);
dom.getNode('main')?.scrollIntoView({
behavior: 'smooth',
});
this.#focusContent({ preventScroll: true });
});
}

Expand All @@ -177,7 +173,7 @@ export function Events(Base) {
.begin();
}

focusContent() {
#focusContent(options = {}) {
const { query } = this.route;
const focusEl = query.id
? // Heading ID
Expand All @@ -188,7 +184,7 @@ export function Events(Base) {
dom.find('#main');

// Move focus to content area
focusEl && focusEl.focus();
focusEl && focusEl.focus(options);
}

#highlight(path) {
Expand Down

0 comments on commit 5e9dbe1

Please sign in to comment.