From 9c85d41c160fa081eb6f59dbc83b7fd3ad271e8c Mon Sep 17 00:00:00 2001 From: Ben Howell Date: Wed, 15 Nov 2023 13:46:42 -0800 Subject: [PATCH 1/2] fix: getLastFocusedProgrammatically returns the element even after the focusin event is processed --- src/FocusEvent.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/FocusEvent.ts b/src/FocusEvent.ts index 45d3fad8c..8751b3a85 100644 --- a/src/FocusEvent.ts +++ b/src/FocusEvent.ts @@ -106,7 +106,8 @@ export function setupFocusEvent(win: Window): void { if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) { details.isFocusedProgrammatically = target === data.lastFocusedProgrammatically?.deref(); - + } + if (!details.isFocusedProgrammatically) { data.lastFocusedProgrammatically = undefined; } @@ -165,7 +166,9 @@ export function disposeFocusEvent(win: Window): void { /** * @param win The window that stores keyborg focus events - * @returns The last element focused with element.focus() + * @returns The last element focused with element.focus(), + * or `null` if focus moved without element.focus(), + * or `undefined` if Keyborg was not initialized on the window. */ export function getLastFocusedProgrammatically( win: Window From bec44cc42545e8aa0d6602648e12ba3b4a02c429 Mon Sep 17 00:00:00 2001 From: Ben Howell <48106640+behowell@users.noreply.github.com> Date: Wed, 15 Nov 2023 23:19:30 -0800 Subject: [PATCH 2/2] Revert comment changes --- src/FocusEvent.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/FocusEvent.ts b/src/FocusEvent.ts index 8751b3a85..583dbb008 100644 --- a/src/FocusEvent.ts +++ b/src/FocusEvent.ts @@ -166,9 +166,7 @@ export function disposeFocusEvent(win: Window): void { /** * @param win The window that stores keyborg focus events - * @returns The last element focused with element.focus(), - * or `null` if focus moved without element.focus(), - * or `undefined` if Keyborg was not initialized on the window. + * @returns The last element focused with element.focus() */ export function getLastFocusedProgrammatically( win: Window