mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-26 21:36: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
|
|
||||||
currentHover?.classList.remove("focus")
|
|
||||||
currentHover?.blur()
|
|
||||||
const target = ev.target as HTMLInputElement
|
|
||||||
currentHover = target
|
|
||||||
currentHover.classList.add("focus")
|
|
||||||
await displayPreview(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onMouseLeave(ev: MouseEvent) {
|
|
||||||
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
|
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
||||||
hideSearch()
|
hideSearch()
|
||||||
},
|
}
|
||||||
],
|
itemTile.addEventListener("click", handler)
|
||||||
] as const
|
window.addCleanup(() => itemTile.removeEventListener("click", handler))
|
||||||
|
|
||||||
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