Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): keep composer placeholders readable in narrow panes
chengyongru7ea2c9a830b9
diff --git a/webui/browser/composer-action-fixture.tsx b/webui/browser/composer-action-fixture.tsxindex 00411c556..bf6b5278d 100644--- a/webui/browser/composer-action-fixture.tsx+++ b/webui/browser/composer-action-fixture.tsx@@ -7,6 +7,7 @@ export function ComposerActionFixture({ parameters }: { parameters: URLSearchParreturn <main className="mx-auto w-full max-w-5xl px-4 pt-24"><ThreadComposervariant={parameters.get("composerVariant") === "thread" ? "thread" : "hero"}+ placeholder={parameters.has("opening") ? "Opening a new topic…" : undefined}modelLabel="Preview"goalState={parameters.has("goal") ? { active: true, objective: "Keep the work in focus." } : undefined}isStreaming={running}diff --git a/webui/browser/composer-action.spec.ts b/webui/browser/composer-action.spec.tsindex d6fbec54d..8926afb40 100644--- a/webui/browser/composer-action.spec.ts+++ b/webui/browser/composer-action.spec.ts@@ -149,7 +149,7 @@ test("idle voice and ready send remain distinct from the composer in both themes});-test("a long mobile placeholder remains available without shifting the composer", async ({ browser, baseURL }) => {+test("a compact mobile placeholder keeps the full hint available without shifting the composer", async ({ browser, baseURL }) => {const context = await browser.newContext({ baseURL, viewport: { width: 314, height: 844 }, hasTouch: true, isMobile: true, reducedMotion: "reduce" });try {const page = await context.newPage();@@ -158,9 +158,10 @@ test("a long mobile placeholder remains available without shifting the composer"await page.evaluate(() => document.fonts.ready);const input = page.locator(".thread-composer-input textarea");const action = page.locator(".composer-primary-action");- await expect(input).toHaveAttribute("placeholder", /compétences/);- const placeholder = (await input.getAttribute("placeholder"))!;- await expect(input).toHaveAttribute("aria-description", placeholder);+ await expect(input).toHaveAttribute("placeholder", "Votre message…");+ await expect.poll(() => input.evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true);+ const placeholder = (await input.getAttribute("aria-description"))!;+ expect(placeholder).toContain("compétences");await expect(page.getByRole("tooltip")).toHaveCount(0);const before = (await action.boundingBox())!;const initialHeight = await input.evaluate(node => node.clientHeight);@@ -200,3 +201,34 @@ test("a long mobile placeholder remains available without shifting the composer"await context.close();}});++for (const variant of ["hero", "thread"]) {+ test(`placeholder follows available input width in a ${variant} composer`, async ({ page }) => {+ await page.setViewportSize({ width: 1200, height: 900 });+ await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));+ await page.goto(`/browser/fixture.html?case=composer-action&composerVariant=${variant}`);+ await page.evaluate(() => document.fonts.ready);+ const container = page.locator("main");+ const input = page.locator(".thread-composer-input textarea");+ const fullHint = "Type / for commands, @ for chats or apps, $ for skills";+ await expect(input).toHaveAttribute("placeholder", fullHint);++ await container.evaluate(node => { node.style.maxWidth = "340px"; });+ await expect(input).toHaveAttribute("placeholder", "Type a message…");+ await expect(input).toHaveAttribute("aria-description", fullHint);+ await expect.poll(() => input.evaluate(node => node.scrollWidth <= node.clientWidth)).toBe(true);++ await input.fill("Keep this draft");+ await container.evaluate(node => { node.style.maxWidth = "600px"; });+ await expect(input).toHaveAttribute("placeholder", fullHint);+ await container.evaluate(node => { node.style.setProperty("--text-reading-size", "28px"); });+ await expect(input).toHaveAttribute("placeholder", "Type a message…");+ await container.evaluate(node => { node.style.maxWidth = "900px"; });+ await expect(input).toHaveAttribute("placeholder", fullHint);+ await expect(input).toHaveValue("Keep this draft");++ await page.goto(`/browser/fixture.html?case=composer-action&composerVariant=${variant}&opening`);+ await page.locator("main").evaluate(node => { node.style.maxWidth = "340px"; });+ await expect(input).toHaveAttribute("placeholder", "Opening a new topic…");+ });+}diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsxindex fef7614a7..85e487397 100644--- a/webui/src/components/thread/ThreadComposer.tsx+++ b/webui/src/components/thread/ThreadComposer.tsx@@ -1129,6 +1129,7 @@ export function ThreadComposer({const [initialDraft] = useState(() => draftKey ? draftStore?.get(draftKey, persistDraft) : undefined);const [value, setValue] = useState(initialDraft?.text ?? "");const [composerFocused, setComposerFocused] = useState(false);+ const [compactPlaceholder, setCompactPlaceholder] = useState(false);const [placeholderHintRequested, setPlaceholderHintRequested] = useState(false);const [placeholderHintOpen, setPlaceholderHintOpen] = useState(false);const [placeholderHintBottomGap, setPlaceholderHintBottomGap] = useState(0);@@ -1175,6 +1176,7 @@ export function ThreadComposer({const mobileWorkspaceControls = useMediaQuery("(max-width: 639px)");const { readingTextSize, customReadingTextSize } = useLocalPreferences();const textareaRef = useRef<HTMLTextAreaElement>(null);+ const placeholderMeasureRef = useRef<HTMLSpanElement>(null);const mentionOverlayRef = useRef<HTMLDivElement>(null);const formRef = useRef<HTMLFormElement>(null);const tabFocusRequested = useRef(false);@@ -1244,6 +1246,31 @@ export function ThreadComposer({}, [activeTurnId, isStreaming, pendingQueueKey, setQueuedPrompt]);const resolvedPlaceholder = placeholder ?? t("thread.composer.placeholder");+ const showCompactPlaceholder = placeholder === undefined && compactPlaceholder;+ const displayedPlaceholder = showCompactPlaceholder ? t("thread.composer.placeholderCompact") : resolvedPlaceholder;++ useLayoutEffect(() => {+ const input = textareaRef.current;+ const text = placeholderMeasureRef.current;+ if (!input || !text || placeholder !== undefined) return;+ const measure = () => {+ const style = getComputedStyle(input);+ const available = input.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);+ if (available > 0) setCompactPlaceholder(text.getBoundingClientRect().width > available);+ };+ measure();+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);+ observer?.observe(input);+ observer?.observe(text);+ window.addEventListener("resize", measure);+ let active = true;+ void document.fonts?.ready.then(() => { if (active) measure(); });+ return () => {+ active = false;+ observer?.disconnect();+ window.removeEventListener("resize", measure);+ };+ }, [placeholder, resolvedPlaceholder, compactControls, readingTextSize, customReadingTextSize]);const maxAttachments = ingressLimits?.attachments.max_count?? MAX_ATTACHMENTS_PER_MESSAGE;@@ -1888,7 +1915,7 @@ export function ThreadComposer({}const form = formRef.current!;const measure = () => {- setPlaceholderHintOpen(input.scrollWidth > input.clientWidth);+ setPlaceholderHintOpen(showCompactPlaceholder || input.scrollWidth > input.clientWidth);setPlaceholderHintBottomGap(form.getBoundingClientRect().bottom - input.getBoundingClientRect().bottom);};measure();@@ -1898,7 +1925,7 @@ export function ThreadComposer({let active = true;void document.fonts?.ready.then(() => { if (active) measure(); });return () => { active = false; observer?.disconnect(); };- }, [placeholderHintRequested, mentionInput.value, resolvedPlaceholder, sessionDragPreview, readingTextSize, customReadingTextSize]);+ }, [placeholderHintRequested, mentionInput.value, resolvedPlaceholder, showCompactPlaceholder, sessionDragPreview, readingTextSize, customReadingTextSize]);// Runs before paint so switching sessions never flashes stale draft text.useLayoutEffect(() => {@@ -2773,6 +2800,11 @@ export function ThreadComposer({) : null}<GoalStateStrip goalState={goalState} /><div className="thread-composer-input relative min-w-0">+ {placeholder === undefined ? (+ <span className="pointer-events-none invisible absolute h-0 w-0 overflow-hidden">+ <span ref={placeholderMeasureRef} aria-hidden className="inline-block whitespace-pre text-composer [text-autospace:no-autospace]">{resolvedPlaceholder}</span>+ </span>+ ) : null}{hasInlineDecorations ? (<ComposerInlineReferenceOverlayoverlayRef={mentionOverlayRef}@@ -2821,7 +2853,7 @@ export function ThreadComposer({onPaste={onPaste}rows={1}enterKeyHint={hasCoarsePointer ? "enter" : undefined}- placeholder={sessionDragPreview ? "" : resolvedPlaceholder}+ placeholder={sessionDragPreview ? "" : displayedPlaceholder}disabled={interactionDisabled}aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}aria-description={sessionDragPreview ? undefined : resolvedPlaceholder}diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.jsonindex 1ff48a661..04413ee66 100644--- a/webui/src/i18n/locales/en/common.json+++ b/webui/src/i18n/locales/en/common.json@@ -2093,6 +2093,7 @@},"composer": {"placeholder": "Type / for commands, @ for chats or apps, $ for skills",+ "placeholderCompact": "Type a message…","placeholderOpening": "Opening a new topic…","inputAria": "Message input","goalStateStrip": "Goal: {{label}}",diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.jsonindex 82fe11ffb..8940bc52a 100644--- a/webui/src/i18n/locales/es/common.json+++ b/webui/src/i18n/locales/es/common.json@@ -1888,6 +1888,7 @@},"composer": {"placeholder": "Escribe / para ver comandos, @ para mencionar conversaciones o aplicaciones y $ para elegir habilidades",+ "placeholderCompact": "Escribe un mensaje…","placeholderOpening": "Abriendo un nuevo tema…","inputAria": "Entrada de mensaje","goalStateStrip": "Objetivo: {{label}}",diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.jsonindex c5d008ee8..11bc84a69 100644--- a/webui/src/i18n/locales/fr/common.json+++ b/webui/src/i18n/locales/fr/common.json@@ -1887,6 +1887,7 @@},"composer": {"placeholder": "Tapez / pour voir les commandes, @ pour les conversations ou les applis, $ pour les compétences",+ "placeholderCompact": "Votre message…","placeholderOpening": "Ouverture d’un nouveau sujet…","inputAria": "Champ de message","goalStateStrip": "Objectif: {{label}}",diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.jsonindex ca902d92a..483f7721f 100644--- a/webui/src/i18n/locales/id/common.json+++ b/webui/src/i18n/locales/id/common.json@@ -1887,6 +1887,7 @@},"composer": {"placeholder": "Ketik / untuk melihat perintah, @ untuk memilih percakapan atau aplikasi, $ untuk memilih keterampilan",+ "placeholderCompact": "Ketik pesan…","placeholderOpening": "Membuka topik baru…","inputAria": "Input pesan","goalStateStrip": "Tujuan: {{label}}",diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.jsonindex b9f8bae2c..cefc7c792 100644--- a/webui/src/i18n/locales/ja/common.json+++ b/webui/src/i18n/locales/ja/common.json@@ -1887,6 +1887,7 @@},"composer": {"placeholder": "/ でコマンド、@ で会話やアプリ、$ でスキルを選択",+ "placeholderCompact": "メッセージを入力…","placeholderOpening": "新しいトピックを開いています…","inputAria": "メッセージ入力欄","goalStateStrip": "目標: {{label}}",diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.jsonindex 2fa27da9c..9b97b3e3b 100644--- a/webui/src/i18n/locales/ko/common.json+++ b/webui/src/i18n/locales/ko/common.json@@ -1887,6 +1887,7 @@},"composer": {"placeholder": "/로 명령어 보기, @로 대화나 앱 선택, $로 스킬 선택",+ "placeholderCompact": "메시지 입력…","placeholderOpening": "새 주제를 여는 중…","inputAria": "메시지 입력","goalStateStrip": "목표: {{label}}",diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.jsonindex 451e95a25..ceaf718fa 100644--- a/webui/src/i18n/locales/pt-BR/common.json+++ b/webui/src/i18n/locales/pt-BR/common.json@@ -1901,6 +1901,7 @@},"composer": {"placeholder": "Digite / para ver comandos, @ para mencionar conversas ou aplicativos e $ para escolher habilidades",+ "placeholderCompact": "Digite uma mensagem…","placeholderOpening": "Abrindo um novo tópico…","inputAria": "Campo de mensagem","goalStateStrip": "Objetivo: {{label}}",diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.jsonindex 4bebbfbdd..8ddef23d5 100644--- a/webui/src/i18n/locales/vi/common.json+++ b/webui/src/i18n/locales/vi/common.json@@ -1887,6 +1887,7 @@},"composer": {"placeholder": "Nhập / để xem lệnh, @ để chọn cuộc trò chuyện hoặc ứng dụng, $ để chọn kỹ năng",+ "placeholderCompact": "Nhập tin nhắn…","placeholderOpening": "Đang mở chủ đề mới…","inputAria": "Ô nhập tin nhắn","goalStateStrip": "Mục tiêu: {{label}}",diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.jsonindex 7921ac59f..f8f82fdea 100644--- a/webui/src/i18n/locales/zh-CN/common.json+++ b/webui/src/i18n/locales/zh-CN/common.json@@ -2093,6 +2093,7 @@},"composer": {"placeholder": "输入 / 查看命令,@ 引用会话或应用,$ 选择技能",+ "placeholderCompact": "输入消息…","placeholderOpening": "正在打开新话题…","inputAria": "消息输入框","goalStateStrip": "目标:{{label}}",diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.jsonindex 58879940b..7bbc581ac 100644--- a/webui/src/i18n/locales/zh-TW/common.json+++ b/webui/src/i18n/locales/zh-TW/common.json@@ -1887,6 +1887,7 @@},"composer": {"placeholder": "輸入 / 查看命令,@ 引用對話或應用程式,$ 選擇技能",+ "placeholderCompact": "輸入訊息…","placeholderOpening": "正在開啟新話題…","inputAria": "訊息輸入框","goalStateStrip": "目標:{{label}}",