Skip to content

Keyboard shortcuts bypass instant navigation and search focus issues #10

@CNSeniorious000

Description

@CNSeniorious000

Hi there! 👋

I noticed that commit 8f49267 (which resolved zensical/zensical#4) introduced a couple of regressions regarding keyboard navigation and search behavior.

1. Navigation shortcuts bypass instant navigation

The shortcuts ., ,, n, and p currently use window.location.href directly, which forces a full page reload even when instant navigation is enabled.

case ",":
case "p":
const prev = document.querySelector("link[rel=prev]")
if (prev instanceof HTMLLinkElement)
window.location.href = prev.href
break
// Go to next page
case ".":
case "n":
const next = document.querySelector("link[rel=next]")
if (next instanceof HTMLLinkElement)
window.location.href = next.href
break

In contrast, mkdocs-material uses setLocation() to respect the instant navigation feature:
https://github.com/squidfunk/mkdocs-material/blob/master/src/templates/assets/javascripts/bundle.ts#L189-L200

Actually in 8f49267 you did import setLocation but didn't use it.

2. Search shortcut (/) issues

When pressing / to open search:

  1. The preventDefault isn't called, so the / character gets typed into the input field if focused.
  2. Pressing Esc closes the panel but doesn't blur the input or reset focus properly. If you type / -> Esc -> 123 -> /, you'll find 123 typed into the search box.

case "/":
const el = document.querySelector("[data-md-component=search] button")
if (el instanceof HTMLButtonElement)
el.click()
break

It would be great to align these behaviors with the expected SPA experience. Thanks for your work on this! 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions