Skip to content

Commit

Permalink
feat(focus): [WASM] Update FocusManager when browser window loses focus
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjohnoliver committed Mar 31, 2020
1 parent cc73d46 commit 3a61248
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Uno.UI.Wasm/WasmScripts/Uno.UI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ declare namespace Uno.UI {
private removeLoading;
private resize;
private onfocusin;
private onWindowBlur;
private dispatchEvent;
private getIsConnectedToRootElement;
setCursor(cssCursor: string): string;
Expand Down
10 changes: 10 additions & 0 deletions src/Uno.UI.Wasm/WasmScripts/Uno.UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ var Uno;
x.preventDefault();
}
});
window.addEventListener("blur", this.onWindowBlur);
}
removeLoading() {
if (!this.loadingElementId) {
Expand Down Expand Up @@ -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}.`);
Expand Down
11 changes: 11 additions & 0 deletions src/Uno.UI.Wasm/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,7 @@
x.preventDefault();
}
})
window.addEventListener("blur", this.onWindowBlur);
}

private removeLoading() {
Expand Down Expand Up @@ -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"));

Expand Down

0 comments on commit 3a61248

Please sign in to comment.