diff --git a/src/Uno.UI.Wasm/WasmScripts/Uno.UI.d.ts b/src/Uno.UI.Wasm/WasmScripts/Uno.UI.d.ts index 1ab574384cf8..cf04cfc8fc9c 100644 --- a/src/Uno.UI.Wasm/WasmScripts/Uno.UI.d.ts +++ b/src/Uno.UI.Wasm/WasmScripts/Uno.UI.d.ts @@ -522,6 +522,7 @@ declare namespace Uno.UI { private removeLoading; private resize; private onfocusin; + private onWindowBlur; private dispatchEvent; private getIsConnectedToRootElement; setCursor(cssCursor: string): string; diff --git a/src/Uno.UI.Wasm/WasmScripts/Uno.UI.js b/src/Uno.UI.Wasm/WasmScripts/Uno.UI.js index 6cd9218f151e..6840a5b91878 100644 --- a/src/Uno.UI.Wasm/WasmScripts/Uno.UI.js +++ b/src/Uno.UI.Wasm/WasmScripts/Uno.UI.js @@ -1548,6 +1548,7 @@ var Uno; x.preventDefault(); } }); + window.addEventListener("blur", this.onWindowBlur); } removeLoading() { if (!this.loadingElementId) { @@ -1580,6 +1581,15 @@ var Uno; WindowManager.focusInMethod(htmlId); } } + onWindowBlur() { + if (WindowManager.isHosted) { + console.warn("Focus not supported in hosted mode"); + } + else { + // Unset managed focus when Window loses focus + WindowManager.focusInMethod(-1); + } + } dispatchEvent(element, eventName, eventPayload = null) { const htmlId = Number(element.getAttribute("XamlHandle")); // console.debug(`${element.getAttribute("id")}: Raising event ${eventName}.`); diff --git a/src/Uno.UI.Wasm/ts/WindowManager.ts b/src/Uno.UI.Wasm/ts/WindowManager.ts index ec9372ac32b7..f0a9d64b7d6e 100644 --- a/src/Uno.UI.Wasm/ts/WindowManager.ts +++ b/src/Uno.UI.Wasm/ts/WindowManager.ts @@ -1612,6 +1612,7 @@ x.preventDefault(); } }) + window.addEventListener("blur", this.onWindowBlur); } private removeLoading() { @@ -1652,6 +1653,16 @@ } } + private onWindowBlur() { + if (WindowManager.isHosted) { + console.warn("Focus not supported in hosted mode"); + } + else { + // Unset managed focus when Window loses focus + WindowManager.focusInMethod(-1); + } + } + private dispatchEvent(element: HTMLElement | SVGElement, eventName: string, eventPayload: string = null): boolean { const htmlId = Number(element.getAttribute("XamlHandle"));