@@ -14,20 +14,11 @@ function triggerFocusChange(element: HTMLElement, event: 'focus' | 'blur') {
14
14
element . addEventListener ( event , handler ) ;
15
15
element [ event ] ( ) ;
16
16
element . removeEventListener ( event , handler ) ;
17
-
18
- // Some browsers won't move focus if the browser window is blurred while other will move it
19
- // asynchronously. If that is the case, we fake the event sequence as a fallback.
20
17
if ( ! eventFired ) {
21
- simulateFocusSequence ( element , event ) ;
18
+ dispatchFakeEvent ( element , event ) ;
22
19
}
23
20
}
24
21
25
- /** Simulates the full event sequence for a focus event. */
26
- function simulateFocusSequence ( element : HTMLElement , event : 'focus' | 'blur' ) {
27
- dispatchFakeEvent ( element , event ) ;
28
- dispatchFakeEvent ( element , event === 'focus' ? 'focusin' : 'focusout' ) ;
29
- }
30
-
31
22
/**
32
23
* Patches an elements focus and blur methods to emit events consistently and predictably.
33
24
* This is necessary, because some browsers can call the focus handlers asynchronously,
@@ -37,8 +28,8 @@ function simulateFocusSequence(element: HTMLElement, event: 'focus' | 'blur') {
37
28
// TODO: Check if this element focus patching is still needed for local testing,
38
29
// where browser is not necessarily focused.
39
30
export function patchElementFocus ( element : HTMLElement ) {
40
- element . focus = ( ) => simulateFocusSequence ( element , 'focus' ) ;
41
- element . blur = ( ) => simulateFocusSequence ( element , 'blur' ) ;
31
+ element . focus = ( ) => dispatchFakeEvent ( element , 'focus' ) ;
32
+ element . blur = ( ) => dispatchFakeEvent ( element , 'blur' ) ;
42
33
}
43
34
44
35
/** @docs -private */
0 commit comments