From 422986c98babf19f00fc65078e3167eba5aaf7f7 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:00:19 -0500 Subject: [PATCH] fix(search): remove background with mouseEvent (#775) * fix(search): remove background with mouseEvent make sure when mouseenter we remove all existing background Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> * chore: update logics from suggestions Co-authored-by: Jacky Zhao * revert: class is evicted * fix: address correct type Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --------- Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> Co-authored-by: Jacky Zhao --- quartz/components/scripts/search.inline.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts index 5f2da36ee..170a8f014 100644 --- a/quartz/components/scripts/search.inline.ts +++ b/quartz/components/scripts/search.inline.ts @@ -281,12 +281,14 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { }) async function onMouseEnter(ev: MouseEvent) { - // When search is active, the first element is in focus, so we need to remove focus if given target is not the first element - const firstEl = document.getElementsByClassName("result-card")[0] as HTMLAnchorElement | null - const target = ev.target as HTMLAnchorElement - if (firstEl !== target) { - firstEl?.classList.remove("focus") + // Actually when we hover, we need to clean all highlights within the result childs + for (const el of document.getElementsByClassName( + "result-card", + ) as HTMLCollectionOf) { + el.classList.remove("focus") + el.blur() } + const target = ev.target as HTMLAnchorElement target.classList.add("focus") await displayPreview(target) }