Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r3-m2 own palette dismissal at modal scope
Josuéf176c392fdf0
diff --git a/desktop-app/ui/src/components/CommandPalette/CommandPalette.dismissal.test.tsx b/desktop-app/ui/src/components/CommandPalette/CommandPalette.dismissal.test.tsxnew file mode 100644index 000000000..4d7e511af--- /dev/null+++ b/desktop-app/ui/src/components/CommandPalette/CommandPalette.dismissal.test.tsx@@ -0,0 +1,93 @@+// @vitest-environment jsdom+import { useState } from 'react'+import { afterEach, describe, expect, it, vi } from 'vitest'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { CommandPalette } from '.'++afterEach(cleanup)++function renderPalette(onClose = vi.fn(), onExecute = vi.fn()) {+ const rendered = render(+ <CommandPalette+ platform="darwin"+ isEligible={() => true}+ onClose={onClose}+ onExecute={onExecute}+ />+ )+ return { ...rendered, onClose, onExecute }+}++describe('CommandPalette modal dismissal ownership', () => {+ it.each([+ ['input', () => screen.getByRole('textbox', { name: 'Search commands' })],+ ['result', () => screen.getByRole('option', { name: /New chat tab/ })],+ ['panel', () => screen.getByRole('dialog', { name: 'Command palette' })],+ ['modal descendant', () => screen.getByText('Open a blank chat view tab.')],+ ])('dismisses on Escape from the %s', (_label, getTarget) => {+ const { onClose } = renderPalette()+ fireEvent.keyDown(getTarget(), { key: 'Escape' })+ expect(onClose).toHaveBeenCalledOnce()+ })++ it('dismisses on Escape from empty-result content', () => {+ const { onClose } = renderPalette()+ fireEvent.change(screen.getByRole('textbox', { name: 'Search commands' }), {+ target: { value: 'no command has this label' },+ })+ fireEvent.keyDown(screen.getByText('No matching commands.'), { key: 'Escape' })+ expect(onClose).toHaveBeenCalledOnce()+ })++ it('dismisses only true backdrop pointer clicks', () => {+ const { container, onClose, onExecute } = renderPalette()+ const backdrop = container.querySelector('.command-palette-backdrop') as HTMLElement+ const panel = screen.getByRole('dialog', { name: 'Command palette' })+ const input = screen.getByRole('textbox', { name: 'Search commands' })+ const result = screen.getByRole('option', { name: /New chat tab/ })+ const shortcut = screen.getByText('⌘T')++ fireEvent.mouseDown(panel)+ fireEvent.mouseDown(input)+ fireEvent.click(shortcut)+ expect(onClose).not.toHaveBeenCalled()+ expect(onExecute).toHaveBeenCalledOnce()+ expect(onExecute).toHaveBeenLastCalledWith('chat.newTab')+ onExecute.mockClear()++ fireEvent.click(result)+ expect(onExecute).toHaveBeenCalledWith('chat.newTab')+ expect(onClose).not.toHaveBeenCalled()++ fireEvent.mouseDown(backdrop)+ expect(onClose).toHaveBeenCalledOnce()+ })++ it('restores prior focus after backdrop dismissal', async () => {+ const previous = document.createElement('button')+ document.body.append(previous)+ previous.focus()++ function Owner() {+ const [open, setOpen] = useState(true)+ return open ? (+ <CommandPalette+ platform="darwin"+ isEligible={() => true}+ onClose={() => setOpen(false)}+ onExecute={vi.fn()}+ />+ ) : null+ }++ const { container } = render(<Owner />)+ fireEvent.mouseDown(container.querySelector('.command-palette-backdrop') as HTMLElement)+ await new Promise<void>(resolve =>+ requestAnimationFrame(() => {+ expect(document.activeElement).toBe(previous)+ resolve()+ })+ )+ previous.remove()+ })+})diff --git a/desktop-app/ui/src/components/CommandPalette/index.tsx b/desktop-app/ui/src/components/CommandPalette/index.tsxindex e5d0c3944..b755699b3 100644--- a/desktop-app/ui/src/components/CommandPalette/index.tsx+++ b/desktop-app/ui/src/components/CommandPalette/index.tsx@@ -69,17 +69,25 @@ export function CommandPalette({}return (- <div className="command-palette-backdrop" role="presentation">+ <div+ className="command-palette-backdrop"+ onKeyDown={event => {+ if (event.key !== 'Escape') return+ event.preventDefault()+ onClose()+ }}+ onMouseDown={event => {+ if (event.target === event.currentTarget) onClose()+ }}+ role="presentation"+ ><divref={dialogRef}aria-label="Command palette"aria-modal="true"className="command-palette"onKeyDown={event => {- if (event.key === 'Escape') {- event.preventDefault()- onClose()- } else if (event.key === 'ArrowDown') {+ if (event.key === 'ArrowDown') {event.preventDefault()moveSelection(1)} else if (event.key === 'ArrowUp') {