@@ -29,6 +29,16 @@ export const TOUCH_BUFFER_MS = 650;
2929export type FocusOrigin = 'touch' | 'mouse' | 'keyboard' | 'program' | null ;
3030
3131
32+ /**
33+ * Corresponds to the options that can be passed to the native `focus` event.
34+ * via https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
35+ */
36+ export interface FocusOptions {
37+ /** Whether the browser should scroll to the element when it is focused. */
38+ preventScroll ?: boolean ;
39+ }
40+
41+
3242type MonitoredElementInfo = {
3343 unlisten : Function ,
3444 checkChildren : boolean ,
@@ -135,15 +145,17 @@ export class FocusMonitor implements OnDestroy {
135145
136146 /**
137147 * Focuses the element via the specified focus origin.
138- * @param element The element to focus.
139- * @param origin The focus origin.
148+ * @param element Element to focus.
149+ * @param origin Focus origin.
150+ * @param focusOption Options that can be used to configure the focus behavior.
140151 */
141- focusVia ( element : HTMLElement , origin : FocusOrigin ) : void {
152+ focusVia ( element : HTMLElement , origin : FocusOrigin , options ?: FocusOptions ) : void {
142153 this . _setOriginForCurrentEventQueue ( origin ) ;
143154
144155 // `focus` isn't available on the server
145156 if ( typeof element . focus === 'function' ) {
146- element . focus ( ) ;
157+ // Cast the element to `any`, because the TS typings don't have the `options` parameter yet.
158+ ( element as any ) . focus ( options ) ;
147159 }
148160 }
149161
0 commit comments