Skip to content

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

TypeScript

fix(desktop-app): r2-l2 make the chat-drawer resize handle keyboard-operable

Diego Zacariasc51817c628b9
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 525eea9d6..14957d4a6 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -2099,6 +2099,8 @@ export function App() {
onResizeHandleMouseDown={
chatDrawerResize.onResizeHandleMouseDown
}
+ onResizeHandleKeyDown={chatDrawerResize.onResizeHandleKeyDown}
+ width={chatDrawerResize.width}
resizing={chatDrawerResize.isResizing}
>
<ChatPage scrollContainerRef={chatDrawerRef} />
diff --git a/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx b/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx
index c218df98d..ecb596c08 100644
--- a/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx
+++ b/desktop-app/ui/src/components/ChatDrawer/ChatDrawer.test.tsx
@@ -28,6 +28,7 @@ function renderDrawer(props: Partial<React.ComponentProps<typeof ChatDrawer>> =
const onNewChat = props.onNewChat ?? vi.fn()
const onClose = props.onClose ?? vi.fn()
const onResizeHandleMouseDown = props.onResizeHandleMouseDown ?? vi.fn()
+ const onResizeHandleKeyDown = props.onResizeHandleKeyDown ?? vi.fn()
const containerRef = props.containerRef ?? createRef<HTMLElement>()
const utils = render(
<ChatDrawer
@@ -37,12 +38,14 @@ function renderDrawer(props: Partial<React.ComponentProps<typeof ChatDrawer>> =
containerRef={containerRef}
ready={props.ready ?? true}
onResizeHandleMouseDown={onResizeHandleMouseDown}
+ onResizeHandleKeyDown={onResizeHandleKeyDown}
+ width={props.width ?? 420}
resizing={props.resizing ?? false}
>
<div data-testid="drawer-chat-page">chat page</div>
</ChatDrawer>
)
- return { ...utils, onNewChat, onClose, onResizeHandleMouseDown }
+ return { ...utils, onNewChat, onClose, onResizeHandleMouseDown, onResizeHandleKeyDown }
}
describe('ChatDrawer', () => {
@@ -102,6 +105,18 @@ describe('ChatDrawer', () => {
expect(onResizeHandleMouseDown).toHaveBeenCalledTimes(1)
})
+ it('makes the resize handle keyboard-operable per the ARIA separator pattern', () => {
+ const { container, onResizeHandleKeyDown } = renderDrawer({ width: 512 })
+ const handle = container.querySelector('.chat-drawer__resize-handle') as HTMLElement
+ // Focusable, with the value semantics the separator role requires.
+ expect(handle.getAttribute('tabindex')).toBe('0')
+ expect(handle.getAttribute('aria-valuemin')).toBe('340')
+ expect(handle.getAttribute('aria-valuemax')).toBe('820')
+ expect(handle.getAttribute('aria-valuenow')).toBe('512')
+ fireEvent.keyDown(handle, { key: 'ArrowLeft' })
+ expect(onResizeHandleKeyDown).toHaveBeenCalledTimes(1)
+ })
+
it('reveals once ready', () => {
const { container } = renderDrawer({ ready: true })
const drawer = container.querySelector('.chat-drawer') as HTMLElement
diff --git a/desktop-app/ui/src/components/ChatDrawer/index.tsx b/desktop-app/ui/src/components/ChatDrawer/index.tsx
index 753eecbc3..19d4b8be6 100644
--- a/desktop-app/ui/src/components/ChatDrawer/index.tsx
+++ b/desktop-app/ui/src/components/ChatDrawer/index.tsx
@@ -1,5 +1,6 @@
import { IconButton } from '@components/Common'
import { IconClose, IconNewChat } from '@components/SidebarNav/icons'
+import { CHAT_DRAWER_MAX_ABSOLUTE, CHAT_DRAWER_MIN_WIDTH } from '@hooks/useChatDrawerResize'
import type { ChatDrawerProps } from './types'
/**
@@ -18,6 +19,8 @@ export function ChatDrawer({
containerRef,
ready,
onResizeHandleMouseDown,
+ onResizeHandleKeyDown,
+ width,
resizing,
children,
}: ChatDrawerProps) {
@@ -30,9 +33,14 @@ export function ChatDrawer({
<div
className="chat-drawer__resize-handle"
role="separator"
+ tabIndex={0}
aria-orientation="vertical"
aria-label="Resize chat drawer"
+ aria-valuemin={CHAT_DRAWER_MIN_WIDTH}
+ aria-valuemax={CHAT_DRAWER_MAX_ABSOLUTE}
+ aria-valuenow={Math.round(width)}
onMouseDown={onResizeHandleMouseDown}
+ onKeyDown={onResizeHandleKeyDown}
/>
<header className="chat-drawer__header">
<div className="chat-drawer__header-main">{header}</div>
diff --git a/desktop-app/ui/src/components/ChatDrawer/types.ts b/desktop-app/ui/src/components/ChatDrawer/types.ts
index 1f04046c4..15cdf3087 100644
--- a/desktop-app/ui/src/components/ChatDrawer/types.ts
+++ b/desktop-app/ui/src/components/ChatDrawer/types.ts
@@ -1,4 +1,9 @@
-import type { MouseEvent as ReactMouseEvent, ReactNode, RefObject } from 'react'
+import type {
+ KeyboardEvent as ReactKeyboardEvent,
+ MouseEvent as ReactMouseEvent,
+ ReactNode,
+ RefObject,
+} from 'react'
export type ChatDrawerProps = {
/**
@@ -21,6 +26,13 @@ export type ChatDrawerProps = {
* Wired from `useChatDrawerResize`.
*/
onResizeHandleMouseDown: (event: ReactMouseEvent<HTMLElement>) => void
+ /**
+ * keydown handler for the focusable drag handle — arrow-key / Home / End
+ * resize (WAI-ARIA window-splitter pattern). Wired from `useChatDrawerResize`.
+ */
+ onResizeHandleKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => void
+ /** Current drawer width in px, surfaced as the handle's `aria-valuenow`. */
+ width: number
/** True while a resize drag is in progress — highlights the drag handle. */
resizing: boolean
children: ReactNode
diff --git a/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.keyboard.test.tsx b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.keyboard.test.tsx
new file mode 100644
index 000000000..3dfc7a785
--- /dev/null
+++ b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.keyboard.test.tsx
@@ -0,0 +1,62 @@
+// @vitest-environment jsdom
+import { createRef } from 'react'
+import { describe, expect, it, vi } from 'vitest'
+import { act, renderHook } from '@testing-library/react'
+import {
+ CHAT_DRAWER_DEFAULT_WIDTH,
+ CHAT_DRAWER_MAX_ABSOLUTE,
+ CHAT_DRAWER_MIN_WIDTH,
+ useChatDrawerResize,
+} from '../useChatDrawerResize'
+
+// R2-L2: the separator handle only had onMouseDown, so it was inert to keyboard
+// users. These pin the arrow/Home/End behavior on the hook. In jsdom the content
+// panel measures 0, so clampWidth falls back to the [MIN, MAX_ABSOLUTE] range —
+// enough to exercise direction and the extremes without layout.
+
+function setup() {
+ const ref = createRef<HTMLElement>()
+ return renderHook(() => useChatDrawerResize(ref, true))
+}
+
+function press(result: ReturnType<typeof setup>['result'], key: string) {
+ const event = { key, preventDefault: vi.fn() } as unknown as React.KeyboardEvent<HTMLElement>
+ act(() => result.current.onResizeHandleKeyDown(event))
+ return event
+}
+
+describe('useChatDrawerResize keyboard resize', () => {
+ it('widens by one step on ArrowLeft (drawer grows leftward)', () => {
+ const { result } = setup()
+ expect(result.current.width).toBe(CHAT_DRAWER_DEFAULT_WIDTH) // 420
+ press(result, 'ArrowLeft')
+ expect(result.current.width).toBe(CHAT_DRAWER_DEFAULT_WIDTH + 24) // 444
+ })
+
+ it('narrows by one step on ArrowRight', () => {
+ const { result } = setup()
+ press(result, 'ArrowRight')
+ expect(result.current.width).toBe(CHAT_DRAWER_DEFAULT_WIDTH - 24) // 396
+ })
+
+ it('jumps to the max on Home and the min on End', () => {
+ const { result } = setup()
+ press(result, 'Home')
+ expect(result.current.width).toBe(CHAT_DRAWER_MAX_ABSOLUTE) // 820
+ press(result, 'End')
+ expect(result.current.width).toBe(CHAT_DRAWER_MIN_WIDTH) // 340
+ })
+
+ it('ignores unrelated keys and does not preventDefault them', () => {
+ const { result } = setup()
+ const event = press(result, 'a')
+ expect(result.current.width).toBe(CHAT_DRAWER_DEFAULT_WIDTH)
+ expect(event.preventDefault).not.toHaveBeenCalled()
+ })
+
+ it('preventDefaults a handled key so the surface does not scroll', () => {
+ const { result } = setup()
+ const event = press(result, 'ArrowLeft')
+ expect(event.preventDefault).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/desktop-app/ui/src/hooks/useChatDrawerResize.ts b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
index b9a88debc..82098ed42 100644
--- a/desktop-app/ui/src/hooks/useChatDrawerResize.ts
+++ b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
@@ -21,7 +21,9 @@ export const CHAT_DRAWER_MIN_WIDTH = 340
/** Default session width (matches the top of the old CSS clamp). */
export const CHAT_DRAWER_DEFAULT_WIDTH = 420
/** Generous absolute ceiling for the drag. */
-const CHAT_DRAWER_MAX_ABSOLUTE = 820
+export const CHAT_DRAWER_MAX_ABSOLUTE = 820
+/** Width step for arrow-key resize (WAI-ARIA window-splitter pattern). */
+const CHAT_DRAWER_KEY_STEP = 24
/** Always leave at least this much of the content panel for the app embed, so
* even at the widest drag the embed never collapses to nothing. */
const CHAT_DRAWER_VIEWPORT_MARGIN = 80
@@ -77,6 +79,8 @@ export type ChatDrawerResize = {
isResizing: boolean
/** mousedown handler for the drag handle on the drawer's left edge. */
onResizeHandleMouseDown: (event: React.MouseEvent<HTMLElement>) => void
+ /** keydown handler for the (focusable) drag handle — arrow/Home/End resize. */
+ onResizeHandleKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void
}
export function useChatDrawerResize(
@@ -174,6 +178,38 @@ export function useChatDrawerResize(
[contentPanelRef, recomputeOverlay]
)
+ // Keyboard resize for the focusable separator handle (WAI-ARIA window-splitter
+ // pattern): with `aria-orientation="vertical"`, Left/Right move the splitter.
+ // The drawer is right-docked, so ArrowLeft widens it (mirroring a leftward
+ // drag) and ArrowRight narrows it; Home/End jump to the drawer's max/min.
+ const onResizeHandleKeyDown = React.useCallback(
+ (event: React.KeyboardEvent<HTMLElement>) => {
+ let requested: number
+ switch (event.key) {
+ case 'ArrowLeft':
+ requested = widthRef.current + CHAT_DRAWER_KEY_STEP
+ break
+ case 'ArrowRight':
+ requested = widthRef.current - CHAT_DRAWER_KEY_STEP
+ break
+ case 'Home':
+ requested = CHAT_DRAWER_MAX_ABSOLUTE
+ break
+ case 'End':
+ requested = CHAT_DRAWER_MIN_WIDTH
+ break
+ default:
+ return
+ }
+ event.preventDefault()
+ const panelWidth = readPanelWidth(contentPanelRef)
+ const next = clampWidth(requested, panelWidth)
+ setWidth(next)
+ recomputeOverlay(next)
+ },
+ [contentPanelRef, recomputeOverlay]
+ )
+
// If the drawer hides or the hook unmounts while a drag is live, tear it down
// so window listeners and the body cursor/user-select overrides never leak.
React.useEffect(() => {
@@ -182,5 +218,5 @@ export function useChatDrawerResize(
}, [active])
React.useEffect(() => () => endDragRef.current?.(), [])
- return { width, isOverlay, isResizing, onResizeHandleMouseDown }
+ return { width, isOverlay, isResizing, onResizeHandleMouseDown, onResizeHandleKeyDown }
}