Skip to content

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

TypeScript

feat(desktop-app): suppress chat drawer below min panel width and restore width on re-widen

Diego Zacarias40ef83fc89fa
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index c8368adba..4bac2bd56 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -520,12 +520,22 @@ export function App() {
// an orthogonal boolean axis over the shared `chatViewTabs`/<ChatPage> — never
// a second tab store, never a foreground/background precedence module.
const chatDrawerAvailable = vm.navItem === DESKTOP_ROUTES.apps && Boolean(activeSandboxUiApp)
- const chatDrawerVisible = chatDrawerAvailable && chatDrawerOpen
- chatDrawerVisibleRef.current = chatDrawerVisible
- chatDrawerAvailableRef.current = chatDrawerAvailable
+ // Intention (what the user asked for) is kept separate from effective
+ // visibility. `chatDrawerDesired` is the user's open intent on an app-live
+ // route; below the minimum panel width the drawer can't coexist with the embed
+ // so it is SUPPRESSED — hidden without clearing the intent — and reappears on
+ // re-widen. A manual close flips `chatDrawerOpen`, so it stays closed. The
+ // resize hook measures the panel while the drawer is DESIRED (not only while
+ // visible) so it can observe the re-widen; `panelTooNarrow` comes from that
+ // measurement, and visibility derives from it — no dependency cycle with the
+ // hook's `active` input, which is the desire alone.
+ const chatDrawerDesired = chatDrawerAvailable && chatDrawerOpen
// Session-only drawer sizing (always docked beside the native embed). Width is
// not persisted by design; it resets to the default each launch.
- const chatDrawerResize = useChatDrawerResize(contentPanelRef, chatDrawerVisible)
+ const chatDrawerResize = useChatDrawerResize(contentPanelRef, chatDrawerDesired)
+ const chatDrawerVisible = chatDrawerDesired && !chatDrawerResize.panelTooNarrow
+ chatDrawerVisibleRef.current = chatDrawerVisible
+ chatDrawerAvailableRef.current = chatDrawerAvailable
// The notification tray's drawer form occupies the same fixed right-rail rect
// as the chat drawer, so it only takes drawer form when the chat drawer is NOT
// visible; while the chat drawer is up it reverts to its popover/overlay form
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index 687341978..c6d829412 100644
--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
@@ -472,3 +472,123 @@ describe('App chat drawer — reopen preserves the last-viewed chat', () => {
expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
})
})
+
+// Mini-spec 05: below the minimum panel width the drawer is SUPPRESSED (hidden,
+// app takes full width) without clearing the user's open intent, so it reappears
+// when the window re-widens; a MANUAL close clears the intent, so it stays gone.
+// `SandboxUiPage.chatDrawerOpen` mirrors effective visibility (App passes
+// `chatDrawerVisible`), and the "Open chats" switcher only mounts while visible —
+// both are the observable outputs asserted here. The panel width is driven
+// through the real producer path: a stubbed ResizeObserver captures the hook's
+// sync callback, and the content-panel's clientWidth is made mutable so firing
+// the callback re-measures exactly as a window resize would.
+describe('App chat drawer — narrow-width suppression (mini-spec 05)', () => {
+ let currentController: AppController
+ let panelClientWidth: number
+ let fireResize: () => void
+
+ beforeEach(() => {
+ vi.clearAllMocks()
+ sidebarHarness.props = null
+ sandboxUiPageHarness.props = null
+ appHeaderHarness.props = null
+ appHeaderHarness.openNotification = null
+ panelClientWidth = 2000
+ fireResize = () => {}
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ constructor(cb: () => void) {
+ fireResize = () => cb()
+ }
+ observe() {}
+ disconnect() {}
+ }
+ )
+ currentController = makeController({
+ selectedAgent: 'alpha',
+ activeChatId: 'chat-1',
+ navItem: DESKTOP_ROUTES.chat,
+ chatList: CHAT_LIST,
+ } as Partial<AppController>)
+ vi.mocked(useAppController).mockImplementation(() => currentController)
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ shortcuts: { onCommand: vi.fn(() => vi.fn()) },
+ app: { rendererReady: vi.fn().mockResolvedValue(undefined) },
+ sandboxUi: {
+ listApps: vi.fn().mockResolvedValue({ apps: [] }),
+ listPendingDeepLinks: vi.fn().mockResolvedValue({ links: [] }),
+ clearPendingDeepLinks: vi.fn().mockResolvedValue(undefined),
+ onDeepLink: vi.fn(() => vi.fn()),
+ setVisible: vi.fn().mockResolvedValue(undefined),
+ setBounds: vi.fn().mockResolvedValue(undefined),
+ focusActive: vi.fn().mockResolvedValue(true),
+ close: vi.fn().mockResolvedValue(undefined),
+ },
+ } as unknown as Window['clerum'],
+ })
+ })
+
+ afterEach(() => {
+ cleanup()
+ delete (window as { clerum?: unknown }).clerum
+ vi.unstubAllGlobals()
+ })
+
+ // Make the live content-panel report a mutable clientWidth so the ResizeObserver
+ // callback measures our test width instead of jsdom's un-laid-out 0.
+ function bindPanelWidth() {
+ const el = document.querySelector('.content-panel') as HTMLElement | null
+ if (el && !Object.getOwnPropertyDescriptor(el, 'clientWidth')) {
+ Object.defineProperty(el, 'clientWidth', {
+ configurable: true,
+ get: () => panelClientWidth,
+ })
+ }
+ }
+
+ function resizeTo(width: number) {
+ panelClientWidth = width
+ bindPanelWidth()
+ act(() => fireResize())
+ }
+
+ it('suppresses the drawer below the threshold and restores it on re-widen, but a manual close stays closed', () => {
+ render(<App />)
+
+ // Launch from chat-1: the drawer opens over the live embed. The first sync
+ // reads a 0 panel (jsdom), which is not "too narrow", so it starts visible.
+ act(() => {
+ sidebarHarness.props?.onOpenSandboxUiApp?.({
+ appRef: 'ns/app',
+ label: 'App',
+ defaultPath: '/',
+ })
+ })
+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(screen.queryByRole('button', { name: 'Open chats' })).not.toBeNull()
+
+ // Narrow the panel below CHAT_DRAWER_MIN_PANEL_WIDTH (846): the drawer is
+ // suppressed and the app takes the full width (no gutter class).
+ resizeTo(800)
+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(screen.queryByRole('button', { name: 'Open chats' })).toBeNull()
+
+ // Re-widen above the threshold: the open intent was never cleared, so the
+ // drawer reappears on its own.
+ resizeTo(1200)
+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(true)
+ expect(screen.queryByRole('button', { name: 'Open chats' })).not.toBeNull()
+
+ // Manual close while visible clears the intent.
+ act(() => sandboxUiPageHarness.props?.onToggleChatDrawer?.())
+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+
+ // Widening (or any resize) must NOT bring a manually-closed drawer back.
+ resizeTo(2000)
+ expect(sandboxUiPageHarness.props?.chatDrawerOpen).toBe(false)
+ expect(screen.queryByRole('button', { name: 'Open chats' })).toBeNull()
+ })
+})
diff --git a/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.narrowWidth.test.tsx b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.narrowWidth.test.tsx
new file mode 100644
index 000000000..c647c2886
--- /dev/null
+++ b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.narrowWidth.test.tsx
@@ -0,0 +1,115 @@
+// @vitest-environment jsdom
+import type { RefObject } from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { act, renderHook } from '@testing-library/react'
+import {
+ CHAT_DRAWER_DEFAULT_WIDTH,
+ CHAT_DRAWER_MIN_PANEL_WIDTH,
+ useChatDrawerResize,
+} from '../useChatDrawerResize'
+
+// Mini-spec 05: below CHAT_DRAWER_MIN_PANEL_WIDTH (846 = MIN 340 + GUTTER 46 +
+// EMBED_FLOOR 460) the docked drawer can't coexist with the embed, so the hook
+// reports `panelTooNarrow` and the caller suppresses it WITHOUT losing intent.
+// And within the valid range, a transient narrowing must not permanently shrink
+// the drawer — the requested width is restored on re-widen (absorbs L2).
+//
+// The panel width is driven through the REAL producer path: the hook's
+// ResizeObserver callback (which IS its `sync`) re-reads the panel's clientWidth.
+// A stubbed ResizeObserver captures that callback so the test can fire it after
+// mutating the measured width, exactly as a window resize would at runtime.
+
+type MutablePanel = { clientWidth: number }
+
+function makeHarness(initialWidth: number) {
+ const panel: MutablePanel = { clientWidth: initialWidth }
+ const ref = { current: panel } as unknown as RefObject<HTMLElement | null>
+ let fire: () => void = () => {}
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ private cb: () => void
+ constructor(cb: () => void) {
+ this.cb = cb
+ fire = () => cb()
+ }
+ observe() {}
+ disconnect() {}
+ }
+ )
+ const resizeTo = (next: number) => {
+ panel.clientWidth = next
+ act(() => fire())
+ }
+ return { ref, resizeTo }
+}
+
+describe('useChatDrawerResize narrow-width suppression', () => {
+ afterEach(() => vi.unstubAllGlobals())
+
+ it('reports panelTooNarrow just below the threshold and not at it', () => {
+ const { ref, resizeTo } = makeHarness(2000)
+ const { result } = renderHook(() => useChatDrawerResize(ref, true))
+ expect(result.current.panelTooNarrow).toBe(false)
+
+ // One pixel below the threshold: suppressed.
+ resizeTo(CHAT_DRAWER_MIN_PANEL_WIDTH - 1) // 845
+ expect(result.current.panelTooNarrow).toBe(true)
+
+ // Exactly at the threshold: visible again.
+ resizeTo(CHAT_DRAWER_MIN_PANEL_WIDTH) // 846
+ expect(result.current.panelTooNarrow).toBe(false)
+ })
+
+ it('never reports panelTooNarrow while the panel is unmeasured (0, e.g. mount)', () => {
+ const { ref } = makeHarness(0)
+ const { result } = renderHook(() => useChatDrawerResize(ref, true))
+ // clientWidth 0 must NOT count as "too narrow" — that would flash-suppress the
+ // drawer on mount before the first real measurement.
+ expect(result.current.panelTooNarrow).toBe(false)
+ })
+})
+
+describe('useChatDrawerResize width restore on re-widen (L2)', () => {
+ beforeEach(() => {
+ // Run rAF synchronously so a drag's apply() is observable within act().
+ vi.stubGlobal('requestAnimationFrame', (cb: FrameRequestCallback) => {
+ cb(0)
+ return 1
+ })
+ vi.stubGlobal('cancelAnimationFrame', () => {})
+ })
+ afterEach(() => vi.unstubAllGlobals())
+
+ it('restores the requested width after a transient narrowing', () => {
+ const { ref, resizeTo } = makeHarness(2000)
+ const { result } = renderHook(() => useChatDrawerResize(ref, true))
+ expect(result.current.width).toBe(CHAT_DRAWER_DEFAULT_WIDTH) // 420
+
+ // Drag the drawer to a requested 600px on the wide panel. The right edge
+ // falls back to window.innerWidth - 18 (jsdom innerWidth = 1024 → 1006), so a
+ // pointer at 406 requests 1006 - 406 = 600.
+ act(() =>
+ result.current.onResizeHandleMouseDown({
+ button: 0,
+ clientX: 1006,
+ preventDefault: vi.fn(),
+ currentTarget: { closest: () => null },
+ } as unknown as React.MouseEvent<HTMLElement>)
+ )
+ act(() => window.dispatchEvent(new MouseEvent('mousemove', { clientX: 406 })))
+ act(() => window.dispatchEvent(new MouseEvent('mouseup')))
+ expect(result.current.width).toBe(600)
+
+ // Narrow the panel within the valid range: the applied width re-clamps DOWN
+ // to preserve the embed floor (1000 - 506 = 494) but stays visible.
+ resizeTo(1000)
+ expect(result.current.panelTooNarrow).toBe(false)
+ expect(result.current.width).toBe(494)
+
+ // Re-widen: the drawer must return to the 600 the user requested, not stay at
+ // the transient minimum (the L2 bug: it used to stick at 494 forever).
+ resizeTo(2000)
+ expect(result.current.width).toBe(600)
+ })
+})
diff --git a/desktop-app/ui/src/hooks/useChatDrawerResize.ts b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
index fcedac8ef..a63d80f15 100644
--- a/desktop-app/ui/src/hooks/useChatDrawerResize.ts
+++ b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
@@ -48,6 +48,25 @@ const CHAT_DRAWER_GUTTER_EXTRA = 46
* (`--space-4` = 18px). */
const CHAT_DRAWER_RIGHT_INSET = 18
+/** Minimum content-panel width at which the docked drawer and the app embed can
+ * still coexist: the drawer already pinned to its own minimum (340) PLUS the
+ * embed at its legible floor (460) PLUS the fixed gutter term (46) = 846. Below
+ * this the two no longer fit side by side, so there is no split to show and the
+ * drawer auto-suppresses (the app takes the full width). Derived from its three
+ * inputs — never a bare literal — so it always tracks them if any one moves. */
+export const CHAT_DRAWER_MIN_PANEL_WIDTH =
+ CHAT_DRAWER_MIN_WIDTH + CHAT_DRAWER_GUTTER_EXTRA + CHAT_DRAWER_EMBED_FLOOR
+
+/** Clamp a user-requested width to the panel-independent absolute bounds
+ * [MIN, MAX_ABSOLUTE], rounded to a whole pixel. This is what we persist as the
+ * user's INTENT (`requestedWidth`): it must survive a transient narrowing so a
+ * later widen can restore it. The dynamic embed-floor cap is applied on top at
+ * render time via `clampWidth(requestedWidth, panelWidth)`, never baked into the
+ * stored intent (that was the L2 "shrinks and never reverts" bug). */
+function clampRequested(requested: number): number {
+ return Math.round(Math.max(CHAT_DRAWER_MIN_WIDTH, Math.min(CHAT_DRAWER_MAX_ABSOLUTE, requested)))
+}
+
function readPanelWidth(ref: RefObject<HTMLElement | null>): number {
return ref.current?.clientWidth ?? 0
}
@@ -78,10 +97,17 @@ export function widthForCursor(rightEdge: number, pointerX: number, panelWidth:
}
export type ChatDrawerResize = {
- /** Current drawer width in px (session-only state). */
+ /** Current drawer width in px, already clamped to the live panel. */
width: number
/** True while a drag is in progress (for handle feedback). */
isResizing: boolean
+ /** True when the content panel is measured (> 0) and narrower than
+ * `CHAT_DRAWER_MIN_PANEL_WIDTH`: the drawer can't coexist with the embed, so
+ * the caller suppresses it (hides it, app takes full width) WITHOUT touching
+ * the user's open/closed intent, and shows it again on re-widen. Stays `false`
+ * while the panel is unmeasured (0, e.g. during mount) so the drawer is never
+ * suppressed on a phantom zero width. */
+ panelTooNarrow: 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. */
@@ -92,26 +118,43 @@ export function useChatDrawerResize(
contentPanelRef: RefObject<HTMLElement | null>,
active: boolean
): ChatDrawerResize {
- const [width, setWidth] = React.useState(CHAT_DRAWER_DEFAULT_WIDTH)
+ // `requestedWidth` is the user's INTENT (drag/keyboard target); the rendered
+ // width is `clampWidth(requestedWidth, panelWidth)`. Separating them is what
+ // lets a transient narrowing shrink the applied width WITHOUT losing the
+ // requested one, so a later widen restores it (L2 fix). `panelWidth` is the
+ // live content-panel measurement kept in state so the render re-clamps and the
+ // narrow-threshold re-derives whenever the panel resizes.
+ const [requestedWidth, setRequestedWidth] = React.useState(CHAT_DRAWER_DEFAULT_WIDTH)
+ const [panelWidth, setPanelWidth] = React.useState(0)
const [isResizing, setIsResizing] = React.useState(false)
+ const width = clampWidth(requestedWidth, panelWidth)
+ const panelTooNarrow = panelWidth > 0 && panelWidth < CHAT_DRAWER_MIN_PANEL_WIDTH
+ // Mirrors the rendered width so the pointer/keyboard handlers (stable
+ // callbacks) can read the current applied value as the base for a relative
+ // resize without re-subscribing on every width change.
const widthRef = React.useRef(width)
widthRef.current = width
// Teardown of an in-progress drag, stored so a cleanup effect can invoke it
// if the drawer hides or the hook unmounts mid-drag (see below).
const endDragRef = React.useRef<(() => void) | null>(null)
- // Keep the width inside the dynamic clamp as the content panel resizes. A
- // ResizeObserver on the content panel also fires on window resize (the panel
- // is full-height flex), so no separate window listener is needed. As the
- // panel narrows this re-clamp shrinks the drawer to preserve the embed floor.
+ // Track the live content-panel width while the drawer is DESIRED (available &&
+ // open), not only while visible — the panel stays mounted when the drawer is
+ // suppressed for being too narrow, and we must keep measuring it to notice the
+ // re-widen that brings the drawer back. A ResizeObserver on the panel also
+ // fires on window resize (the panel is full-height flex), so no separate
+ // window listener is needed. Storing the measurement re-derives both the
+ // clamped width and `panelTooNarrow`; because the drawer is `position: fixed`
+ // and the gutter is `padding-right` on a child, neither its visibility nor its
+ // width changes the panel's `clientWidth` — so there is no feedback loop and no
+ // flicker at the threshold.
React.useEffect(() => {
if (!active) return
const panel = contentPanelRef.current
if (!panel) return
const sync = () => {
- const panelWidth = readPanelWidth(contentPanelRef)
- const clamped = clampWidth(widthRef.current, panelWidth)
- setWidth(prev => (clamped === prev ? prev : clamped))
+ const measured = readPanelWidth(contentPanelRef)
+ setPanelWidth(prev => (prev === measured ? prev : measured))
}
sync()
if (typeof ResizeObserver === 'undefined') return
@@ -120,97 +163,94 @@ export function useChatDrawerResize(
return () => observer.disconnect()
}, [active, contentPanelRef])
- const onResizeHandleMouseDown = React.useCallback(
- (event: React.MouseEvent<HTMLElement>) => {
- // Only the left button starts a drag; ignore middle/right so a right-click
- // over the 8px strip while the left button is held can't open a second,
- // re-entrant drag.
- if (event.button !== 0) return
- event.preventDefault()
- // End any drag still in progress before installing a new one, so the
- // previous drag's window listeners/rAF are always torn down first — a
- // re-entrant mousedown must never orphan an earlier drag's `onMove`.
- endDragRef.current?.()
- // The drawer's right edge is fixed while docked; measure it once from the
- // live element (robust to any transformed ancestor) so the width tracks
- // `rightEdge - cursorX` for the whole drag.
- const drawerEl = event.currentTarget.closest('.chat-drawer')
- const rightEdge = drawerEl
- ? drawerEl.getBoundingClientRect().right
- : window.innerWidth - CHAT_DRAWER_RIGHT_INSET
+ const onResizeHandleMouseDown = React.useCallback((event: React.MouseEvent<HTMLElement>) => {
+ // Only the left button starts a drag; ignore middle/right so a right-click
+ // over the 8px strip while the left button is held can't open a second,
+ // re-entrant drag.
+ if (event.button !== 0) return
+ event.preventDefault()
+ // End any drag still in progress before installing a new one, so the
+ // previous drag's window listeners/rAF are always torn down first — a
+ // re-entrant mousedown must never orphan an earlier drag's `onMove`.
+ endDragRef.current?.()
+ // The drawer's right edge is fixed while docked; measure it once from the
+ // live element (robust to any transformed ancestor) so the width tracks
+ // `rightEdge - cursorX` for the whole drag.
+ const drawerEl = event.currentTarget.closest('.chat-drawer')
+ const rightEdge = drawerEl
+ ? drawerEl.getBoundingClientRect().right
+ : window.innerWidth - CHAT_DRAWER_RIGHT_INSET
- let frame = 0
- let pointerX = event.clientX
- const apply = () => {
- frame = 0
- const panelWidth = readPanelWidth(contentPanelRef)
- const next = widthForCursor(rightEdge, pointerX, panelWidth)
- setWidth(next)
- }
- const onMove = (moveEvent: MouseEvent) => {
- pointerX = moveEvent.clientX
- if (!frame) frame = window.requestAnimationFrame(apply)
- }
- // Teardown. Each closure removes its OWN listeners/rAF unconditionally,
- // BEFORE the guard, so a superseded drag can always detach itself and can
- // never leave this closure's `onMove` pinned to `window` (the leak this
- // ordering fixes). The guard then protects ONLY the shared state
- // (body style, isResizing, endDragRef) so a superseded drag's late
- // teardown doesn't clobber the drag that replaced it. Also runs on `blur`
- // (mouse released outside the window never fires `mouseup`) and from the
- // cleanup effect below.
- const endDrag = () => {
- if (frame) window.cancelAnimationFrame(frame)
- window.removeEventListener('mousemove', onMove)
- window.removeEventListener('mouseup', endDrag)
- window.removeEventListener('blur', endDrag)
- if (endDragRef.current !== endDrag) return
- document.body.style.userSelect = ''
- document.body.style.cursor = ''
- endDragRef.current = null
- setIsResizing(false)
- }
- endDragRef.current = endDrag
- document.body.style.userSelect = 'none'
- document.body.style.cursor = 'col-resize'
- setIsResizing(true)
- window.addEventListener('mousemove', onMove)
- window.addEventListener('mouseup', endDrag)
- window.addEventListener('blur', endDrag)
- },
- [contentPanelRef]
- )
+ let frame = 0
+ let pointerX = event.clientX
+ const apply = () => {
+ frame = 0
+ // Record the raw cursor target as the requested intent (clamped only to
+ // the absolute bounds); the render applies the dynamic embed-floor cap on
+ // top, so the drag stops following the cursor at the cap yet the intent
+ // is preserved for a later widen.
+ setRequestedWidth(clampRequested(rightEdge - pointerX))
+ }
+ const onMove = (moveEvent: MouseEvent) => {
+ pointerX = moveEvent.clientX
+ if (!frame) frame = window.requestAnimationFrame(apply)
+ }
+ // Teardown. Each closure removes its OWN listeners/rAF unconditionally,
+ // BEFORE the guard, so a superseded drag can always detach itself and can
+ // never leave this closure's `onMove` pinned to `window` (the leak this
+ // ordering fixes). The guard then protects ONLY the shared state
+ // (body style, isResizing, endDragRef) so a superseded drag's late
+ // teardown doesn't clobber the drag that replaced it. Also runs on `blur`
+ // (mouse released outside the window never fires `mouseup`) and from the
+ // cleanup effect below.
+ const endDrag = () => {
+ if (frame) window.cancelAnimationFrame(frame)
+ window.removeEventListener('mousemove', onMove)
+ window.removeEventListener('mouseup', endDrag)
+ window.removeEventListener('blur', endDrag)
+ if (endDragRef.current !== endDrag) return
+ document.body.style.userSelect = ''
+ document.body.style.cursor = ''
+ endDragRef.current = null
+ setIsResizing(false)
+ }
+ endDragRef.current = endDrag
+ document.body.style.userSelect = 'none'
+ document.body.style.cursor = 'col-resize'
+ setIsResizing(true)
+ window.addEventListener('mousemove', onMove)
+ window.addEventListener('mouseup', endDrag)
+ window.addEventListener('blur', endDrag)
+ }, [])
// 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)
- },
- [contentPanelRef]
- )
+ 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()
+ // Arrows step from the current APPLIED width so the splitter visibly moves
+ // on every press even when the requested intent sits above the dynamic cap;
+ // Home/End set an absolute intent. The render clamps to the live panel.
+ setRequestedWidth(clampRequested(requested))
+ }, [])
// 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.
@@ -220,5 +260,11 @@ export function useChatDrawerResize(
}, [active])
React.useEffect(() => () => endDragRef.current?.(), [])
- return { width, isResizing, onResizeHandleMouseDown, onResizeHandleKeyDown }
+ return {
+ width,
+ isResizing,
+ panelTooNarrow,
+ onResizeHandleMouseDown,
+ onResizeHandleKeyDown,
+ }
}