Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): the device screen keeps focus when typing or returning to the window #14534

Mergedhaydenkz(GitHub profile, opens in a new tab)merged 10 commits intomain fromrefs/pull/14534/headmerged by juliusmarminge View on GitHub

Showing 4 changed files with 45 additions and 0 deletions (loading 1).

x
0 of 4 viewed, 4 left
38 additions and 0 deletionsapps/web/src/components/chat/composerFocusRedirect.browser.test.tsAdded
View file
@@ -0,0 +1,38 @@
+import { afterEach, describe, expect, it } from "vite-plus/test";
+​
+import { shouldTypeToFocusComposer } from "./composerFocusRedirect";
+​
+// composedPath() is only populated while the event is dispatching, so decide
+// inside a window capture listener the way the chat view does.
+function typeOn(target: Element, key: string): boolean {
+ let redirected = false;
+ const listener = (event: KeyboardEvent) => {
+ redirected = shouldTypeToFocusComposer(event);
+ };
+ window.addEventListener("keydown", listener, { capture: true });
+ target.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, composed: true }));
+ window.removeEventListener("keydown", listener, { capture: true });
+ return redirected;
+}
+​
+afterEach(() => {
+ document.body.replaceChildren();
+});
+​
+describe("shouldTypeToFocusComposer", () => {
+ it("sends letters typed on the chat to the composer", () => {
+ const chat = document.createElement("div");
+ document.body.append(chat);
+​
+ expect(typeOn(chat, "a")).toBe(true);
+ });
+​
+ it("keeps letters typed on the device screen on the device", () => {