Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-app): r1-m1 move keyboard focus into the portaled agent menu

Diego Zacariasde0fec9a3eb8
diff --git a/desktop-app/ui/src/components/agents/AgentTitleSelector.tsx b/desktop-app/ui/src/components/agents/AgentTitleSelector.tsx
index 3ea4bdfa7..c717c3057 100644
--- a/desktop-app/ui/src/components/agents/AgentTitleSelector.tsx
+++ b/desktop-app/ui/src/components/agents/AgentTitleSelector.tsx
@@ -98,6 +98,9 @@ export function AgentTitleSelector({
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
if (openAgent) {
+ // Return focus to the row's dots button the sub-menu came from before
+ // collapsing it (the ref reflects the currently expanded row).
+ submenuAnchorRef.current?.focus()
setOpenAgent(null)
} else {
setOpen(false)
@@ -107,6 +110,24 @@ export function AgentTitleSelector({
}
window.addEventListener('keydown', onKeyDown)
return () => window.removeEventListener('keydown', onKeyDown)
+ }, [open, openAgent, submenuAnchorRef])
+
+ // The menu and its sections sub-menu are portaled to document.body, so opening
+ // them leaves keyboard focus on the trigger and a Tab would jump past them to
+ // the next header control instead of into the menu. Move focus to the first
+ // enabled item on open — mirroring GfsResourceMenu, the portaled-menu pattern
+ // this component follows; ESC returns focus outward (above). Keyed on `open`
+ // alone so expanding a row's sub-menu doesn't yank focus back to the main menu.
+ useEffect(() => {
+ if (!open) return
+ menuRef.current?.querySelector<HTMLButtonElement>('[role="menuitem"]:not(:disabled)')?.focus()
+ }, [open])
+
+ useEffect(() => {
+ if (!open || openAgent === null) return
+ submenuRef.current
+ ?.querySelector<HTMLButtonElement>('[role="menuitem"]:not(:disabled)')
+ ?.focus()
}, [open, openAgent])
return (
diff --git a/desktop-app/ui/src/components/agents/__tests__/AgentTitleSelector.test.tsx b/desktop-app/ui/src/components/agents/__tests__/AgentTitleSelector.test.tsx
index 54ae7e24e..76ffedb82 100644
--- a/desktop-app/ui/src/components/agents/__tests__/AgentTitleSelector.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/AgentTitleSelector.test.tsx
@@ -230,4 +230,28 @@ describe('AgentTitleSelector', () => {
// The route item still fires its click (guard kept it mounted through mousedown).
fireEvent.click(screen.getByRole('menuitem', { name: 'Connectors' }))
})
+
+ it('moves keyboard focus into the portaled menu when it opens', () => {
+ renderSelector()
+ openMenu()
+ // The menu is portaled to document.body; without moving focus into it, a
+ // keyboard user's Tab jumps from the trigger past the menu to the next
+ // header control. Focus must land on the first row item (Alpha's name).
+ expect(document.activeElement).toBe(findNameItem('Alpha'))
+ })
+
+ it('moves focus into a sections sub-menu on expand and back to its row on ESC', () => {
+ renderSelector()
+ openMenu()
+ fireEvent.click(findDotsItem('Beta'))
+ const submenu = submenuEl()
+ const firstRoute = submenu?.querySelector<HTMLElement>('[role="menuitem"]')
+ expect(firstRoute).not.toBeNull()
+ expect(document.activeElement).toBe(firstRoute)
+
+ // ESC collapses the sub-menu and returns focus to the row's dots button.
+ fireEvent.keyDown(document.body, { key: 'Escape' })
+ expect(submenuEl()).toBeNull()
+ expect(document.activeElement).toBe(findDotsItem('Beta'))
+ })
})