From a41295cd2c1cf366f47541652e1723c2f06c5457 Mon Sep 17 00:00:00 2001 From: Oliver Baker Date: Tue, 24 Oct 2023 13:52:34 -0500 Subject: [PATCH] fix(spotlight, usescrollobserver): automatically scroll nearest scrollable element Instead of always trying to scroll the window to highlight the target, it now finds the nearest scrollable element and scrolls that instead. Many times, that will be the window/html element fixes #481 --- src/components/Spotlight/Spotlight.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Spotlight/Spotlight.tsx b/src/components/Spotlight/Spotlight.tsx index fabe55c5d..39046934d 100644 --- a/src/components/Spotlight/Spotlight.tsx +++ b/src/components/Spotlight/Spotlight.tsx @@ -58,7 +58,7 @@ export enum SpotlightShapes { const findNearestScrollingParent = (el: HTMLElement | Element): HTMLElement | Element | null => { const parent = el.parentElement; - if (parent && parent.tagName !== 'html') { + if (parent && parent.tagName !== 'HTML') { if (parent?.scrollHeight > parent?.clientHeight) { // found it! return parent; @@ -150,6 +150,8 @@ const Spotlight = ({ } }, [targetElement]); + console.log(scrollTarget.current); + useEffect(() => { if (targetElement) { const newTargetTop = targetElement?.getBoundingClientRect().top ?? 0;