Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/smooth-tips-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@dnd-kit/core': patch
'@dnd-kit/utilities': patch
---

Fix scroll calculations for draggable elements in a different frame context than the execution context
11 changes: 6 additions & 5 deletions packages/core/src/utilities/scroll/getScrollableElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export function getScrollableElement(element: EventTarget | null) {
return null;
}

if (
isDocument(element) ||
element === getOwnerDocument(element).scrollingElement
) {
return window;
if (isDocument(element)) {
return element.defaultView ?? window;
}

if (element === getOwnerDocument(element).scrollingElement) {
return getOwnerDocument(element)?.defaultView ?? window;
}

if (isHTMLElement(element)) {
Expand Down
6 changes: 5 additions & 1 deletion packages/utilities/src/execution-context/getWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ export function getWindow(target: Event['target']): typeof window {
return window;
}

return target.ownerDocument?.defaultView ?? window;
let ownerDoc = target.ownerDocument;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles when target is the Document object itself

if (!ownerDoc) {
ownerDoc = 'documentElement' in target ? target : null;
}
return ownerDoc?.defaultView ?? window;
}