@@ -44,13 +44,13 @@ export abstract class ViewportScroller {
44
44
* Scrolls to a specified position.
45
45
* @param position A position in screen coordinates (a tuple with x and y values).
46
46
*/
47
- abstract scrollToPosition ( position : [ number , number ] ) : void ;
47
+ abstract scrollToPosition ( position : [ number , number ] , options ?: ScrollOptions ) : void ;
48
48
49
49
/**
50
50
* Scrolls to an anchor element.
51
51
* @param anchor The ID of the anchor element.
52
52
*/
53
- abstract scrollToAnchor ( anchor : string ) : void ;
53
+ abstract scrollToAnchor ( anchor : string , options ?: ScrollOptions ) : void ;
54
54
55
55
/**
56
56
* Disables automatic scroll restoration provided by the browser.
@@ -97,8 +97,8 @@ export class BrowserViewportScroller implements ViewportScroller {
97
97
* Sets the scroll position.
98
98
* @param position The new position in screen coordinates.
99
99
*/
100
- scrollToPosition ( position : [ number , number ] ) : void {
101
- this . window . scrollTo ( position [ 0 ] , position [ 1 ] ) ;
100
+ scrollToPosition ( position : [ number , number ] , options ?: ScrollOptions ) : void {
101
+ this . window . scrollTo ( { ... options , left : position [ 0 ] , top : position [ 1 ] } ) ;
102
102
}
103
103
104
104
/**
@@ -112,11 +112,11 @@ export class BrowserViewportScroller implements ViewportScroller {
112
112
* @see https://html.spec.whatwg.org/#the-indicated-part-of-the-document
113
113
* @see https://html.spec.whatwg.org/#scroll-to-fragid
114
114
*/
115
- scrollToAnchor ( target : string ) : void {
115
+ scrollToAnchor ( target : string , options ?: ScrollOptions ) : void {
116
116
const elSelected = findAnchorFromDocument ( this . document , target ) ;
117
117
118
118
if ( elSelected ) {
119
- this . scrollToElement ( elSelected ) ;
119
+ this . scrollToElement ( elSelected , options ) ;
120
120
// After scrolling to the element, the spec dictates that we follow the focus steps for the
121
121
// target. Rather than following the robust steps, simply attempt focus.
122
122
//
@@ -140,12 +140,16 @@ export class BrowserViewportScroller implements ViewportScroller {
140
140
* The offset can be used when we know that there is a floating header and scrolling naively to an
141
141
* element (ex: `scrollIntoView`) leaves the element hidden behind the floating header.
142
142
*/
143
- private scrollToElement ( el : HTMLElement ) : void {
143
+ private scrollToElement ( el : HTMLElement , options ?: ScrollOptions ) : void {
144
144
const rect = el . getBoundingClientRect ( ) ;
145
145
const left = rect . left + this . window . pageXOffset ;
146
146
const top = rect . top + this . window . pageYOffset ;
147
147
const offset = this . offset ( ) ;
148
- this . window . scrollTo ( left - offset [ 0 ] , top - offset [ 1 ] ) ;
148
+ this . window . scrollTo ( {
149
+ ...options ,
150
+ left : left - offset [ 0 ] ,
151
+ top : top - offset [ 1 ] ,
152
+ } ) ;
149
153
}
150
154
}
151
155
0 commit comments