Chat: the message box stops at 30% of the window height and scrolls inside, so Send and the toolbar stay in view in a small window

This commit is contained in:
Niko1221 committed 2026-10-18 20:49:29 +02:00
1 parent e0aa3b872a
commit 95ece0bcd2
4 files changed
+26 -6

No files matched your search

+5
View File
@@ -16,3 +16,8 @@ export function scrollBehavior(): ScrollBehavior {
const override = document.documentElement.dataset.motion;
return override === 'reduced' || (override !== 'full' && window.matchMedia('(prefers-reduced-motion: reduce)').matches) ? 'instant' : 'smooth';
}
/** The tallest the message box may grow: 30% of the window, between 44 and 180 pixels (the rest of the window keeps the toolbar and Send in view). */
export function composerCap(windowHeight: number): number {
return Math.max(44, Math.min(180, Math.floor(windowHeight * 0.3)));
}
+12 -6
View File
@@ -33,7 +33,7 @@ import { artifactFromUrl, type PreviewArtifact } from '../lib/artifacts';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Markdown } from '../components/Markdown';
import { Btn, Icon, IconBtn, ErrorNotice, type IconName } from '../components/ui';
import { scrollBehavior } from '../lib/responsive';
import { composerCap, scrollBehavior } from '../lib/responsive';
import { relTime, cx, duration, tokens, tps } from '../lib/format';
import { createSubagentExample, pushToast, setPreviewTabClosed, branchFrom, continueLast, markRead, resolveTool, retryLast, selectSession, rewindTo, sendMessage, stopStreaming, useStore, } from '../lib/store';
import { getSlashCommands } from '../lib/commands';
@@ -265,12 +265,18 @@ export function ChatScreen() {
// would fight the follow-the-stream effect above.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session?.id]);
// The box grows with the draft but never past 30% of the window, and scrolls inside after that, so Send and the toolbar stay on screen (QA F08).
useEffect(() => {
const el = textarea.current;
if (!el)
return;
el.style.height = 'auto';
el.style.height = `${Math.min(200, el.scrollHeight)}px`;
const fit = () => {
const el = textarea.current;
if (!el)
return;
el.style.height = 'auto';
el.style.height = `${Math.min(composerCap(window.innerHeight), el.scrollHeight)}px`;
};
fit();
window.addEventListener('resize', fit);
return () => window.removeEventListener('resize', fit);
}, [draft]);
/** Hands a rewound prompt back to the composer so it can be changed. */
function editPrompt(text: string) {
@@ -57,6 +57,7 @@ input:focus, textarea:focus, [contenteditable]:focus { outline: none; box-shadow
.sampling-field p { margin: 1px 0 0; }
#response-panel-sampling > .stack { gap: 12px; }
.sampling-number-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.composer .st-composer textarea { max-height: clamp(44px, 30dvh, 180px); overflow-y: auto; }
.field-problem { color: var(--st-danger-text); font-size: var(--st-fs-sm); }
.input-field input[aria-invalid="true"] { border-color: var(--st-danger); }
.response-projection { display: flex; align-items: center; gap: 20px; }
@@ -49,3 +49,11 @@ test('F07: a page opened from another computer says why Add skill cannot work in
assert.match(skills, /pageIsOnThisComputer\(window\.location\.hostname\)/);
void pick;
});
test('F08: the message box stops at 30% of the window height (44 to 180 px) and scrolls inside', async () => {
const { composerCap } = await loadTs('../src/lib/responsive.ts');
assert.equal(composerCap(400), 120); assert.equal(composerCap(500), 150); assert.equal(composerCap(720), 180); assert.equal(composerCap(2000), 180); assert.equal(composerCap(100), 44);
const css = await readFile(new URL('../src/styles/annotation-fixes.css', import.meta.url), 'utf8');
assert.match(css, /\.composer \.st-composer textarea \{ max-height: clamp\(44px, 30dvh, 180px\); overflow-y: auto; \}/);
assert.match(await readFile(new URL('../src/screens/Chat.tsx', import.meta.url), 'utf8'), /composerCap\(window\.innerHeight\)/);
});