Cap the config panel to available height, add menu keyboard navigation and drop the unreachable model fallback

This commit is contained in:
Chris Scott committed 2026-11-27 22:06:10 -05:00
1 parent c586bcb4ad
commit bc36df403f
3 files changed
+60 -14

No files matched your search

@@ -419,6 +419,24 @@ describe.each([
expect(screen.getByRole('menuitemcheckbox', { name: /Accept all permissions/ })).toBeInTheDocument()
})
it('moves focus between menu items with the keyboard and exposes named sections', async () => {
const { user } = await renderConfig(mobile, {
agents: [makeAgent({ id: 'build', mode: 'primary' })],
})
await openConfig(user)
expect(await screen.findByRole('group', { name: 'Session' })).toBeInTheDocument()
expect(screen.getByRole('group', { name: 'Agent' })).toBeInTheDocument()
const first = screen.getByRole('menuitem', { name: /Change agent: Build/ })
first.focus()
await user.keyboard('{ArrowDown}')
expect(screen.getByRole('menuitem', { name: /Change model/ })).toHaveFocus()
await user.keyboard('{End}')
expect(screen.getByRole('menuitem', { name: 'Attach image or PDF' })).toHaveFocus()
})
it('updates the trigger summary when cycling the agent through the handle', async () => {
const ref = createRef<PromptInputHandle>()
await renderPromptInput({
@@ -1,4 +1,4 @@
import { memo, useEffect, useState, type CSSProperties, type ReactNode } from 'react'
import { memo, useEffect, useId, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react'
import { Box, Check, ChevronLeft, ChevronRight, Cpu, Paperclip, Shield, ShieldCheck, SlidersHorizontal, Target } from 'lucide-react'
import type { AgentInfo } from '@opencode-manager/shared/opencode'
import { useAgents, useSession } from '@/hooks/useOpenCode'
@@ -73,6 +73,33 @@ const rowClassName = (mobile: boolean) =>
mobile ? 'min-h-11 py-2' : 'py-1.5',
)
const menuItems = (container: HTMLElement) =>
Array.from(container.querySelectorAll<HTMLElement>('[role^="menuitem"]')).filter(
(item) => !item.matches(':disabled') && item.getAttribute('aria-disabled') !== 'true',
)
const handleMenuKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
const items = menuItems(event.currentTarget)
if (items.length === 0) return
const currentIndex = items.findIndex((item) => item === document.activeElement)
const lastIndex = items.length - 1
let nextIndex: number | null = null
if (event.key === 'ArrowDown') {
nextIndex = currentIndex < 0 ? 0 : (currentIndex + 1) % items.length
} else if (event.key === 'ArrowUp') {
nextIndex = currentIndex < 0 ? lastIndex : (currentIndex + items.length - 1) % items.length
} else if (event.key === 'Home') {
nextIndex = 0
} else if (event.key === 'End') {
nextIndex = lastIndex
}
if (nextIndex === null) return
event.preventDefault()
items[nextIndex]?.focus()
}
interface SessionMenuItemProps {
role: SessionMenuItemRole
checked?: boolean
@@ -141,10 +168,15 @@ interface ConfigSectionProps {
}
function ConfigSection({ label, children }: ConfigSectionProps) {
const labelId = useId()
return (
<div className="flex flex-col gap-1">
<div
role={label ? 'group' : undefined}
aria-labelledby={label ? labelId : undefined}
className="flex flex-col gap-1"
>
{label ? (
<div role="presentation" className="px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
<div id={labelId} className="px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
{label}
</div>
) : null}
@@ -484,7 +516,7 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({
</button>
<h2 className="truncate text-sm font-semibold text-foreground">Agent</h2>
</div>
<div role="menu" aria-label="Agent">
<div role="menu" aria-label="Agent" onKeyDown={handleMenuKeyDown}>
{primaryAgents.map((agent) => {
const checked = agent.id.toLowerCase() === currentAgent.toLowerCase()
return (
@@ -608,7 +640,7 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({
className={view === 'model' ? 'flex min-h-0 flex-1 flex-col overflow-hidden p-0 pb-safe' : undefined}
>
{view === 'main' ? (
<div role="menu" aria-label="Session config">
<div role="menu" aria-label="Session config" onKeyDown={handleMenuKeyDown}>
{renderMainView(true)}
</div>
) : view === 'agent' ? (
@@ -627,10 +659,10 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({
align="start"
collisionPadding={8}
avoidCollisions={false}
className="h-[min(70vh,560px)] w-[22rem] max-w-[calc(100vw-1rem)] overflow-hidden p-0"
className="h-[min(70vh,560px,var(--radix-popover-content-available-height))] w-[22rem] max-w-[calc(100vw-1rem)] overflow-hidden p-0"
>
{view === 'main' ? (
<div role="menu" aria-label="Session config" className="h-full overflow-y-auto p-1.5">
<div role="menu" aria-label="Session config" onKeyDown={handleMenuKeyDown} className="h-full overflow-y-auto p-1.5">
{renderMainView(false)}
</div>
) : view === 'agent' ? (
@@ -210,7 +210,6 @@ export const ModelPicker = memo(function ModelPicker({
const rowsByKey = new Map<string, ModelListItem>()
const modelsByProviderId = new Map<string, ModelListItem[]>()
const providerItems: ProviderListItem[] = []
const allModels: ModelListItem[] = []
for (const section of catalogSections) {
if (!section.providerID) continue
@@ -218,10 +217,9 @@ export const ModelPicker = memo(function ModelPicker({
for (const item of items) rowsByKey.set(item.key, item)
providerItems.push({ id: section.providerID, label: section.title, count: items.length })
modelsByProviderId.set(section.providerID, items)
allModels.push(...items)
}
return { rowsByKey, modelsByProviderId, providerItems, allModels }
return { rowsByKey, modelsByProviderId, providerItems }
}, [showAllModels, catalogSections, toModelListItem])
const quickSections = useMemo((): QuickModelSection[] => {
@@ -272,16 +270,14 @@ export const ModelPicker = memo(function ModelPicker({
[browseData, selectedProviderId]
)
const browseModels = selectedProviderId ? selectedProviderModels : browseData?.allModels ?? EMPTY_MODELS
const navigableItems = useMemo((): ModelListItem[] => {
if (showAllModels) {
if (isSearching) return searchResults
if (!selectedProviderId) return EMPTY_MODELS
return browseModels
return selectedProviderModels
}
return quickSections.flatMap((section) => section.models)
}, [showAllModels, isSearching, selectedProviderId, searchResults, browseModels, quickSections])
}, [showAllModels, isSearching, selectedProviderId, searchResults, selectedProviderModels, quickSections])
const quickSectionOffsets = useMemo(() => {
const offsets = new Map<string, number>()