mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-23 03:56:23 +00:00
fix(search): dont rely on mouse to manipulate focus
This commit is contained in:
parent
260498a96b
commit
a2c46f442d
2 changed files with 6 additions and 31 deletions
|
@ -310,38 +310,12 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
|
||||||
itemTile.href = resolveUrl(slug).toString()
|
itemTile.href = resolveUrl(slug).toString()
|
||||||
itemTile.innerHTML = `<h3>${title}</h3>${htmlTags}<p class="preview">${content}</p>`
|
itemTile.innerHTML = `<h3>${title}</h3>${htmlTags}<p class="preview">${content}</p>`
|
||||||
|
|
||||||
async function onMouseEnter(ev: MouseEvent) {
|
const handler = (event: MouseEvent) => {
|
||||||
if (!ev.target) return
|
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
||||||
currentHover?.classList.remove("focus")
|
hideSearch()
|
||||||
currentHover?.blur()
|
|
||||||
const target = ev.target as HTMLInputElement
|
|
||||||
currentHover = target
|
|
||||||
currentHover.classList.add("focus")
|
|
||||||
await displayPreview(target)
|
|
||||||
}
|
}
|
||||||
|
itemTile.addEventListener("click", handler)
|
||||||
async function onMouseLeave(ev: MouseEvent) {
|
window.addCleanup(() => itemTile.removeEventListener("click", handler))
|
||||||
if (!ev.target) return
|
|
||||||
const target = ev.target as HTMLElement
|
|
||||||
target.classList.remove("focus")
|
|
||||||
}
|
|
||||||
|
|
||||||
const events = [
|
|
||||||
["mouseenter", onMouseEnter],
|
|
||||||
["mouseleave", onMouseLeave],
|
|
||||||
[
|
|
||||||
"click",
|
|
||||||
(event: MouseEvent) => {
|
|
||||||
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
|
||||||
hideSearch()
|
|
||||||
},
|
|
||||||
],
|
|
||||||
] as const
|
|
||||||
|
|
||||||
events.forEach(([event, handler]) => {
|
|
||||||
itemTile.addEventListener(event, handler)
|
|
||||||
window.addCleanup(() => itemTile.removeEventListener(event, handler))
|
|
||||||
})
|
|
||||||
|
|
||||||
return itemTile
|
return itemTile
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,7 @@
|
||||||
outline: none;
|
outline: none;
|
||||||
font-weight: inherit;
|
font-weight: inherit;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
&:focus,
|
&:focus,
|
||||||
&.focus {
|
&.focus {
|
||||||
background: var(--lightgray);
|
background: var(--lightgray);
|
||||||
|
|
Loading…
Reference in a new issue