forked from hello-pangea/dnd
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: support scroll while dragging in an iframe
Showing
4 changed files
with
44 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
import type { Position } from 'css-box-model'; | ||
|
||
export default (el: Element): Position => ({ | ||
x: el.scrollLeft, | ||
y: el.scrollTop, | ||
}); | ||
export default (el: Element): Position => { | ||
const isIframe = el.tagName === 'IFRAME'; | ||
|
||
if (isIframe) { | ||
const targetEl = (el as HTMLIFrameElement).contentWindow!; | ||
|
||
return { x: targetEl.scrollX, y: targetEl.scrollY }; | ||
} | ||
|
||
return { | ||
x: el.scrollLeft, | ||
y: el.scrollTop, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default (scrollable: HTMLElement) => { | ||
const scrollableIsIframe = scrollable.tagName === 'IFRAME'; | ||
|
||
const scrollableTarget = scrollableIsIframe | ||
? (scrollable as HTMLIFrameElement).contentWindow! | ||
: scrollable; | ||
|
||
return scrollableTarget; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters