From 36a5693b5c3c85717647e7c11fcccb27bda399d3 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:20:57 -0400 Subject: [PATCH] fix(frontend): float one jump-to-latest button above the composer Match the mobile app: while the transcript is scrolled up, show a centered round button above the composer instead of swapping the mobile composer tools button for an arrow and hiding the desktop arrow when the prompt has text. The composer tools menu now stays available on mobile at all times, and the desktop in-composer arrow is gone. --- .../message/PromptInput.command.test.tsx | 1 - .../message/PromptInput.composer.test.tsx | 80 ++++--------------- .../message/PromptInput.draft.test.tsx | 1 - .../message/PromptInput.goal.test.tsx | 1 - .../message/PromptInput.mention.test.tsx | 1 - .../message/PromptInput.stt.test.tsx | 2 - .../src/components/message/PromptInput.tsx | 31 +------ frontend/src/pages/SessionDetail.tsx | 15 +++- .../SessionDetail.scroll-floating.test.tsx | 70 ++++++---------- 9 files changed, 57 insertions(+), 145 deletions(-) diff --git a/frontend/src/components/message/PromptInput.command.test.tsx b/frontend/src/components/message/PromptInput.command.test.tsx index a57767dd..eb07be05 100644 --- a/frontend/src/components/message/PromptInput.command.test.tsx +++ b/frontend/src/components/message/PromptInput.command.test.tsx @@ -148,7 +148,6 @@ describe('PromptInput command submission', () => { const defaultProps = { directory: '/test', sessionID: 'test-session', - showScrollButton: false, isSessionActive: false, isStreamingResponse: false, onScrollToBottom: vi.fn(), diff --git a/frontend/src/components/message/PromptInput.composer.test.tsx b/frontend/src/components/message/PromptInput.composer.test.tsx index 4d0363ae..f9fd93b6 100644 --- a/frontend/src/components/message/PromptInput.composer.test.tsx +++ b/frontend/src/components/message/PromptInput.composer.test.tsx @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import { render, screen, fireEvent, waitFor, within, act } from '@testing-library/react' +import { render, screen, fireEvent, waitFor, act } from '@testing-library/react' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { PromptInput } from './PromptInput' import { useComposerDraftStore } from '@/stores/composerDraftStore' @@ -94,7 +94,6 @@ const createTestQueryClient = () => new QueryClient({ const defaultProps = { directory: '/test', sessionID: 'test-session', - showScrollButton: false, isSessionActive: false, isStreamingResponse: false, onScrollToBottom: vi.fn(), @@ -281,55 +280,22 @@ describe('PromptInput composer layout', () => { expect(screen.getByTestId('model-quick-select')).toBeInTheDocument() }) - it('swaps the composer tools button for a scroll-to-bottom arrow while scrolled up', () => { - renderComponent({ showScrollButton: true }) - - const actions = controlsRow().lastElementChild as HTMLElement - expect(within(actions).getByRole('button', { name: 'Scroll to bottom' })).toBeInTheDocument() - expect(screen.queryByTestId('composer-tools-menu')).not.toBeInTheDocument() - expect(within(controlsRow().firstElementChild as HTMLElement).getByTestId('agent-quick-select')).toBeInTheDocument() - expect(within(controlsRow().firstElementChild as HTMLElement).getByTestId('model-quick-select')).toBeInTheDocument() - expect(screen.queryByText('Latest')).not.toBeInTheDocument() - }) - - it('keeps the scroll-to-bottom arrow on the right while the prompt is focused', () => { - renderComponent({ showScrollButton: true }) - - fireEvent.focus(promptInput()) - - const keys = screen.getByRole('toolbar', { name: 'Insert' }) - expect(within(keys).getByRole('button', { name: 'bash !' })).toBeInTheDocument() - - const actions = controlsRow().lastElementChild as HTMLElement - expect(within(actions).getByRole('button', { name: 'Scroll to bottom' })).toBeInTheDocument() - expect(screen.queryByTestId('composer-tools-menu')).not.toBeInTheDocument() - }) - - it('keeps the scroll-to-bottom arrow while the prompt has text', () => { - renderComponent({ showScrollButton: true }) - - fireEvent.change(promptInput(), { target: { value: 'hello' } }) - - expect(screen.getByRole('button', { name: 'Scroll to bottom' })).toBeInTheDocument() - }) - - it('scrolls to the bottom from the swapped arrow and keeps the composer tools box size', () => { - const onScrollToBottom = vi.fn() - renderComponent({ showScrollButton: true, onScrollToBottom }) - - const arrow = screen.getByRole('button', { name: 'Scroll to bottom' }) - expect(arrow).toHaveClass('size-11', 'p-0') - - fireEvent.click(arrow) - - expect(onScrollToBottom).toHaveBeenCalledTimes(1) - }) - - it('keeps the composer tools button while at the bottom of the transcript', () => { - renderComponent({ showScrollButton: false }) + it('keeps the composer tools button at the bottom of the transcript', () => { + renderComponent() expect(screen.getByTestId('composer-tools-menu')).toBeInTheDocument() expect(screen.queryByRole('button', { name: 'Scroll to bottom' })).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument() + }) + + it('keeps the composer tools button while the prompt has text', () => { + renderComponent() + + fireEvent.change(promptInput(), { target: { value: 'hello' } }) + + expect(screen.getByTestId('composer-tools-menu')).toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Scroll to bottom' })).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument() }) it('keeps the voice button and composer tools on the right side of the controls row', () => { @@ -343,24 +309,6 @@ describe('PromptInput composer layout', () => { }) }) - describe('desktop scroll button visibility', () => { - const desktopScrollButton = () => screen.getByTitle('Scroll to bottom') - - it('hides the desktop scroll arrow once the prompt has text', () => { - renderComponent({ showScrollButton: true }) - - fireEvent.change(promptInput(), { target: { value: 'hello' } }) - - expect(desktopScrollButton()).toHaveClass('invisible') - }) - - it('shows the desktop scroll arrow while the prompt is empty', () => { - renderComponent({ showScrollButton: true }) - - expect(desktopScrollButton()).toHaveClass('visible') - }) - }) - describe('mobile voice button', () => { beforeEach(() => { mocks.useMobile.mockReturnValue(true) diff --git a/frontend/src/components/message/PromptInput.draft.test.tsx b/frontend/src/components/message/PromptInput.draft.test.tsx index 34a5b445..20788082 100644 --- a/frontend/src/components/message/PromptInput.draft.test.tsx +++ b/frontend/src/components/message/PromptInput.draft.test.tsx @@ -92,7 +92,6 @@ const createTestQueryClient = () => new QueryClient({ const defaultProps = { directory: '/test', sessionID: 'session-a', - showScrollButton: false, isSessionActive: false, isStreamingResponse: false, onScrollToBottom: vi.fn(), diff --git a/frontend/src/components/message/PromptInput.goal.test.tsx b/frontend/src/components/message/PromptInput.goal.test.tsx index f976563b..2f63e25f 100644 --- a/frontend/src/components/message/PromptInput.goal.test.tsx +++ b/frontend/src/components/message/PromptInput.goal.test.tsx @@ -146,7 +146,6 @@ describe('PromptInput goal mode', () => { const defaultProps = { directory: '/test', sessionID: 'test-session', - showScrollButton: false, isSessionActive: false, isStreamingResponse: false, onScrollToBottom: vi.fn(), diff --git a/frontend/src/components/message/PromptInput.mention.test.tsx b/frontend/src/components/message/PromptInput.mention.test.tsx index b686b7bb..2721ecac 100644 --- a/frontend/src/components/message/PromptInput.mention.test.tsx +++ b/frontend/src/components/message/PromptInput.mention.test.tsx @@ -135,7 +135,6 @@ describe('PromptInput agent mention submission', () => { const defaultProps = { directory: '/test', sessionID: 'test-session', - showScrollButton: false, isSessionActive: false, isStreamingResponse: false, onScrollToBottom: vi.fn(), diff --git a/frontend/src/components/message/PromptInput.stt.test.tsx b/frontend/src/components/message/PromptInput.stt.test.tsx index 0586436a..22f4f146 100644 --- a/frontend/src/components/message/PromptInput.stt.test.tsx +++ b/frontend/src/components/message/PromptInput.stt.test.tsx @@ -152,7 +152,6 @@ describe('PromptInput voice conversation', () => { const defaultProps = { directory: '/test', sessionID: 'test-session', - showScrollButton: false, isSessionActive: false, isStreamingResponse: false, onScrollToBottom: vi.fn(), @@ -401,7 +400,6 @@ describe('PromptInput submission', () => { const defaultProps = { directory: '/test', sessionID: 'test-session', - showScrollButton: false, isSessionActive: false, isStreamingResponse: false, onScrollToBottom: vi.fn(), diff --git a/frontend/src/components/message/PromptInput.tsx b/frontend/src/components/message/PromptInput.tsx index 9d1fc585..62496482 100644 --- a/frontend/src/components/message/PromptInput.tsx +++ b/frontend/src/components/message/PromptInput.tsx @@ -20,10 +20,10 @@ import { FINE_POINTER_MEDIA_QUERY, useMediaQuery } from '@/hooks/useMediaQuery' import { usePermissions } from '@/contexts/EventContext' import { isLocalOpenCodeServer, useOpenCodeServerId } from '@/contexts/OpenCodeServerContext' -import { ArrowDown, Upload, X, Mic, Target } from 'lucide-react' +import { Upload, X, Mic, Target } from 'lucide-react' import { SquareFill } from '@/components/ui/square-fill' -import { IconToggleButton, getIconToggleButtonClassName } from '@/components/ui/icon-toggle-button' +import { IconToggleButton } from '@/components/ui/icon-toggle-button' import { PromptSuggestions, type PromptSuggestion } from './PromptSuggestions' import { ComposerActivityBar } from './ComposerActivityBar' @@ -39,7 +39,7 @@ import { detectMentionTrigger, parsePromptToInput, getFilename, getDirectory, ty import { matchText, rankByMatch, type MatchRange } from '@/lib/fuzzyMatch' import { getNextPrimaryAgentId } from '@/lib/primaryAgents' import { getNextFavoriteModel } from '@/lib/favoriteModels' -import { cn, randomId } from '@/lib/utils' +import { randomId } from '@/lib/utils' import { showToast } from '@/lib/toast' import { findModelInfo, isSameModelSelection } from '@opencode-manager/shared/opencode' import { isOpenSessionGoal } from '@opencode-manager/shared/schemas' @@ -131,7 +131,6 @@ interface PromptInputProps { sessionID: string onVoiceConversationActiveChange?: (active: boolean) => void onSuggestionsOpenChange?: (open: boolean) => void - showScrollButton?: boolean isSessionActive?: boolean isStreamingResponse?: boolean onScrollToBottom: () => void @@ -144,7 +143,6 @@ export const PromptInput = memo(forwardRef( sessionID, onVoiceConversationActiveChange, onSuggestionsOpenChange, - showScrollButton, isSessionActive = false, isStreamingResponse = false, onScrollToBottom, @@ -1101,7 +1099,6 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read) const composerModeStyle = composerMode ? COMPOSER_MODE_STYLES[composerMode] : null const isTakeoverOpen = isMobile && isSuggestionListOpen const showStopButton = isSessionActive - const showMobileScrollButton = isMobile && showScrollButton const hasOpenGoal = isOpenSessionGoal(sessionGoal) const lockedReason = permissionMode?.lockedReason ?? null const goalButtonLabel = lockedReason === 'schedule' @@ -1362,15 +1359,6 @@ return ( )}
- {!isMobile && ( - - )} {showStopButton && ( {showVoiceMic && renderVoiceMic()} - {showMobileScrollButton ? ( - - ) : isMobile && directory && ( + {isMobile && directory && ( )} + {showScrollButton && !isFormSheetOpen && ( + + )} {minimizedForm && ( { } ) - mocks.PromptInput.mockImplementation((props: { onPromptChange?: (hasContent: boolean) => void; showScrollButton?: boolean; onScrollToBottom: () => void }) => { + mocks.PromptInput.mockImplementation((props: { onPromptChange?: (hasContent: boolean) => void }) => { const { onPromptChange } = props useEffect(() => { onPromptChange?.(opts.promptContent ?? false) }, [onPromptChange]) - return ( -
- MockedPromptInput - {props.showScrollButton && ( - - )} -
- ) + return
MockedPromptInput
}) const queryClient = createQueryClient() @@ -348,44 +339,46 @@ describe('SessionDetail scroll floating button', () => { return Object.assign(render(buildTree()), { buildTree }) } - it('passes scroll button state to PromptInput when showScrollButton is true', async () => { + it('shows the jump to latest button while scrolled up on mobile', async () => { renderWith({ mobile: true, showScrollButton: true }) - await waitFor(() => { - expect(screen.getByTitle('Scroll to bottom')).toBeInTheDocument() - }) - expect(screen.getByLabelText('Scroll to bottom')).toBeInTheDocument() + expect(await screen.findByRole('button', { name: 'Jump to latest' })).toBeInTheDocument() }) - it('still passes scroll button state when content height is below tall threshold', async () => { - renderWith({ mobile: true, showScrollButton: true }) + it('shows the jump to latest button while scrolled up on desktop', async () => { + renderWith({ mobile: false, showScrollButton: true }) - await waitFor(() => { - expect(screen.getByLabelText('Scroll to bottom')).toBeInTheDocument() - }) + expect(await screen.findByRole('button', { name: 'Jump to latest' })).toBeInTheDocument() }) - it('does NOT pass scroll button state when mobile + tall content but no showScrollButton', async () => { + it('shows the jump to latest button even when the prompt has content', async () => { + renderWith({ mobile: true, showScrollButton: true, promptContent: true }) + + expect(await screen.findByRole('button', { name: 'Jump to latest' })).toBeInTheDocument() + }) + + it('hides the jump to latest button while at the bottom of the transcript', async () => { renderWith({ mobile: true, showScrollButton: false }) await waitFor(() => expect(screen.getByText('MockedPromptInput')).toBeInTheDocument()) - expect(screen.queryByLabelText('Scroll to bottom')).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument() }) - it('passes scroll button state on desktop for PromptInput desktop handling', async () => { - renderWith({ mobile: false, showScrollButton: true }) + it('no longer passes scroll button state to PromptInput', async () => { + renderWith({ mobile: true, showScrollButton: true }) - await waitFor(() => { - expect(screen.getByLabelText('Scroll to bottom')).toBeInTheDocument() - }) + await screen.findByRole('button', { name: 'Jump to latest' }) + + const props = mocks.PromptInput.mock.calls.at(-1)?.[0] as Record + expect(props.showScrollButton).toBeUndefined() }) - it('passes scroll button state even when the prompt has content', async () => { - renderWith({ mobile: true, showScrollButton: true, promptContent: true }) + it('scrolls to the bottom when the jump to latest button is clicked', async () => { + renderWith({ mobile: true, showScrollButton: true }) - await waitFor(() => { - expect(screen.getByLabelText('Scroll to bottom')).toBeInTheDocument() - }) + fireEvent.click(await screen.findByRole('button', { name: 'Jump to latest' })) + + expect(mockScrollToBottom).toHaveBeenCalledTimes(1) }) it('shows clear button for prompt content only when session is idle', async () => { @@ -417,17 +410,6 @@ describe('SessionDetail scroll floating button', () => { expect(screen.queryByTitle('Stop')).not.toBeInTheDocument() }) - it('clicking PromptInput scroll button calls scrollToBottom from useAutoScroll', async () => { - renderWith({ mobile: true, showScrollButton: true }) - - await waitFor(() => { - expect(screen.getByLabelText('Scroll to bottom')).toBeInTheDocument() - }) - - fireEvent.click(screen.getByLabelText('Scroll to bottom')) - expect(mockScrollToBottom).toHaveBeenCalledTimes(1) - }) - it('does NOT disable PromptInput when SSE is disconnected', async () => { mocks.useSSE.mockReturnValue({ isConnected: false, isReconnecting: true }) renderWith({ mobile: true, showScrollButton: false })