@@ -29,6 +29,16 @@ export const TOUCH_BUFFER_MS = 650;
29
29
export type FocusOrigin = 'touch' | 'mouse' | 'keyboard' | 'program' | null ;
30
30
31
31
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
+
32
42
type MonitoredElementInfo = {
33
43
unlisten : Function ,
34
44
checkChildren : boolean ,
@@ -135,15 +145,17 @@ export class FocusMonitor implements OnDestroy {
135
145
136
146
/**
137
147
* 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.
140
151
*/
141
- focusVia ( element : HTMLElement , origin : FocusOrigin ) : void {
152
+ focusVia ( element : HTMLElement , origin : FocusOrigin , options ?: FocusOptions ) : void {
142
153
this . _setOriginForCurrentEventQueue ( origin ) ;
143
154
144
155
// `focus` isn't available on the server
145
156
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 ) ;
147
159
}
148
160
}
149
161
0 commit comments