mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46: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.innerHTML = `<h3>${title}</h3>${htmlTags}<p class="preview">${content}</p>`
|
||||
|
||||
async function onMouseEnter(ev: 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) => {
|
||||
const handler = (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))
|
||||
})
|
||||
}
|
||||
itemTile.addEventListener("click", handler)
|
||||
window.addCleanup(() => itemTile.removeEventListener("click", handler))
|
||||
|
||||
return itemTile
|
||||
}
|
||||
|
|
|
@ -179,6 +179,7 @@
|
|||
outline: none;
|
||||
font-weight: inherit;
|
||||
|
||||
&:hover,
|
||||
&:focus,
|
||||
&.focus {
|
||||
background: var(--lightgray);
|
||||
|
|
Loading…
Reference in a new issue