Skip to content

Commit 829c6af

Browse files
authored
fix: target attached logic for shadow dom element (#1054)
1 parent ffbe349 commit 829c6af

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ function scrollIntoView<T>(
6464
function scrollIntoView(target: Element, options?: Options | boolean): void
6565
function scrollIntoView<T>(target: Element, options?: Options<T> | boolean) {
6666
// 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-
)
67+
const isTargetAttached =
68+
target.isConnected ||
69+
target.ownerDocument!.documentElement!.contains(target)
7070

7171
if (
7272
isOptionsObject<CustomBehaviorOptions<T>>(options) &&
7373
typeof options.behavior === 'function'
7474
) {
75-
return options.behavior(targetIsDetached ? [] : compute(target, options))
75+
return options.behavior(isTargetAttached ? compute(target, options) : [])
7676
}
7777

7878
// Don't do anything if using a standard behavior on an element that is not in the document
79-
if (targetIsDetached) {
79+
if (!isTargetAttached) {
8080
return
8181
}
8282

0 commit comments

Comments
 (0)