From 3c7387f6842eb20cc1e3d8191ae35c2963cb279b Mon Sep 17 00:00:00 2001 From: weishu Date: Wed, 17 Dec 2025 21:21:04 +0800 Subject: [PATCH] feat: add viewport height tracking and improve scroll behavior on mobile --- web/src/components/ChatInput.tsx | 16 ++++++++++++-- web/src/components/SessionChat.tsx | 34 ++++++++++++++++-------------- web/src/index.css | 5 ++++- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/web/src/components/ChatInput.tsx b/web/src/components/ChatInput.tsx index d6c8fa4f..abea3c36 100644 --- a/web/src/components/ChatInput.tsx +++ b/web/src/components/ChatInput.tsx @@ -196,7 +196,15 @@ export const ChatInput = memo(forwardRef(functi // Imperative handle useImperativeHandle(ref, () => ({ - focus: () => textareaRef.current?.focus(), + focus: () => { + const el = textareaRef.current + if (!el) return + try { + el.focus({ preventScroll: true }) + } catch { + el.focus() + } + }, blur: () => textareaRef.current?.blur() }), []) @@ -257,7 +265,11 @@ export const ChatInput = memo(forwardRef(functi setTimeout(() => { if (textareaRef.current) { textareaRef.current.setSelectionRange(result.cursorPosition, result.cursorPosition) - textareaRef.current.focus() + try { + textareaRef.current.focus({ preventScroll: true }) + } catch { + textareaRef.current.focus() + } } }, 0) diff --git a/web/src/components/SessionChat.tsx b/web/src/components/SessionChat.tsx index 45b1bf38..05a77981 100644 --- a/web/src/components/SessionChat.tsx +++ b/web/src/components/SessionChat.tsx @@ -106,7 +106,7 @@ export function SessionChat(props: { ) : null} -
+
{props.messagesWarning ? (
@@ -183,22 +183,24 @@ export function SessionChat(props: { )}
-
- +
+ +
+
) } diff --git a/web/src/index.css b/web/src/index.css index a15d4ce4..79c53362 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -66,7 +66,10 @@ html, body { - height: 100%; + height: 100vh; + height: 100dvh; + height: var(--tg-viewport-stable-height, 100dvh); + overflow: hidden; touch-action: pan-x pan-y; overscroll-behavior: none; -webkit-text-size-adjust: 100%;