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.
This commit is contained in:
Chris Scott committed 2026-10-23 14:20:57 -04:00
1 parent 67cfd862b1
commit 36a5693b5c
9 files changed
+57 -145

No files matched your search

@@ -148,7 +148,6 @@ describe('PromptInput command submission', () => {
const defaultProps = {
directory: '/test',
sessionID: 'test-session',
showScrollButton: false,
isSessionActive: false,
isStreamingResponse: false,
onScrollToBottom: vi.fn(),
@@ -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)
@@ -92,7 +92,6 @@ const createTestQueryClient = () => new QueryClient({
const defaultProps = {
directory: '/test',
sessionID: 'session-a',
showScrollButton: false,
isSessionActive: false,
isStreamingResponse: false,
onScrollToBottom: vi.fn(),
@@ -146,7 +146,6 @@ describe('PromptInput goal mode', () => {
const defaultProps = {
directory: '/test',
sessionID: 'test-session',
showScrollButton: false,
isSessionActive: false,
isStreamingResponse: false,
onScrollToBottom: vi.fn(),
@@ -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(),
@@ -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(),
@@ -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<PromptInputHandle, PromptInputProps>(
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 (
)}
</div>
<div className="flex items-center gap-1.5 md:gap-2 flex-shrink-0">
{!isMobile && (
<button
onClick={onScrollToBottom}
className={`p-2 rounded-lg bg-background/80 hover:bg-accent/90 text-primary hover:text-primary-hover transition-all duration-200 active:scale-95 hover:scale-105 shadow-md border border-primary/20 backdrop-blur-md ring-1 ring-primary/15 ${showScrollButton && !hasPromptContent ? 'visible' : 'invisible'}`}
title="Scroll to bottom"
>
<ArrowDown className="w-6 h-6" />
</button>
)}
{showStopButton && (
<button
onClick={handleStop}
@@ -1396,18 +1384,7 @@ return (
<Upload className="w-5 h-5" />
</button>
{showVoiceMic && renderVoiceMic()}
{showMobileScrollButton ? (
<button
type="button"
aria-label="Scroll to bottom"
title="Scroll to bottom"
onMouseDown={(e) => e.preventDefault()}
onClick={onScrollToBottom}
className={cn(getIconToggleButtonClassName(false), 'flex items-center justify-center size-11 p-0')}
>
<ArrowDown className="w-5 h-5" />
</button>
) : isMobile && directory && (
{isMobile && directory && (
<ComposerToolsMenu
sessionID={sessionID}
directory={directory}
+13 -2
View File
@@ -5,7 +5,7 @@ import { repoQueryOptions } from "@/lib/repoQuery";
import { MessageThread } from "@/components/message/MessageThread";
import { PromptInput, type PromptInputHandle } from "@/components/message/PromptInput";
import { FloatingTTSButton } from '@/components/message/FloatingTTSButton'
import { X, CornerUpLeft, GitBranch } from "lucide-react";
import { X, CornerUpLeft, GitBranch, ArrowDown } from "lucide-react";
import { SquareFill } from "@/components/ui/square-fill";
import { Header } from "@/components/ui/header";
import { Badge } from "@/components/ui/badge";
@@ -946,6 +946,18 @@ export function SessionDetail() {
)}
</div>
)}
{showScrollButton && !isFormSheetOpen && (
<button
type="button"
aria-label="Jump to latest"
title="Jump to latest"
onMouseDown={(e) => e.preventDefault()}
onClick={scrollToBottom}
className="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 z-50 size-11 rounded-full bg-card text-foreground border border-border shadow-md flex items-center justify-center transition-all duration-200 active:scale-95 hover:bg-accent"
>
<ArrowDown className="w-5 h-5" />
</button>
)}
{minimizedForm && (
<MinimizedFormIndicator
form={minimizedForm}
@@ -983,7 +995,6 @@ export function SessionDetail() {
sessionID={sessionId}
onVoiceConversationActiveChange={setIsVoiceConversationActive}
onSuggestionsOpenChange={setHasComposerSuggestions}
showScrollButton={showScrollButton}
isSessionActive={isSessionActive}
isStreamingResponse={isStreamingResponse}
onScrollToBottom={scrollToBottom}
@@ -316,22 +316,13 @@ describe('SessionDetail scroll floating button', () => {
}
)
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 (
<div>
<span>MockedPromptInput</span>
{props.showScrollButton && (
<button type="button" title="Scroll to bottom" aria-label="Scroll to bottom" onClick={props.onScrollToBottom}>
Latest
</button>
)}
</div>
)
return <div>MockedPromptInput</div>
})
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<string, unknown>
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 })