Skip to content

Commit

Permalink
Clip scrolled rectangle to element bounding box while traversing DOM …
Browse files Browse the repository at this point in the history
…for scrolling
  • Loading branch information
marijnh committed Feb 28, 2025
1 parent 683f9e1 commit 61f4b5c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ export function scrollRectIntoView(dom: HTMLElement, rect: Rect, side: -1 | 1,
}
}
if (top) break
if (rect.top < bounding.top || rect.bottom > bounding.bottom ||
rect.left < bounding.left || rect.right > bounding.right)
rect = {left: Math.max(rect.left, bounding.left), right: Math.min(rect.right, bounding.right),
top: Math.max(rect.top, bounding.top), bottom: Math.min(rect.bottom, bounding.bottom)}
cur = cur.assignedSlot || cur.parentNode
} else if (cur.nodeType == 11) { // A shadow root
cur = cur.host
Expand Down

0 comments on commit 61f4b5c

Please sign in to comment.