Skip to content

Commit b3cf3a4

Browse files
authored
fix: contains check should work cross iframe boundaries (#482)
* change to cross realms .contains check * ownerDocument won't be null in this context * Thanks IE11… 🤦‍♂️ * Sync with Prettier * Update index.ts
1 parent 82929e9 commit b3cf3a4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ function scrollIntoView<T>(
6363
): T
6464
function scrollIntoView(target: Element, options?: Options | boolean): void
6565
function scrollIntoView<T>(target: Element, options?: Options<T> | boolean) {
66-
// Browsers treats targets that aren't in the dom as a no-op
67-
const scrollingElement = (document.scrollingElement ||
68-
document.documentElement) as Element
69-
const targetIsDetached =
70-
target !== scrollingElement && !scrollingElement.contains(target)
66+
// Browsers treats targets that aren't in the dom as a no-op and so should we
67+
const targetIsDetached = !target.ownerDocument!.documentElement!.contains(
68+
target
69+
)
7170

7271
if (
7372
isOptionsObject<CustomBehaviorOptions<T>>(options) &&

0 commit comments

Comments
 (0)