diff --git a/frontend/src/__tests__/ConfirmDialog.test.tsx b/frontend/src/__tests__/ConfirmDialog.test.tsx index f12cf58..2b91ac0 100644 --- a/frontend/src/__tests__/ConfirmDialog.test.tsx +++ b/frontend/src/__tests__/ConfirmDialog.test.tsx @@ -74,7 +74,7 @@ describe('ConfirmDialog', () => { it('calls onCancel when overlay clicked', () => { const onCancel = vi.fn(); - const { container } = render( + render( { onCancel={onCancel} /> ); - // The overlay is the outermost div with fixed positioning - const overlay = container.firstChild as HTMLElement; - fireEvent.click(overlay); + // The backdrop overlay is the first child inside the dialog with aria-hidden + const backdrop = document.querySelector('dialog > div[aria-hidden="true"]'); + fireEvent.click(backdrop!); expect(onCancel).toHaveBeenCalled(); }); diff --git a/frontend/src/__tests__/ModelModal.test.tsx b/frontend/src/__tests__/ModelModal.test.tsx index 35f33d2..61fab78 100644 --- a/frontend/src/__tests__/ModelModal.test.tsx +++ b/frontend/src/__tests__/ModelModal.test.tsx @@ -206,10 +206,11 @@ describe('ModelModal', () => { expect(screen.getAllByText('GPT-4o').length).toBeGreaterThanOrEqual(1); }); - // Click on the dialog element itself (backdrop area) to close - const dialog = document.querySelector('dialog'); - fireEvent.click(dialog!); + // Click on the backdrop overlay (the aria-hidden div inside the dialog) + const backdrop = document.querySelector('dialog > div[aria-hidden="true"]'); + fireEvent.click(backdrop!); + const dialog = document.querySelector('dialog'); await waitFor(() => { expect(dialog).not.toHaveAttribute('open'); }); diff --git a/frontend/src/components/ConfirmDialog.tsx b/frontend/src/components/ConfirmDialog.tsx index 5c8225a..8118bfe 100644 --- a/frontend/src/components/ConfirmDialog.tsx +++ b/frontend/src/components/ConfirmDialog.tsx @@ -41,21 +41,19 @@ export function ConfirmDialog({ return () => dialog?.removeEventListener('cancel', handleCancel); }, [onCancel]); - const handleBackdropClick = (e: React.MouseEvent) => { - // Close when clicking the backdrop (outside the dialog content) - if (e.target === dialogRef.current) { - onCancel(); - } - }; - return ( -
+ {/* Backdrop overlay for click-to-close */} +