File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,21 @@ function scrollIntoView<T>(
63
63
) : T
64
64
function scrollIntoView ( target : Element , options ?: Options | boolean ) : void
65
65
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 || document . documentElement
68
+ const targetIsDetached =
69
+ target !== scrollingElement && ! scrollingElement . contains ( target )
70
+
66
71
if (
67
72
isOptionsObject < CustomBehaviorOptions < T > > ( options ) &&
68
73
typeof options . behavior === 'function'
69
74
) {
70
- return options . behavior ( compute ( target , options ) )
75
+ return options . behavior ( targetIsDetached ? [ ] : compute ( target , options ) )
76
+ }
77
+
78
+ // Don't do anything if using a standard behavior on an element that is not in the document
79
+ if ( targetIsDetached ) {
80
+ return
71
81
}
72
82
73
83
// @TODO see if it's possible to avoid this assignment
You can’t perform that action at this time.
0 commit comments