Skip to content

Commit 61f4b5c

Browse files
committed
Clip scrolled rectangle to element bounding box while traversing DOM for scrolling
1 parent 683f9e1 commit 61f4b5c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/dom.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ export function scrollRectIntoView(dom: HTMLElement, rect: Rect, side: -1 | 1,
193193
}
194194
}
195195
if (top) break
196+
if (rect.top < bounding.top || rect.bottom > bounding.bottom ||
197+
rect.left < bounding.left || rect.right > bounding.right)
198+
rect = {left: Math.max(rect.left, bounding.left), right: Math.min(rect.right, bounding.right),
199+
top: Math.max(rect.top, bounding.top), bottom: Math.min(rect.bottom, bounding.bottom)}
196200
cur = cur.assignedSlot || cur.parentNode
197201
} else if (cur.nodeType == 11) { // A shadow root
198202
cur = cur.host

0 commit comments

Comments
 (0)