Skip to content

Commit

Permalink
fix(spotlight, usescrollobserver): automatically scroll nearest scrol…
Browse files Browse the repository at this point in the history
…lable 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
  • Loading branch information
aVileBroker committed Oct 24, 2023
1 parent 92eac05 commit a41295c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/Spotlight/Spotlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,6 +150,8 @@ const Spotlight = ({
}
}, [targetElement]);

console.log(scrollTarget.current);

useEffect(() => {
if (targetElement) {
const newTargetTop = targetElement?.getBoundingClientRect().top ?? 0;
Expand Down

0 comments on commit a41295c

Please sign in to comment.