From 64749a760dd07c345273aa8f0b045d686c24c199 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:52:08 -0500 Subject: [PATCH] One composer row with the Send, Stop and microphone slot --- .../message/PromptInput.composer.test.tsx | 103 ++++++++++++------ .../message/PromptInput.stt.test.tsx | 2 +- .../src/components/message/PromptInput.tsx | 87 +++++++-------- frontend/src/test/promptInput.tsx | 4 +- 4 files changed, 117 insertions(+), 79 deletions(-) diff --git a/frontend/src/components/message/PromptInput.composer.test.tsx b/frontend/src/components/message/PromptInput.composer.test.tsx index 366e8513..224437f7 100644 --- a/frontend/src/components/message/PromptInput.composer.test.tsx +++ b/frontend/src/components/message/PromptInput.composer.test.tsx @@ -1,12 +1,13 @@ import { describe, expect, it } from 'vitest' -import { act, fireEvent, screen, waitFor } from '@testing-library/react' +import { act, fireEvent, screen, waitFor, within } from '@testing-library/react' import { useSessionStatus } from '@/stores/sessionStatusStore' import { connectTestEventStream } from '@/test/render' import { promptTextarea, renderPromptInput } from '@/test/promptInput' import type { SessionMessageAssistant } from '@opencode-manager/shared/opencode' const submitButton = () => document.querySelector('[data-submit-prompt]') -const controlsRow = () => screen.getByTestId('composer-controls-row') +const inputRow = () => screen.getByTestId('composer-input-row') +const keysRow = () => screen.queryByTestId('composer-keys-row') const voiceMicButton = () => screen.queryByRole('button', { name: 'Start voice conversation' }) const keyButtons = () => screen.queryAllByRole('toolbar', { name: 'Insert' }) @@ -23,15 +24,30 @@ function assistantUsageMessage(tokens: SessionMessageAssistant['tokens']): Sessi } describe('PromptInput composer layout', () => { - it('anchors the activity bar in the gap above the controls row', async () => { + it('anchors the activity bar in the gap above the input row', async () => { useSessionStatus.getState().setStatus('test-session', { type: 'busy' }) await renderPromptInput() const bar = await screen.findByRole('progressbar', { name: 'Session working' }) - expect(controlsRow()).toContainElement(bar) - expect(controlsRow().firstElementChild).toBe(bar) + expect(inputRow()).toContainElement(bar) + expect(inputRow().firstElementChild).toBe(bar) expect(bar).toHaveClass('absolute', 'bottom-full') - expect(promptTextarea().compareDocumentPosition(bar) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy() + expect(bar.compareDocumentPosition(promptTextarea()) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy() + }) + + it('holds only the config trigger, the input and the action buttons in the input row', async () => { + await renderPromptInput() + + fireEvent.change(await screen.findByPlaceholderText('Send a message...'), { target: { value: 'hello' } }) + + const config = screen.getByRole('button', { name: /^Session config:/ }) + expect(within(inputRow()).getAllByRole('button')).toEqual([config, submitButton()]) + expect(promptTextarea().previousElementSibling).toBe(config) + expect(screen.queryByRole('button', { name: /^Agent:/ })).toBeNull() + expect(screen.queryByRole('button', { name: /permission/i })).toBeNull() + expect(screen.queryByRole('button', { name: /goal/i })).toBeNull() + expect(screen.queryByRole('button', { name: /sandbox/i })).toBeNull() + expect(screen.queryByRole('button', { name: /attach|upload/i })).toBeNull() }) describe('primary action placement', () => { @@ -53,7 +69,7 @@ describe('PromptInput composer layout', () => { expect(button.parentElement).toBe(textarea.parentElement) expect(textarea.nextElementSibling).toBe(button) - expect(button.parentElement?.contains(controlsRow())).toBe(false) + expect(button.parentElement).toBe(inputRow()) }) it('sends the typed prompt from the row button', async () => { @@ -185,34 +201,32 @@ describe('PromptInput composer layout', () => { }) describe('mobile key bar', () => { - it('replaces the config trigger with keys in the controls row while focused', async () => { + it('mounts the key bar below the input row while focused and keeps the config trigger', async () => { await renderPromptInput({ mobile: true }) expect(await screen.findByPlaceholderText('Send a message...')).toBeInTheDocument() expect(keyButtons()).toHaveLength(0) - expect(screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })).toBeInTheDocument() + expect(keysRow()).toBeNull() + const config = screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ }) + expect(inputRow()).toContainElement(config) fireEvent.focus(promptTextarea()) expect(keyButtons()).toHaveLength(1) - expect(controlsRow().firstElementChild).toContainElement(keyButtons()[0]) - expect(screen.getByRole('button', { name: 'cmd /' })).toBeInTheDocument() - expect(screen.getByRole('button', { name: 'mention @' })).toBeInTheDocument() - expect(screen.getByRole('button', { name: 'bash !' })).toBeInTheDocument() - expect(screen.queryByRole('button', { name: /^Session config/ })).not.toBeInTheDocument() + expect(keysRow()).toContainElement(keyButtons()[0]) + expect(inputRow()).not.toContainElement(keyButtons()[0]) + expect(screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })).toBe(config) }) - it('restores the config trigger after the prompt blurs', async () => { + it('removes the key bar after the prompt blurs', async () => { await renderPromptInput({ mobile: true }) fireEvent.focus(await screen.findByPlaceholderText('Send a message...')) - expect(screen.queryByRole('button', { name: /^Session config/ })).not.toBeInTheDocument() + expect(keyButtons()).toHaveLength(1) fireEvent.blur(promptTextarea()) - await waitFor(() => { - expect(screen.queryByRole('toolbar', { name: 'Insert' })).not.toBeInTheDocument() - }) + await waitFor(() => expect(keysRow()).toBeNull()) expect(screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })).toBeInTheDocument() }) @@ -224,31 +238,28 @@ describe('PromptInput composer layout', () => { expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument() }) - it('keeps the voice button on the right and the session config in the controls row', async () => { + it('keeps the voice button and the session config in the input row', async () => { await renderPromptInput({ mobile: true }) await screen.findByPlaceholderText('Send a message...') - const actions = controlsRow().lastElementChild - if (!(actions instanceof HTMLElement)) throw new Error('actions row is missing') - expect(actions).toContainElement(voiceMicButton()) - const config = screen.getByRole('button', { name: /^Session config/ }) - expect(controlsRow()).toContainElement(config) - expect(actions).not.toContainElement(config) + + expect(within(inputRow()).getAllByRole('button')).toEqual([config, voiceMicButton()]) }) }) describe('mobile voice button', () => { - it('renders the mobile mic alongside Send when the prompt has content', async () => { + it('replaces the mic with Send once the prompt has content', async () => { await renderPromptInput({ mobile: true }) - fireEvent.change(await screen.findByPlaceholderText('Send a message...'), { target: { value: 'hello' } }) + await screen.findByPlaceholderText('Send a message...') + expect(voiceMicButton()).not.toBeNull() + + fireEvent.change(promptTextarea(), { target: { value: 'hello' } }) expect(submitButton()).not.toBeNull() - expect(voiceMicButton()).not.toBeNull() - const actions = controlsRow().lastElementChild - if (!(actions instanceof HTMLElement)) throw new Error('actions row is missing') - expect(actions).toContainElement(voiceMicButton()) + expect(voiceMicButton()).toBeNull() + expect(inputRow()).toContainElement(submitButton()) }) it('hides the mic while a permission is pending', async () => { @@ -270,6 +281,34 @@ describe('PromptInput composer layout', () => { }) }) + describe('stop action', () => { + it.each([true, false])('shows Stop in the input row while a turn runs and hides the mic (mobile: %s)', async (mobile) => { + const { rerenderWith } = await renderPromptInput({ mobile, isSessionActive: true }) + + await screen.findByPlaceholderText('Send a message...') + const stop = screen.getByTitle('Stop') + expect(inputRow()).toContainElement(stop) + expect(voiceMicButton()).toBeNull() + if (mobile) { + expect(stop).toHaveClass('min-h-11', 'min-w-11') + } + + await rerenderWith({ isSessionActive: false }) + + expect(screen.queryByTitle('Stop')).toBeNull() + expect(voiceMicButton()).not.toBeNull() + }) + + it('keeps Stop next to Queue while the prompt has text during a turn', async () => { + await renderPromptInput({ isSessionActive: true, isStreamingResponse: true }) + + fireEvent.change(await screen.findByPlaceholderText('Send a message...'), { target: { value: 'follow-up' } }) + + const queue = screen.getByTitle('Queue message') + expect(queue.nextElementSibling).toBe(screen.getByTitle('Stop')) + }) + }) + describe('control sizing', () => { it('keeps the mic at 44px before and after the prompt gains focus on mobile', async () => { await renderPromptInput({ mobile: true }) diff --git a/frontend/src/components/message/PromptInput.stt.test.tsx b/frontend/src/components/message/PromptInput.stt.test.tsx index 9bc84480..9d80bb62 100644 --- a/frontend/src/components/message/PromptInput.stt.test.tsx +++ b/frontend/src/components/message/PromptInput.stt.test.tsx @@ -333,7 +333,7 @@ describe('PromptInput submission', () => { fireEvent.change(promptTextarea(), { target: { value: 'draft while active' } }) - expect(screen.getAllByTitle('Stop').length).toBeGreaterThan(0) + expect(screen.getAllByTitle('Stop')).toHaveLength(1) }) it('clears the draft store for the session after a successful send', async () => { diff --git a/frontend/src/components/message/PromptInput.tsx b/frontend/src/components/message/PromptInput.tsx index 06364586..ec6481ae 100644 --- a/frontend/src/components/message/PromptInput.tsx +++ b/frontend/src/components/message/PromptInput.tsx @@ -1267,7 +1267,26 @@ return ( {!isVoiceActive && ( <> -
+
+ +