feat(frontend): consolidate composer controls at 36px and repaint the activity scanner in CSS

This commit is contained in:
Chris Scott committed 2026-10-21 12:40:34 -04:00
1 parent 76d52b3550
commit 648713268d
12 files changed
+212 -413

No files matched your search

@@ -55,7 +55,7 @@ export function AgentQuickSelect({
const buttonContent = (
<button
style={styleVars as React.CSSProperties}
className="px-2 md:px-3.5 py-1 h-[44px] md:h-[36px] rounded-lg text-sm font-medium border min-w-[56px] max-w-[80px] md:max-w-[100px] flex-shrink-0 flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md text-[var(--agent-color)] bg-[var(--agent-bg)] border-[var(--agent-border)] hover:bg-[var(--agent-bg-hover)] hover:border-[var(--agent-border-hover)] shadow-[var(--agent-shadow)] hover:shadow-[var(--agent-shadow-hover)]"
className="px-2 md:px-3.5 py-1 h-9 rounded-lg text-sm font-medium border min-w-[56px] max-w-[80px] md:max-w-[100px] flex-shrink-0 flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md text-[var(--agent-color)] bg-[var(--agent-bg)] border-[var(--agent-border)] hover:bg-[var(--agent-bg-hover)] hover:border-[var(--agent-border-hover)] shadow-[var(--agent-shadow)] hover:shadow-[var(--agent-shadow-hover)]"
>
<span className="truncate">{displayName}</span>
</button>
@@ -1,35 +1,10 @@
import { act, render, screen } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { ComposerActivityBar } from './ComposerActivityBar'
import { useSessionStatus } from '@/stores/sessionStatusStore'
import { stubMatchMedia } from '@/test/test-utils'
const originalMatchMedia = window.matchMedia
const originalResizeObserver = global.ResizeObserver
class MockResizeObserver {
static instances: MockResizeObserver[] = []
readonly callback: ResizeObserverCallback
constructor(callback: ResizeObserverCallback) {
this.callback = callback
MockResizeObserver.instances.push(this)
}
observe() {}
unobserve() {}
disconnect() {}
trigger(width: number) {
this.callback(
[{ contentRect: { width } } as ResizeObserverEntry],
this as unknown as ResizeObserver,
)
}
}
const resetStore = () => {
useSessionStatus.setState({
@@ -45,25 +20,14 @@ const resetStore = () => {
})
}
const segmentsOf = (bar: HTMLElement) =>
Array.from(bar.firstElementChild?.children ?? []) as HTMLElement[]
const measureWidth = (width: number) => {
act(() => {
MockResizeObserver.instances.forEach((instance) => instance.trigger(width))
})
}
const trackOf = (bar: HTMLElement) => bar.firstElementChild as HTMLElement
describe('ComposerActivityBar', () => {
beforeEach(() => {
resetStore()
MockResizeObserver.instances = []
global.ResizeObserver = MockResizeObserver as unknown as typeof ResizeObserver
})
afterEach(() => {
vi.useRealTimers()
global.ResizeObserver = originalResizeObserver
Object.defineProperty(window, 'matchMedia', {
configurable: true,
writable: true,
@@ -77,83 +41,49 @@ describe('ComposerActivityBar', () => {
expect(container).toBeEmptyDOMElement()
})
it('anchors a pointer-transparent progressbar in the gap below the composer', () => {
it('pins a pointer-transparent progressbar across the screen bottom on mobile and below the composer on desktop', () => {
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
render(<ComposerActivityBar sessionID="session-a" />)
const bar = screen.getByRole('progressbar', { name: 'Session working' })
expect(bar).toHaveClass('pointer-events-none')
expect(bar).toHaveClass('absolute')
expect(bar).toHaveClass('inset-x-3')
expect(bar).toHaveClass('-bottom-[13px]')
expect(bar).toHaveClass('md:-bottom-[11px]')
expect(bar).toHaveClass('flex')
expect(bar).toHaveClass('pointer-events-none', 'flex')
expect(bar).toHaveClass('fixed', 'inset-x-0', 'bottom-0')
expect(bar).toHaveClass('md:absolute', 'md:inset-x-3', 'md:-bottom-[11px]')
})
it('fills the measured width with 4x8 segments', () => {
it('renders a masked segment track with only the sweeping window', () => {
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
render(<ComposerActivityBar sessionID="session-a" />)
const bar = screen.getByRole('progressbar', { name: 'Session working' })
expect(bar.firstElementChild).toHaveClass('gap-0.5')
const track = trackOf(screen.getByRole('progressbar', { name: 'Session working' }))
expect(track).toHaveClass('scanner-track', 'relative', 'h-2', 'w-full')
measureWidth(602)
const segments = segmentsOf(bar)
expect(segments).toHaveLength(100)
expect(segments[0]).toHaveClass('w-1')
expect(segments[0]).toHaveClass('h-2')
expect(segments[0]).toHaveClass('rounded-[1px]')
expect(segments[0]).toHaveClass('transition-colors')
expect(segments[0]).toHaveClass('duration-75')
expect(segments[0]).not.toHaveClass('flex-1')
const children = Array.from(track.children) as HTMLElement[]
expect(children).toHaveLength(1)
expect(children[0]).toHaveClass('scanner-sweep')
})
it('keeps the minimum segment count for narrow containers', () => {
it('tints the track with the info tone while the session is busy', () => {
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
render(<ComposerActivityBar sessionID="session-a" />)
const bar = screen.getByRole('progressbar', { name: 'Session working' })
measureWidth(20)
expect(segmentsOf(bar)).toHaveLength(12)
const track = trackOf(screen.getByRole('progressbar', { name: 'Session working' }))
expect(track).toHaveClass('text-info')
})
it('lights the info tiers around the scanner window', () => {
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
render(<ComposerActivityBar sessionID="session-a" />)
measureWidth(602)
const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Session working' }))
expect(segments[3]).toHaveClass('bg-info')
expect(segments[4]).toHaveClass('bg-info/70')
expect(segments[6]).toHaveClass('bg-info/40')
expect(segments[7]).toHaveClass('bg-info/20')
expect(segments[8]).toHaveClass('bg-muted/20')
expect(segments[99]).toHaveClass('bg-muted/20')
})
it('renders the compacting state with primary colors', () => {
it('tints the track with the primary tone while compacting', () => {
useSessionStatus.getState().setStatus('session-a', { type: 'compact' })
render(<ComposerActivityBar sessionID="session-a" />)
measureWidth(602)
const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Compacting' }))
expect(segments[3]).toHaveClass('bg-primary')
expect(segments[4]).toHaveClass('bg-primary/70')
expect(segments[6]).toHaveClass('bg-primary/40')
expect(segments[7]).toHaveClass('bg-primary/20')
expect(segments[8]).toHaveClass('bg-muted/20')
const track = trackOf(screen.getByRole('progressbar', { name: 'Compacting' }))
expect(track).toHaveClass('text-primary')
})
it('reports the retry attempt in the label with warning colors', () => {
it('reports the retry attempt in the label with the warning tone', () => {
useSessionStatus.getState().setStatus('session-a', {
type: 'retry',
attempt: 2,
@@ -163,66 +93,26 @@ describe('ComposerActivityBar', () => {
render(<ComposerActivityBar sessionID="session-a" />)
measureWidth(602)
const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Retrying (Retry #2)' }))
expect(segments[3]).toHaveClass('bg-warning')
expect(segments[4]).toHaveClass('bg-warning/70')
expect(segments[6]).toHaveClass('bg-warning/40')
expect(segments[7]).toHaveClass('bg-warning/20')
expect(segments[8]).toHaveClass('bg-muted/20')
const track = trackOf(screen.getByRole('progressbar', { name: 'Retrying (Retry #2)' }))
expect(track).toHaveClass('text-warning')
})
it('renders the muted background activity state when idle with a running shell', () => {
it('tints the track with the muted foreground tone for background activity', () => {
useSessionStatus.getState().setShellRunning('shell-1', 'session-a', '/repo')
render(<ComposerActivityBar sessionID="session-a" />)
measureWidth(602)
const segments = segmentsOf(screen.getByRole('progressbar', { name: 'Background tasks running' }))
expect(segments[3]).toHaveClass('bg-muted-foreground')
expect(segments[4]).toHaveClass('bg-muted-foreground/70')
expect(segments[6]).toHaveClass('bg-muted-foreground/40')
expect(segments[7]).toHaveClass('bg-muted-foreground/20')
expect(segments[8]).toHaveClass('bg-muted/20')
const track = trackOf(screen.getByRole('progressbar', { name: 'Background tasks running' }))
expect(track).toHaveClass('text-muted-foreground')
})
it('sweeps the lit window on the step interval', () => {
vi.useFakeTimers()
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
render(<ComposerActivityBar sessionID="session-a" />)
const bar = screen.getByRole('progressbar', { name: 'Session working' })
measureWidth(602)
expect(segmentsOf(bar)[3]).toHaveClass('bg-info')
act(() => {
vi.advanceTimersByTime(120)
})
const segments = segmentsOf(bar)
expect(segments[7]).toHaveClass('bg-info')
expect(segments[4]).toHaveClass('bg-info/40')
})
it('renders every segment statically when reduced motion is requested', () => {
vi.useFakeTimers()
it('keeps sweeping when reduced motion is requested', () => {
stubMatchMedia(true)
useSessionStatus.getState().setStatus('session-a', { type: 'busy' })
render(<ComposerActivityBar sessionID="session-a" />)
const bar = screen.getByRole('progressbar', { name: 'Session working' })
measureWidth(602)
act(() => {
vi.advanceTimersByTime(600)
})
const segments = segmentsOf(bar)
expect(segments).toHaveLength(100)
expect(segments.every((segment) => segment.classList.contains('bg-info/60'))).toBe(true)
expect(segments.some((segment) => segment.classList.contains('bg-muted/20'))).toBe(false)
const track = trackOf(screen.getByRole('progressbar', { name: 'Session working' }))
expect(track.querySelector('.scanner-sweep')).not.toBeNull()
})
})
@@ -5,9 +5,6 @@ interface ComposerActivityBarProps {
sessionID: string
}
const LIT_WIDTH = 6
const STEP_INTERVAL_MS = 30
const ACTIVITY_PRESENTATION = {
background: {
label: 'Background tasks running',
@@ -28,10 +25,11 @@ const ACTIVITY_PRESENTATION = {
} as const satisfies Record<string, { label: string; tone: ScannerTone }>
/**
* Session activity scanner anchored in the gap below the composer frame. The strip uses the same
* 4x8px segments as the session status scanner and fills the composer width with as many segments
* as fit. Renders nothing while the session is idle and has no background activity; otherwise
* announces the current activity through an indeterminate progressbar.
* Session activity scanner. On mobile it spans the full width of the bottom screen edge; from the
* `md` breakpoint it is anchored in the gap below the composer frame. A fading lit window of 4x8px
* segments sweeps across the strip. Renders nothing while the
* session is idle and has no background activity; otherwise announces the current activity through
* an indeterminate progressbar.
*/
export function ComposerActivityBar({ sessionID }: ComposerActivityBarProps) {
const status = useSessionStatusForSession(sessionID)
@@ -54,9 +52,9 @@ export function ComposerActivityBar({ sessionID }: ComposerActivityBarProps) {
aria-label={label}
aria-valuemin={0}
aria-valuemax={100}
className="pointer-events-none absolute inset-x-3 -bottom-[13px] md:-bottom-[11px] flex"
className="pointer-events-none fixed inset-x-0 bottom-0 flex md:absolute md:inset-x-3 md:-bottom-[11px]"
>
<ScannerBars tone={activity.tone} litWidth={LIT_WIDTH} intervalMs={STEP_INTERVAL_MS} />
<ScannerBars tone={activity.tone} />
</div>
)
}
@@ -249,22 +249,13 @@ describe('ComposerToolsMenu', () => {
expect(props.onAttachFile).toHaveBeenCalledTimes(1)
})
it('uses the default control size for the trigger', () => {
it('uses the 36px control size for the trigger', () => {
mockPermissionMode()
renderMenu()
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('uses the compact control size for the trigger while the composer is focused', () => {
mockPermissionMode()
renderMenu({ compact: true })
const trigger = screen.getByRole('button', { name: 'Composer options' })
expect(trigger).toHaveClass('min-h-9', 'min-w-9')
expect(trigger).not.toHaveClass('min-h-[44px]')
expect(trigger).toHaveClass('size-9', 'p-0')
expect(trigger).not.toHaveClass('p-2')
})
})
@@ -13,6 +13,7 @@ import { isLocalOpenCodeServer, useOpenCodeServerId } from '@/contexts/OpenCodeS
import { usePermissionModeToggle } from '@/hooks/usePermissionModeToggle'
import { useSandboxToggle } from '@/hooks/useSandboxToggle'
import { shouldShowSandboxResources } from '@/lib/sandboxResources'
import { cn } from '@/lib/utils'
import { SandboxMenuItems } from './SandboxMenuItems'
import { ToolMenuItemContent } from './ToolMenuItemContent'
import { SessionSandboxResourcesDialog } from './SessionSandboxResourcesDialog'
@@ -25,16 +26,13 @@ interface ComposerToolsMenuProps {
goalLabel: string
onToggleGoal: () => void
onAttachFile: () => 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.
* @param props Session context, goal state, and the attach handler.
*/
export function ComposerToolsMenu({
sessionID,
@@ -44,7 +42,6 @@ export function ComposerToolsMenu({
goalLabel,
onToggleGoal,
onAttachFile,
compact = false,
}: ComposerToolsMenuProps) {
const isLocalServer = isLocalOpenCodeServer(useOpenCodeServerId())
const permission = usePermissionModeToggle(sessionID, directory)
@@ -59,7 +56,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 ${compact ? 'min-h-9 min-w-9' : 'min-h-[44px] min-w-[44px]'}`}
className={cn(getIconToggleButtonClassName(permission.isAuto || sandbox.isSandboxed || goalArmed), 'flex items-center justify-center size-9 p-0')}
>
<Plus className="w-5 h-5" />
</button>
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import { render, screen, fireEvent, waitFor, within } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PromptInput } from './PromptInput'
import { createCommandActionsMock } from '@/test/test-utils'
@@ -71,9 +71,7 @@ vi.mock('@/components/model/ModelQuickSelect', () => ({
vi.mock('@/components/session/PermissionModeToggle', () => ({ PermissionModeToggle: () => null }))
vi.mock('@/components/session/SessionSandboxMenu', () => ({ SessionSandboxMenu: () => null }))
vi.mock('./ComposerToolsMenu', () => ({
ComposerToolsMenu: ({ compact }: { compact?: boolean }) => (
<div data-testid="composer-tools-menu" data-compact={compact ? 'true' : 'false'} />
),
ComposerToolsMenu: () => <div data-testid="composer-tools-menu" />,
}))
vi.mock('./PromptSuggestions', () => ({ PromptSuggestions: () => null }))
vi.mock('@/hooks/useSessionGoals', () => ({
@@ -256,15 +254,55 @@ describe('PromptInput composer layout', () => {
expect(screen.getByTestId('model-quick-select')).toBeInTheDocument()
})
it('replaces the mobile Latest button with keys while focused', () => {
it('swaps the composer tools button for a scroll-to-bottom arrow while scrolled up', () => {
renderComponent({ showScrollButton: true })
expect(screen.getByText('Latest')).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()
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())
expect(screen.queryByText('Latest')).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'cmd /' })).toBeInTheDocument()
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-9', '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 })
expect(screen.getByTestId('composer-tools-menu')).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Scroll to bottom' })).not.toBeInTheDocument()
})
it('keeps the voice button and composer tools on the right side of the controls row', () => {
@@ -278,6 +316,24 @@ 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)
@@ -302,8 +358,23 @@ describe('PromptInput composer layout', () => {
})
})
describe('compact controls', () => {
it('uses compact sizing for the key buttons and mic while focused on mobile', () => {
describe('control sizing', () => {
it('keeps the mic at 36px before and after the prompt gains focus on mobile', () => {
mocks.useMobile.mockReturnValue(true)
renderComponent()
const micBeforeFocus = mobileVoiceButton() as HTMLElement
expect(micBeforeFocus).toHaveClass('min-h-9', 'min-w-9')
expect(micBeforeFocus).not.toHaveClass('min-h-[44px]')
fireEvent.focus(promptInput())
const micAfterFocus = mobileVoiceButton() as HTMLElement
expect(micAfterFocus).toHaveClass('min-h-9', 'min-w-9')
expect(micAfterFocus).not.toHaveClass('min-h-[44px]')
})
it('keeps the key buttons at 36px after the prompt gains focus on mobile', () => {
mocks.useMobile.mockReturnValue(true)
renderComponent()
@@ -312,20 +383,17 @@ describe('PromptInput composer layout', () => {
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', () => {
it('sizes the submit button at 36px on mobile', () => {
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')
fireEvent.change(promptInput(), { target: { value: 'hello' } })
const send = submitButton() as HTMLElement
expect(send).toHaveClass('h-9')
expect(send).not.toHaveClass('min-h-[44px]')
})
})
})
@@ -541,7 +541,7 @@ describe('PromptInput STT Gesture Tests', () => {
expect(voiceButtons.length).toBeGreaterThan(0)
})
it('renders mobile in-row Latest button when showScrollButton is true', async () => {
it('renders the mobile scroll-to-bottom button when showScrollButton is true', async () => {
mocks.useMobile.mockReturnValue(true)
render(
@@ -550,8 +550,8 @@ describe('PromptInput STT Gesture Tests', () => {
</QueryClientProvider>
)
expect(screen.getByTitle('Scroll to bottom')).toBeInTheDocument()
expect(screen.getByText('Latest')).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Scroll to bottom' })).toBeInTheDocument()
expect(screen.queryByText('Latest')).not.toBeInTheDocument()
})
})
+21 -33
View File
@@ -22,7 +22,7 @@ import { isLocalOpenCodeServer, useOpenCodeServerId } from '@/contexts/OpenCodeS
import { ArrowDown, Upload, X, Mic, MicOff, Target } from 'lucide-react'
import { SquareFill } from '@/components/ui/square-fill'
import { IconToggleButton } from '@/components/ui/icon-toggle-button'
import { IconToggleButton, getIconToggleButtonClassName } from '@/components/ui/icon-toggle-button'
import { PromptSuggestions, type PromptSuggestion } from './PromptSuggestions'
import { ComposerActivityBar } from './ComposerActivityBar'
@@ -38,7 +38,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 { randomId } from '@/lib/utils'
import { cn, randomId } from '@/lib/utils'
import { showToast } from '@/lib/toast'
import { findModelInfo, isSameModelSelection } from '@opencode-manager/shared/opencode'
import { isOpenSessionGoal } from '@opencode-manager/shared/schemas'
@@ -1370,7 +1370,6 @@ 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 compactControls = isMobile && isPromptFocused
const showMobileKeys = isMobile && isPromptFocused && !hasPendingPermissionForSession
const voiceFeedbackLabel = voiceFeedbackState === 'starting'
? 'Starting microphone...'
@@ -1414,7 +1413,7 @@ 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'
}`
: `${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 ${
: `min-h-9 min-w-9 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'
@@ -1475,9 +1474,7 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
onTouchMove={keybarTouch.onTouchMove}
onTouchEnd={(e) => keybarTouch.onTouchEnd(e, key.id)}
onClick={() => keybarTouch.onClick(key.id)}
className={`flex items-center gap-1 min-w-0 rounded-lg border font-mono text-base font-bold transition-colors disabled:opacity-30 ${
compactControls ? 'min-h-9 px-2' : 'min-h-[44px] px-3'
} ${
className={`flex items-center gap-1 min-w-0 rounded-lg border font-mono text-base font-bold transition-colors disabled:opacity-30 min-h-9 px-2 ${
isActive ? COMPOSER_MODE_STYLES[key.id].key : 'bg-muted border-border text-foreground active:bg-muted-foreground/20'
}`}
>
@@ -1536,7 +1533,7 @@ return (
{composerModeStyle.label}
</span>
)}
<div className="flex items-end gap-1.5 md:gap-2">
<div className="flex items-end gap-1.5 md:gap-2 mb-1.5 md:mb-2">
<textarea
ref={textareaRef}
data-prompt-input
@@ -1566,7 +1563,7 @@ return (
data-submit-prompt
onClick={hasPendingPermissionForSession ? () => setShowDialog(true) : handleSubmit}
disabled={hasPendingPermissionForSession ? false : (!isModelReady || !hasPromptContent || (isPromptSubmitPending && !isStreamingResponse))}
className={`px-4 md:px-5 py-1.5 md:py-2 rounded-lg text-sm font-medium transition-colors dark:border flex-shrink-0 min-w-[52px] flex items-center justify-center min-h-[44px] md:min-h-0 ${
className={`px-4 md:px-5 h-9 md:h-auto md:py-2 rounded-lg text-sm font-medium transition-colors dark:border flex-shrink-0 min-w-[52px] flex items-center justify-center ${
hasPendingPermissionForSession
? 'bg-highlight hover:bg-highlight/90 border-highlight text-highlight-foreground ring-highlight/20'
: 'bg-primary hover:bg-primary/90 disabled:bg-muted disabled:text-muted-foreground disabled:cursor-not-allowed text-primary-foreground border-border/30'
@@ -1600,26 +1597,7 @@ return (
<div data-testid="composer-controls-row" className="flex gap-1.5 md:gap-2 items-center justify-between">
<div className="flex flex-1 md:flex-initial gap-1.5 md:gap-2 items-center min-w-0">
{showMobileKeys ? renderMobileKeys() : showMobileScrollButton ? (
<>
<button
type="button"
onClick={onScrollToBottom}
className={`flex items-center gap-1.5 px-3 rounded-lg text-xs font-medium border bg-background/80 hover:bg-accent/90 text-primary hover:text-primary-hover border-primary/20 shadow-md backdrop-blur-md transition-all duration-200 active:scale-95 ring-1 ring-primary/15 ${compactControls ? 'min-h-9' : 'min-h-[44px]'}`}
title="Scroll to bottom"
aria-label="Scroll to bottom"
>
<ArrowDown className="w-4 h-4" />
<span>Latest</span>
</button>
<ModelQuickSelect
directory={directory}
open={isModelPickerOpen}
onOpenChange={setIsModelPickerOpen}
session={modelSelectionSession}
/>
</>
) : (
{showMobileKeys ? renderMobileKeys() : (
<>
<AgentQuickSelect
directory={directory}
@@ -1648,7 +1626,7 @@ return (
session={modelSelectionSession}
>
<button
className="px-2.5 py-0.5 md:px-3 min-h-[44px] md:min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
className="px-2.5 py-0.5 md:px-3 min-h-9 min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
>
<span className="truncate w-full text-left">{displayModelName || 'Select model'}</span>
{hasVariants && currentVariant && (
@@ -1663,7 +1641,7 @@ return (
{!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 ? 'visible' : 'invisible'}`}
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" />
@@ -1696,7 +1674,18 @@ return (
{canUseMobileVoice && (
renderVoiceButton('mobile')
)}
{isMobile && directory && (
{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-9 p-0')}
>
<ArrowDown className="w-5 h-5" />
</button>
) : isMobile && directory && (
<ComposerToolsMenu
sessionID={sessionID}
directory={directory}
@@ -1705,7 +1694,6 @@ return (
goalLabel={goalButtonLabel}
onToggleGoal={toggleGoalArmed}
onAttachFile={openFilePicker}
compact={compactControls}
/>
)}
{!isMobile && sttEnabled && sttSupported && (
+20 -188
View File
@@ -1,205 +1,37 @@
import { useLayoutEffect, useRef, useState, type RefObject } from 'react'
import { useMediaQuery } from '@/hooks/useMediaQuery'
import { cn } from '@/lib/utils'
export type ScannerTone = 'info' | 'primary' | 'warning' | 'muted-foreground'
export const SCANNER_REDUCED_MOTION_QUERY = '(prefers-reduced-motion: reduce)'
const SCANNER_SEGMENT_WIDTH = 4
const SCANNER_SEGMENT_GAP = 2
const SCANNER_SEGMENT_PITCH = SCANNER_SEGMENT_WIDTH + SCANNER_SEGMENT_GAP
const SCANNER_MIN_SEGMENTS = 12
const SCANNER_SEGMENT_CLASS = 'w-1 h-2 rounded-[1px] transition-colors duration-75'
const SCANNER_TONE_TIERS: Record<ScannerTone, readonly [string, string, string, string]> = {
info: ['bg-info', 'bg-info/70', 'bg-info/40', 'bg-info/20'],
primary: ['bg-primary', 'bg-primary/70', 'bg-primary/40', 'bg-primary/20'],
warning: ['bg-warning', 'bg-warning/70', 'bg-warning/40', 'bg-warning/20'],
'muted-foreground': ['bg-muted-foreground', 'bg-muted-foreground/70', 'bg-muted-foreground/40', 'bg-muted-foreground/20'],
}
const SCANNER_STATIC_TONE_CLASS: Record<ScannerTone, string> = {
info: 'bg-info/60',
primary: 'bg-primary/60',
warning: 'bg-warning/60',
'muted-foreground': 'bg-muted-foreground/60',
}
const SCANNER_OFF_CLASS = 'bg-muted/20'
const SCANNER_INTENSITY_THRESHOLDS = [0.8, 0.5, 0.2] as const
const SCANNER_FAINTEST_TIER = SCANNER_INTENSITY_THRESHOLDS.length
/**
* Returns how many fixed-width segments fit into `width`: each segment is 4px wide and the
* container adds a 2px gap between neighbors, so `n` segments occupy `6n - 2` pixels. Never
* drops below `SCANNER_MIN_SEGMENTS` so an unmeasured container still renders a usable scanner.
*/
export function scannerSegmentCountForWidth(width: number): number {
return Math.max(SCANNER_MIN_SEGMENTS, Math.floor((width + SCANNER_SEGMENT_GAP) / SCANNER_SEGMENT_PITCH))
}
/**
* Tracks the content width of a container across resizes. Returns 0 until the first measurement.
*/
function useContainerWidth(ref: RefObject<HTMLElement | null>): number {
const [width, setWidth] = useState(0)
useLayoutEffect(() => {
const element = ref.current
if (!element) {
return
}
const update = (next: number) => setWidth((previous) => (previous === next ? previous : next))
update(element.getBoundingClientRect().width)
if (typeof ResizeObserver === 'undefined') {
return
}
const observer = new ResizeObserver((entries) => {
const entry = entries[0]
if (entry) {
update(entry.contentRect.width)
}
})
observer.observe(element)
return () => observer.disconnect()
}, [ref])
return width
}
interface ScannerSegmentClassOptions {
index: number
position: number
litWidth: number
tone: ScannerTone
static?: boolean
}
/**
* Returns the background class for one scanner segment. Segments within the lit window fade out
* with distance from the window center across four intensity tiers; everything outside the window
* stays muted. `static` skips the window math and renders the uniform reduced-motion tint.
*/
export function scannerSegmentClass({
index,
position,
litWidth,
tone,
static: isStatic = false,
}: ScannerSegmentClassOptions): string {
if (isStatic) {
return SCANNER_STATIC_TONE_CLASS[tone]
}
const halfWidth = litWidth / 2
const distance = Math.abs(index - (position + halfWidth))
if (distance > halfWidth + 1) {
return SCANNER_OFF_CLASS
}
const intensity = Math.max(0, 1 - distance / (halfWidth + 2))
const tier = SCANNER_INTENSITY_THRESHOLDS.findIndex((threshold) => intensity > threshold)
return SCANNER_TONE_TIERS[tone][tier === -1 ? SCANNER_FAINTEST_TIER : tier]
}
interface ScannerPositionOptions {
segmentCount: number
litWidth: number
intervalMs: number
paused: boolean
}
function useScannerPosition({
segmentCount,
litWidth,
intervalMs,
paused,
}: ScannerPositionOptions): number {
const [position, setPosition] = useState(0)
const direction = useRef(1)
const maxPosition = Math.max(0, segmentCount - litWidth)
useLayoutEffect(() => {
setPosition((previous) => Math.min(previous, maxPosition))
}, [maxPosition])
useLayoutEffect(() => {
if (paused || maxPosition === 0) {
return
}
const interval = setInterval(() => {
setPosition((previous) => {
const next = previous + direction.current
if (next >= maxPosition) {
direction.current = -1
return maxPosition
}
if (next <= 0) {
direction.current = 1
return 0
}
return next
})
}, intervalMs)
return () => clearInterval(interval)
}, [paused, maxPosition, intervalMs])
return position
const SCANNER_TONE_CLASS: Record<ScannerTone, string> = {
info: 'text-info',
primary: 'text-primary',
warning: 'text-warning',
'muted-foreground': 'text-muted-foreground',
}
interface ScannerBarsProps {
tone: ScannerTone
segmentCount?: number
litWidth?: number
intervalMs?: number
className?: string
}
/**
* Segmented scanner matching the session status scanner: 4x8px segments with a 2px gap and a lit
* window of `litWidth` segments that sweeps back and forth. Without an explicit `segmentCount` the
* count is measured from the container width so the strip spans the space it is given. Under
* `prefers-reduced-motion: reduce` the sweep is not started and every segment renders statically at
* 60% opacity.
* Segmented scanner: a masked track of 4x8px cells with a 2px gap where only a lit window is
* visible. The window is brightest at its center and fades out cell by cell toward both edges as it
* sweeps from edge to edge and back. The mask, gradient and sweep live in `index.css`, so the
* animation advances in the browser with no JavaScript and no React render per frame. Like the
* braille activity spinner it animates regardless of `prefers-reduced-motion`, because a still
* indicator is indistinguishable from a stalled one.
*/
export function ScannerBars({
tone,
segmentCount,
litWidth = 6,
intervalMs = 60,
className,
}: ScannerBarsProps) {
const containerRef = useRef<HTMLDivElement>(null)
const reducedMotion = useMediaQuery(SCANNER_REDUCED_MOTION_QUERY)
const measuredWidth = useContainerWidth(containerRef)
const resolvedCount = segmentCount ?? scannerSegmentCountForWidth(measuredWidth)
const position = useScannerPosition({
segmentCount: resolvedCount,
litWidth,
intervalMs,
paused: reducedMotion,
})
export function ScannerBars({ tone, className }: ScannerBarsProps) {
return (
<div ref={containerRef} className={cn('flex w-full items-center gap-0.5', className)}>
{Array.from({ length: resolvedCount }, (_, index) => (
<div
key={index}
className={cn(
SCANNER_SEGMENT_CLASS,
scannerSegmentClass({ index, position, litWidth, tone, static: reducedMotion }),
)}
/>
))}
<div
className={cn(
'scanner-track relative h-2 w-full overflow-hidden',
SCANNER_TONE_CLASS[tone],
className,
)}
>
<div className="scanner-sweep absolute inset-y-0" />
</div>
)
}
+34
View File
@@ -545,6 +545,40 @@ input:-webkit-autofill:active {
animation: progress 2s ease-in-out infinite;
}
.scanner-track {
mask-image: repeating-linear-gradient(
90deg,
#000 0 4px,
transparent 4px 6px
);
-webkit-mask-image: repeating-linear-gradient(
90deg,
#000 0 4px,
transparent 4px 6px
);
}
@keyframes scanner-sweep {
from { left: -15%; }
to { left: 85%; }
}
.scanner-sweep {
left: -15%;
width: 30%;
background-image: linear-gradient(
90deg,
transparent,
color-mix(in oklab, currentColor 12%, transparent) 20%,
color-mix(in oklab, currentColor 40%, transparent) 35%,
currentColor 50%,
color-mix(in oklab, currentColor 40%, transparent) 65%,
color-mix(in oklab, currentColor 12%, transparent) 80%,
transparent
);
animation: scanner-sweep 2.8s ease-in-out infinite alternate;
}
:root [data-sonner-toaster][data-sonner-theme] {
--normal-bg: var(--color-popover);
--normal-bg-hover: var(--color-accent);
+1 -1
View File
@@ -968,7 +968,7 @@ export function SessionDetail() {
ref={promptInputRef}
directory={sessionDirectory}
sessionID={sessionId}
showScrollButton={showScrollButton && !hasPromptContent}
showScrollButton={showScrollButton}
isSessionActive={isSessionActive}
isStreamingResponse={isStreamingResponse}
onScrollToBottom={scrollToBottom}
@@ -379,11 +379,12 @@ describe('SessionDetail scroll floating button', () => {
})
})
it('does NOT pass scroll button state when prompt has content', async () => {
it('passes scroll button state even when the prompt has content', async () => {
renderWith({ mobile: true, showScrollButton: true, promptContent: true })
await waitFor(() => expect(screen.getByText('MockedPromptInput')).toBeInTheDocument())
expect(screen.queryByLabelText('Scroll to bottom')).not.toBeInTheDocument()
await waitFor(() => {
expect(screen.getByLabelText('Scroll to bottom')).toBeInTheDocument()
})
})
it('shows clear button for prompt content only when session is idle', async () => {