From 76d52b3550f98d804eda38b138b3e42971faa14c Mon Sep 17 00:00:00 2001 From: ioplex Date: Wed, 21 Oct 2026 00:59:42 -0400 Subject: [PATCH] feat(frontend): move send to the input and show key bar in the controls row - Place Send/Queue/View at the end of the textarea and hide Send when the draft is empty - Keep the model picker visible on mobile while a session is active - Keep the mobile mic in the controls row alongside Send - Show the /, @, ! keys in place of the agent/model selectors while focused on mobile - Compact the mobile controls row while the prompt is focused --- .../message/ComposerToolsMenu.test.tsx | 23 +- .../components/message/ComposerToolsMenu.tsx | 21 +- .../message/PromptInput.command.test.tsx | 2 +- .../message/PromptInput.composer.test.tsx | 331 ++++++++++++++++++ .../message/PromptInput.stt.test.tsx | 4 +- .../src/components/message/PromptInput.tsx | 186 +++++----- 6 files changed, 449 insertions(+), 118 deletions(-) create mode 100644 frontend/src/components/message/PromptInput.composer.test.tsx diff --git a/frontend/src/components/message/ComposerToolsMenu.test.tsx b/frontend/src/components/message/ComposerToolsMenu.test.tsx index fb9517f7..870c2d63 100644 --- a/frontend/src/components/message/ComposerToolsMenu.test.tsx +++ b/frontend/src/components/message/ComposerToolsMenu.test.tsx @@ -249,27 +249,22 @@ describe('ComposerToolsMenu', () => { expect(props.onAttachFile).toHaveBeenCalledTimes(1) }) - it('omits the dictate item when onDictate is not provided', async () => { - const user = userEvent.setup() + it('uses the default control size for the trigger', () => { mockPermissionMode() renderMenu() - await user.click(screen.getByRole('button', { name: 'Composer options' })) - await screen.findByRole('menuitem', { name: 'Attach image or PDF' }) - - expect(screen.queryByRole('menuitem', { name: 'Dictate' })).not.toBeInTheDocument() + const trigger = screen.getByRole('button', { name: 'Composer options' }) + expect(trigger).toHaveClass('min-h-[44px]', 'min-w-[44px]') + expect(trigger).not.toHaveClass('min-h-9') }) - it('starts dictation when onDictate is provided', async () => { - const user = userEvent.setup() + it('uses the compact control size for the trigger while the composer is focused', () => { mockPermissionMode() - const onDictate = vi.fn() - renderMenu({ onDictate }) + renderMenu({ compact: true }) - await user.click(screen.getByRole('button', { name: 'Composer options' })) - await user.click(await screen.findByRole('menuitem', { name: 'Dictate' })) - - expect(onDictate).toHaveBeenCalledTimes(1) + const trigger = screen.getByRole('button', { name: 'Composer options' }) + expect(trigger).toHaveClass('min-h-9', 'min-w-9') + expect(trigger).not.toHaveClass('min-h-[44px]') }) }) diff --git a/frontend/src/components/message/ComposerToolsMenu.tsx b/frontend/src/components/message/ComposerToolsMenu.tsx index 27094ade..ccd742b4 100644 --- a/frontend/src/components/message/ComposerToolsMenu.tsx +++ b/frontend/src/components/message/ComposerToolsMenu.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { Mic, Paperclip, Plus, Shield, ShieldCheck, Target } from 'lucide-react' +import { Paperclip, Plus, Shield, ShieldCheck, Target } from 'lucide-react' import { DropdownMenu, DropdownMenuCheckboxItem, @@ -25,9 +25,17 @@ interface ComposerToolsMenuProps { goalLabel: string onToggleGoal: () => void onAttachFile: () => void - onDictate?: () => void + /** Uses the 36px control size for the trigger while the prompt is focused. */ + compact?: boolean } +/** + * Renders the mobile composer tools trigger: a dropdown for permission mode, + * sandboxing, goal mode, and file attachment. + * + * @param props Session context, goal state, the attach handler, and whether the + * trigger uses the compact 36px control size while the prompt is focused. + */ export function ComposerToolsMenu({ sessionID, directory, @@ -36,7 +44,7 @@ export function ComposerToolsMenu({ goalLabel, onToggleGoal, onAttachFile, - onDictate, + compact = false, }: ComposerToolsMenuProps) { const isLocalServer = isLocalOpenCodeServer(useOpenCodeServerId()) const permission = usePermissionModeToggle(sessionID, directory) @@ -51,7 +59,7 @@ export function ComposerToolsMenu({ type="button" aria-label="Composer options" title="Composer options" - className={`${getIconToggleButtonClassName(permission.isAuto || sandbox.isSandboxed || goalArmed)} flex items-center justify-center min-h-[44px] min-w-[44px]`} + className={`${getIconToggleButtonClassName(permission.isAuto || sandbox.isSandboxed || goalArmed)} flex items-center justify-center ${compact ? 'min-h-9 min-w-9' : 'min-h-[44px] min-w-[44px]'}`} > @@ -82,11 +90,6 @@ export function ComposerToolsMenu({ } title="Attach image or PDF" /> - {onDictate ? ( - - } title="Dictate" /> - - ) : null} {shouldShowSandboxResources(sandbox) ? ( diff --git a/frontend/src/components/message/PromptInput.command.test.tsx b/frontend/src/components/message/PromptInput.command.test.tsx index 83f6380d..dfc56086 100644 --- a/frontend/src/components/message/PromptInput.command.test.tsx +++ b/frontend/src/components/message/PromptInput.command.test.tsx @@ -581,7 +581,7 @@ describe('PromptInput command submission', () => { renderComponent() const input = await screen.findByPlaceholderText('Send a message...') - const frame = input.parentElement as HTMLElement + const frame = input.closest('.isolate') as HTMLElement const tokens = frame.className.split(/\s+/) expect(tokens).not.toContain('transition-all') diff --git a/frontend/src/components/message/PromptInput.composer.test.tsx b/frontend/src/components/message/PromptInput.composer.test.tsx new file mode 100644 index 00000000..ab5a7a17 --- /dev/null +++ b/frontend/src/components/message/PromptInput.composer.test.tsx @@ -0,0 +1,331 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { render, screen, fireEvent, waitFor } from '@testing-library/react' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { PromptInput } from './PromptInput' +import { createCommandActionsMock } from '@/test/test-utils' + +const mocks = vi.hoisted(() => ({ + useSTT: vi.fn(), + useMobile: vi.fn(), + useCommands: vi.fn(), + useCommandHandler: vi.fn(), + useFileSearch: vi.fn(), + useModelSelection: vi.fn(), + useVariants: vi.fn(), + useSessionAgent: vi.fn(), + useUserBash: vi.fn(), + useSessionAgentStore: vi.fn(), + useSendErrorStore: vi.fn(), + useHasBackgroundActivity: vi.fn(), + useSendPrompt: vi.fn(), + hasPendingPermission: vi.fn(() => false), + setShowDialog: vi.fn(), +})) + +vi.mock('@/hooks/useSTT', () => ({ useSTT: mocks.useSTT })) +vi.mock('@/hooks/useMobile', () => ({ useMobile: mocks.useMobile })) +vi.mock('@/hooks/useCommands', () => ({ useCommands: mocks.useCommands })) +vi.mock('@/hooks/useCommandHandler', () => ({ useCommandHandler: mocks.useCommandHandler })) +vi.mock('@/hooks/useFileSearch', () => ({ useFileSearch: mocks.useFileSearch })) +vi.mock('@/hooks/useModelSelection', () => ({ useModelSelection: mocks.useModelSelection })) +vi.mock('@/hooks/useVariants', () => ({ useVariants: mocks.useVariants })) +vi.mock('@/hooks/useSessionAgent', () => ({ useSessionAgent: mocks.useSessionAgent })) +vi.mock('@/stores/userBashStore', () => ({ useUserBash: mocks.useUserBash })) +vi.mock('@/stores/sessionAgentStore', () => ({ useSessionAgentStore: mocks.useSessionAgentStore })) +vi.mock('@/stores/sendErrorStore', () => ({ useSendErrorStore: mocks.useSendErrorStore })) +vi.mock('@/stores/sessionStatusStore', async (importOriginal) => { + const actual = await importOriginal() + return { ...actual, useHasBackgroundActivity: mocks.useHasBackgroundActivity } +}) +vi.mock('@/lib/toast', () => ({ + showToast: { success: vi.fn(), error: vi.fn(), info: vi.fn(), warning: vi.fn(), loading: vi.fn(), promise: vi.fn(), dismiss: vi.fn() }, +})) + +vi.mock('@/hooks/useOpenCode', () => ({ + useSendPrompt: () => ({ mutate: mocks.useSendPrompt, isPending: false }), + useInterruptSession: () => ({ mutate: vi.fn() }), + useSendShell: () => ({ mutate: vi.fn(), isPending: false }), + useAgents: () => ({ data: [] }), + useSkills: () => ({ data: [] }), +})) + +vi.mock('@/hooks/useProviders', () => ({ useProviders: () => ({ data: undefined }) })) + +vi.mock('@/contexts/EventContext', () => ({ + usePermissions: () => ({ + hasForSession: mocks.hasPendingPermission, + setShowDialog: mocks.setShowDialog, + }), +})) + +vi.mock('@/components/agent/AgentQuickSelect', () => ({ + AgentQuickSelect: () =>
, +})) + +vi.mock('@/components/model/ModelQuickSelect', () => ({ + ModelQuickSelect: ({ children }: { children?: React.ReactNode }) => ( +
{children}
+ ), +})) + +vi.mock('@/components/session/PermissionModeToggle', () => ({ PermissionModeToggle: () => null })) +vi.mock('@/components/session/SessionSandboxMenu', () => ({ SessionSandboxMenu: () => null })) +vi.mock('./ComposerToolsMenu', () => ({ + ComposerToolsMenu: ({ compact }: { compact?: boolean }) => ( +
+ ), +})) +vi.mock('./PromptSuggestions', () => ({ PromptSuggestions: () => null })) +vi.mock('@/hooks/useSessionGoals', () => ({ + useSessionGoal: () => ({ data: undefined }), + useStartSessionGoal: () => ({ mutateAsync: vi.fn(), isPending: false }), +})) +vi.mock('@/hooks/useSessionPermissionMode', () => ({ useSessionPermissionMode: () => ({ data: undefined }) })) + +const createTestQueryClient = () => new QueryClient({ + defaultOptions: { queries: { retry: false }, mutations: { retry: false } }, +}) + +const defaultProps = { + directory: '/test', + sessionID: 'test-session', + showScrollButton: false, + isSessionActive: false, + isStreamingResponse: false, + onScrollToBottom: vi.fn(), + commandActions: createCommandActionsMock(), + onPromptChange: vi.fn(), +} + +describe('PromptInput composer layout', () => { + const renderComponent = (overrides: Partial = {}) => render( + + + , + ) + + const promptInput = () => screen.getByPlaceholderText('Send a message...') + const submitButton = () => document.querySelector('[data-submit-prompt]') + const controlsRow = () => screen.getByTestId('composer-controls-row') + const mobileVoiceButton = () => document.querySelector('[data-voice-variant="mobile"]') + const keyButtons = () => screen.queryAllByRole('toolbar', { name: 'Insert' }) + + beforeEach(() => { + vi.clearAllMocks() + mocks.hasPendingPermission.mockReturnValue(false) + mocks.useMobile.mockReturnValue(false) + mocks.useSTT.mockReturnValue({ + isRecording: false, + isProcessing: false, + isSupported: true, + isEnabled: true, + interimTranscript: '', + transcript: '', + startRecording: vi.fn(), + stopRecording: vi.fn(), + abortRecording: vi.fn(), + reset: vi.fn(), + clear: vi.fn(), + }) + mocks.useCommands.mockReturnValue({ searchCommands: () => [], findCommand: vi.fn(), recentNames: [] }) + mocks.useCommandHandler.mockReturnValue({ executeCommand: vi.fn() }) + mocks.useFileSearch.mockReturnValue({ files: [] }) + mocks.useModelSelection.mockReturnValue({ + model: null, + modelString: 'test-model', + setModel: vi.fn(), + setActiveAgent: vi.fn(), + recentModels: [], + favoriteModels: [], + toggleFavorite: vi.fn(), + isModelReady: true, + }) + mocks.useVariants.mockReturnValue({ hasVariants: false, currentVariant: null, cycleVariant: vi.fn() }) + mocks.useSessionAgent.mockReturnValue({ agent: 'default' }) + mocks.useUserBash.mockImplementation((selector: (state: unknown) => unknown) => selector({ addUserBashCommand: vi.fn() })) + mocks.useSessionAgentStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ setAgent: vi.fn() })) + mocks.useSendErrorStore.mockImplementation((selector: (state: unknown) => unknown) => selector({ errors: {} })) + mocks.useHasBackgroundActivity.mockReturnValue(false) + }) + + describe('primary action placement', () => { + it('omits the submit button while the prompt is empty', () => { + renderComponent() + + expect(promptInput()).toBeInTheDocument() + expect(submitButton()).toBeNull() + }) + + it('renders the submit button after the textarea in the same row', () => { + renderComponent() + + fireEvent.change(promptInput(), { target: { value: 'hello' } }) + + const textarea = promptInput() + const button = submitButton() as HTMLElement + + expect(button).not.toBeNull() + expect(button.parentElement).toBe(textarea.parentElement) + expect(textarea.nextElementSibling).toBe(button) + expect(button.parentElement?.contains(controlsRow())).toBe(false) + }) + + it('sends the typed prompt from the row button', () => { + renderComponent() + + fireEvent.change(promptInput(), { target: { value: 'row send' } }) + fireEvent.click(screen.getByTitle('Send')) + + const [variables] = mocks.useSendPrompt.mock.calls[0] as [{ text: string }] + expect(variables.text).toBe('row send') + }) + + it('queues from the row button while a response streams', () => { + renderComponent({ isStreamingResponse: true }) + + fireEvent.change(promptInput(), { target: { value: 'follow-up' } }) + + expect(screen.getByTitle('Queue message')).toBeInTheDocument() + }) + + it('shows View for a pending permission even while the prompt is empty', () => { + mocks.hasPendingPermission.mockReturnValue(true) + renderComponent() + + const view = screen.getByTitle('View pending permission') + expect(view).toHaveTextContent('View') + expect(view).toHaveAttribute('data-submit-prompt') + expect(view.parentElement).toBe(promptInput().parentElement) + + fireEvent.click(view) + expect(mocks.setShowDialog).toHaveBeenCalledWith(true) + }) + }) + + describe('model visibility', () => { + it('keeps the model selector visible on mobile while the session is active', () => { + mocks.useMobile.mockReturnValue(true) + renderComponent({ isSessionActive: true }) + + expect(screen.getByTestId('model-quick-select')).toBeInTheDocument() + expect(screen.getByText('test-model')).toBeInTheDocument() + }) + + it('keeps the model selector visible on desktop while the session is active', () => { + renderComponent({ isSessionActive: true }) + + expect(screen.getByTestId('model-quick-select')).toBeInTheDocument() + }) + }) + + describe('mobile key bar', () => { + beforeEach(() => { + mocks.useMobile.mockReturnValue(true) + }) + + it('replaces the agent and model selectors with keys in the controls row while focused', () => { + renderComponent() + + expect(keyButtons()).toHaveLength(0) + expect(screen.getByTestId('agent-quick-select')).toBeInTheDocument() + expect(screen.getByTestId('model-quick-select')).toBeInTheDocument() + + fireEvent.focus(promptInput()) + + 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.queryByTestId('agent-quick-select')).not.toBeInTheDocument() + expect(screen.queryByTestId('model-quick-select')).not.toBeInTheDocument() + }) + + it('restores the agent and model selectors after the prompt blurs', async () => { + renderComponent() + + fireEvent.focus(promptInput()) + expect(screen.queryByTestId('model-quick-select')).not.toBeInTheDocument() + + fireEvent.blur(promptInput()) + + await waitFor(() => { + expect(screen.queryByRole('toolbar', { name: 'Insert' })).not.toBeInTheDocument() + }) + expect(screen.getByTestId('agent-quick-select')).toBeInTheDocument() + expect(screen.getByTestId('model-quick-select')).toBeInTheDocument() + }) + + it('replaces the mobile Latest button with keys while focused', () => { + renderComponent({ showScrollButton: true }) + + expect(screen.getByText('Latest')).toBeInTheDocument() + + fireEvent.focus(promptInput()) + + expect(screen.queryByText('Latest')).not.toBeInTheDocument() + expect(screen.getByRole('button', { name: 'cmd /' })).toBeInTheDocument() + }) + + it('keeps the voice button and composer tools on the right side of the controls row', () => { + renderComponent() + + fireEvent.focus(promptInput()) + + const actions = controlsRow().lastElementChild as HTMLElement + expect(actions).toContainElement(mobileVoiceButton() as HTMLElement) + expect(actions).toContainElement(screen.getByTestId('composer-tools-menu')) + }) + }) + + describe('mobile voice button', () => { + beforeEach(() => { + mocks.useMobile.mockReturnValue(true) + }) + + it('renders the mobile mic alongside Send when the prompt has content', () => { + renderComponent() + + fireEvent.change(promptInput(), { target: { value: 'hello' } }) + + expect(submitButton()).not.toBeNull() + expect(mobileVoiceButton()).not.toBeNull() + expect(controlsRow().lastElementChild).toContainElement(mobileVoiceButton() as HTMLElement) + }) + + it('hides the mic while a permission is pending', () => { + mocks.hasPendingPermission.mockReturnValue(true) + renderComponent() + + expect(mobileVoiceButton()).toBeNull() + expect(screen.getByTitle('View pending permission')).toBeInTheDocument() + }) + }) + + describe('compact controls', () => { + it('uses compact sizing for the key buttons and mic while focused on mobile', () => { + mocks.useMobile.mockReturnValue(true) + renderComponent() + + fireEvent.focus(promptInput()) + + const commandKey = screen.getByRole('button', { name: 'cmd /' }) + expect(commandKey).toHaveClass('min-h-9') + expect(commandKey).not.toHaveClass('min-h-[44px]') + + const mic = mobileVoiceButton() as HTMLElement + expect(mic).toHaveClass('min-h-9', 'min-w-9') + expect(mic).not.toHaveClass('min-h-[44px]') + expect(screen.getByTestId('composer-tools-menu')).toHaveAttribute('data-compact', 'true') + }) + + it('uses the default sizing while the prompt is not focused', () => { + mocks.useMobile.mockReturnValue(true) + renderComponent() + + const mic = mobileVoiceButton() as HTMLElement + expect(mic).toHaveClass('min-h-[44px]', 'min-w-[44px]') + expect(screen.getByTestId('composer-tools-menu')).toHaveAttribute('data-compact', 'false') + }) + }) +}) diff --git a/frontend/src/components/message/PromptInput.stt.test.tsx b/frontend/src/components/message/PromptInput.stt.test.tsx index 8dc7c1d9..20c33ff4 100644 --- a/frontend/src/components/message/PromptInput.stt.test.tsx +++ b/frontend/src/components/message/PromptInput.stt.test.tsx @@ -571,13 +571,13 @@ describe('PromptInput STT Gesture Tests', () => { expect(screen.queryByTitle('Send')).not.toBeInTheDocument() }) - it('shows the submit button and hides the mobile mic once the prompt has content', () => { + it('shows the submit button and keeps the mobile mic once the prompt has content', () => { renderComponent() fireEvent.change(screen.getByPlaceholderText('Send a message...'), { target: { value: 'hello' } }) expect(screen.getByTitle('Send')).toBeInTheDocument() - expect(queryMobileVoiceButton()).toBeNull() + expect(queryMobileVoiceButton()).not.toBeNull() }) it('keeps the mobile mic visible while recording even with prompt content', () => { diff --git a/frontend/src/components/message/PromptInput.tsx b/frontend/src/components/message/PromptInput.tsx index 93327a63..b8da4c2b 100644 --- a/frontend/src/components/message/PromptInput.tsx +++ b/frontend/src/components/message/PromptInput.tsx @@ -1340,7 +1340,6 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) const composerModeStyle = composerMode ? COMPOSER_MODE_STYLES[composerMode] : null const isTakeoverOpen = isMobile && (isCommandListOpen || isMentionListOpen) const showStopButton = isSessionActive - const hideSecondaryButtons = isMobile && isSessionActive const showMobileScrollButton = isMobile && showScrollButton const hasOpenGoal = isOpenSessionGoal(sessionGoal) const lockedReason = permissionMode?.lockedReason ?? null @@ -1371,7 +1370,8 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) const showVoiceFeedback = voiceFeedbackState !== null const hasPromptContent = prompt.trim().length > 0 || imageAttachments.length > 0 const canUseMobileVoice = isMobile && sttEnabled && sttSupported && !hasPendingPermissionForSession - const showMobileVoiceButton = canUseMobileVoice && (!hasPromptContent || showVoiceFeedback) + const compactControls = isMobile && isPromptFocused + const showMobileKeys = isMobile && isPromptFocused && !hasPendingPermissionForSession const voiceFeedbackLabel = voiceFeedbackState === 'starting' ? 'Starting microphone...' : voiceFeedbackState === 'sending' @@ -1414,13 +1414,13 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) ? 'bg-destructive hover:bg-destructive/90 text-destructive-foreground border-destructive/60 animate-pulse' : 'bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border' }` - : `px-4 min-h-[44px] min-w-[56px] rounded-lg transition-all duration-150 flex items-center justify-center border touch-none select-none ${ + : `${compactControls ? 'min-h-9 min-w-9 px-0' : 'min-h-[44px] min-w-[44px] px-0'} rounded-lg transition-all duration-150 flex items-center justify-center border touch-none select-none ${ isBusy ? 'bg-success text-success-foreground border-success/70 shadow-lg shadow-success/40' : 'bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground border-border active:bg-muted-foreground/30 active:scale-95' }` - const containerClassName = isDesktop ? 'relative hidden md:block' : 'relative flex w-full justify-end touch-none select-none' + const containerClassName = isDesktop ? 'relative hidden md:block' : 'relative flex touch-none select-none' return (
( +
+ {KEYBAR_KEYS.map((key) => { + const isActive = key.id === 'command' + ? showSuggestions + : key.id === 'mention' + ? showMentionSuggestions + : isBashMode + const isDisabled = key.id === 'bash' ? !isBashKeyEnabled : isBashMode + return ( + + ) + })} +
+ ) + @@ -1501,30 +1536,47 @@ return ( {composerModeStyle.label} )} -