diff --git a/src/cdk/testing/testbed/fake-events/element-focus.ts b/src/cdk/testing/testbed/fake-events/element-focus.ts index f0318d4358b3..6b71c252f3c7 100644 --- a/src/cdk/testing/testbed/fake-events/element-focus.ts +++ b/src/cdk/testing/testbed/fake-events/element-focus.ts @@ -14,20 +14,11 @@ function triggerFocusChange(element: HTMLElement, event: 'focus' | 'blur') { element.addEventListener(event, handler); element[event](); element.removeEventListener(event, handler); - - // Some browsers won't move focus if the browser window is blurred while other will move it - // asynchronously. If that is the case, we fake the event sequence as a fallback. if (!eventFired) { - simulateFocusSequence(element, event); + dispatchFakeEvent(element, event); } } -/** Simulates the full event sequence for a focus event. */ -function simulateFocusSequence(element: HTMLElement, event: 'focus' | 'blur') { - dispatchFakeEvent(element, event); - dispatchFakeEvent(element, event === 'focus' ? 'focusin' : 'focusout'); -} - /** * Patches an elements focus and blur methods to emit events consistently and predictably. * This is necessary, because some browsers can call the focus handlers asynchronously, @@ -37,8 +28,8 @@ function simulateFocusSequence(element: HTMLElement, event: 'focus' | 'blur') { // TODO: Check if this element focus patching is still needed for local testing, // where browser is not necessarily focused. export function patchElementFocus(element: HTMLElement) { - element.focus = () => simulateFocusSequence(element, 'focus'); - element.blur = () => simulateFocusSequence(element, 'blur'); + element.focus = () => dispatchFakeEvent(element, 'focus'); + element.blur = () => dispatchFakeEvent(element, 'blur'); } /** @docs-private */