Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): reliable mobile keyboard offset and backdrop for chat input (#281)

Gener03101faf79f3
diff --git a/src/cli/eslint.config.mjs b/src/cli/eslint.config.mjs
index 50a7cedfc..e1bad3c11 100644
--- a/src/cli/eslint.config.mjs
+++ b/src/cli/eslint.config.mjs
@@ -3,7 +3,7 @@ import tseslint from "typescript-eslint";
const eslintConfig = defineConfig([
...tseslint.configs.recommended,
- globalIgnores(["dist/**"]),
+ globalIgnores(["dist/**", "coverage/**"]),
{
files: ["**/*.test.ts"],
rules: {
diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.css
index f28c001e6..3b6af0cc6 100644
--- a/src/web/src/app/globals.css
+++ b/src/web/src/app/globals.css
@@ -1726,6 +1726,15 @@ html, body {
will-change: transform;
}
+[data-keyboard-offset][data-keyboard-active]::before {
+ content: "";
+ position: absolute;
+ inset: 0;
+ bottom: -100vh;
+ background: var(--background);
+ z-index: -1;
+}
+
html, body {
background-color: oklch(0.93 0.015 80);
min-height: 100dvh;
diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsx
index e19cfdd2b..632af7474 100644
--- a/src/web/src/components/agent-chat/agent-chat-view.tsx
+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx
@@ -2060,6 +2060,7 @@ export function AgentChatView({
toast.error(msg.error || "Failed to dispatch follow-up");
}
});
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- activeChannelRef is a stable ref read inside the callback, not a reactive dep
}, [subscribeWs, conversation?.id, workspaceId, agentId]);
useEffect(() => {
diff --git a/src/web/src/components/agent-chat/chat-composer.tsx b/src/web/src/components/agent-chat/chat-composer.tsx
index 3fd6e51e6..c75b005fe 100644
--- a/src/web/src/components/agent-chat/chat-composer.tsx
+++ b/src/web/src/components/agent-chat/chat-composer.tsx
@@ -153,6 +153,7 @@ export const ChatComposer = forwardRef<ChatComposerHandle, ChatComposerProps>(
},
ref,
) {
+ const [editorFocused, setEditorFocused] = useState(false);
const [mentionPopup, setMentionPopup] = useState<MentionPopupState>(EMPTY_MENTION_STATE);
const mentionPopupRef = useRef(mentionPopup);
useEffect(() => {
@@ -353,6 +354,8 @@ export const ChatComposer = forwardRef<ChatComposerHandle, ChatComposerProps>(
},
handleDrop: () => false,
},
+ onFocus: () => setEditorFocused(true),
+ onBlur: () => setEditorFocused(false),
onUpdate: ({ editor }) => {
onChangeRef.current(decodeChatEntities(editor.getMarkdown()));
reportState(editor);
@@ -401,7 +404,7 @@ export const ChatComposer = forwardRef<ChatComposerHandle, ChatComposerProps>(
// iOS Safari fallback: scroll composer into view when the virtual keyboard resizes
// the visual viewport.
- useKeyboardScroll(contentRef, !!editor?.isFocused);
+ useKeyboardScroll(contentRef, editorFocused);
useImperativeHandle(
ref,
diff --git a/src/web/src/hooks/__tests__/use-keyboard-scroll.test.ts b/src/web/src/hooks/__tests__/use-keyboard-scroll.test.ts
index 960952105..317e16ddd 100644
--- a/src/web/src/hooks/__tests__/use-keyboard-scroll.test.ts
+++ b/src/web/src/hooks/__tests__/use-keyboard-scroll.test.ts
@@ -20,6 +20,8 @@ function createMockContainer(bottom = 800) {
return {
style: { transform: "" },
getBoundingClientRect: () => ({ top: 0, left: 0, right: 0, bottom, width: 0, height: 0 }),
+ setAttribute: vi.fn(),
+ removeAttribute: vi.fn(),
} as unknown as HTMLElement;
}
diff --git a/src/web/src/hooks/use-keyboard-scroll.ts b/src/web/src/hooks/use-keyboard-scroll.ts
index 461ae496c..f006b5ba3 100644
--- a/src/web/src/hooks/use-keyboard-scroll.ts
+++ b/src/web/src/hooks/use-keyboard-scroll.ts
@@ -2,6 +2,11 @@
import { useEffect, type RefObject } from "react";
+interface VirtualKeyboard extends EventTarget {
+ overlaysContent: boolean;
+ boundingRect: DOMRect;
+}
+
export interface KeyboardScrollController {
handler: () => void;
cleanup: () => void;
@@ -39,10 +44,16 @@ export function createKeyboardScrollController(
// Only shift enough to keep it visible, not the full keyboard height.
const rect = inputContainer.getBoundingClientRect();
const overflow = rect.bottom - vv.height - vv.offsetTop;
- inputContainer.style.transform =
- overflow > 0 ? `translateY(-${overflow}px)` : "";
+ if (overflow > 0) {
+ inputContainer.style.transform = `translateY(-${overflow}px)`;
+ inputContainer.setAttribute("data-keyboard-active", "");
+ } else {
+ inputContainer.style.transform = "";
+ inputContainer.removeAttribute("data-keyboard-active");
+ }
} else if (inputContainer) {
inputContainer.style.transform = "";
+ inputContainer.removeAttribute("data-keyboard-active");
} else {
el.scrollIntoView({ block: "end", behavior: "smooth" });
}
@@ -57,6 +68,7 @@ export function createKeyboardScrollController(
) as HTMLElement | null;
if (inputContainer) {
inputContainer.style.transform = "";
+ inputContainer.removeAttribute("data-keyboard-active");
}
};
return { handler, cleanup };
@@ -101,7 +113,7 @@ function attachVirtualKeyboardAPI(
isFocused: boolean,
): (() => void) | null {
if (typeof window === "undefined") return null;
- const vk = (navigator as any).virtualKeyboard;
+ const vk = (navigator as unknown as { virtualKeyboard?: VirtualKeyboard }).virtualKeyboard;
if (!vk) return null;
vk.overlaysContent = true;
@@ -114,17 +126,24 @@ function attachVirtualKeyboardAPI(
const onGeometryChange = () => {
if (!isFocused) {
inputContainer.style.transform = "";
+ inputContainer.removeAttribute("data-keyboard-active");
return;
}
const { height } = vk.boundingRect;
- inputContainer.style.transform =
- height > 0 ? `translateY(-${height}px)` : "";
+ if (height > 0) {
+ inputContainer.style.transform = `translateY(-${height}px)`;
+ inputContainer.setAttribute("data-keyboard-active", "");
+ } else {
+ inputContainer.style.transform = "";
+ inputContainer.removeAttribute("data-keyboard-active");
+ }
};
vk.addEventListener("geometrychange", onGeometryChange);
return () => {
vk.removeEventListener("geometrychange", onGeometryChange);
inputContainer.style.transform = "";
+ inputContainer.removeAttribute("data-keyboard-active");
vk.overlaysContent = false;
};
}