Improved search user experience

This commit is contained in:
squidfunk
2017-07-25 17:02:42 +02:00
committed by Martin Donath
parent 357c6f4122
commit bda96f88df
3 changed files with 7 additions and 9 deletions

View File

@@ -302,9 +302,8 @@ function initialize(config) { // eslint-disable-line func-style
/* Retrieve all results */
const links = Array.prototype.slice.call(
document.querySelectorAll("[data-md-component=search] [href]"))
if (!links.length)
return
document.querySelectorAll(
"[data-md-component=query], [data-md-component=search] [href]"))
/* Retrieve current active/focused result */
const focus = links.find(link => {
@@ -321,10 +320,10 @@ function initialize(config) { // eslint-disable-line func-style
) % links.length)
/* Set active state and focus */
if (!(links[index] instanceof HTMLElement))
throw new ReferenceError
links[index].dataset.mdState = "active"
links[index].focus()
if (links[index]) {
links[index].dataset.mdState = "active"
links[index].focus()
}
/* Prevent scrolling of page */
ev.preventDefault()